Construction signal in BBands based strategy

Hello, 



In the Quantitative Trading Strategies and Models Section 2 Unit 19, it seems to me the signal should be:

df['Signal'] = 0

df.loc[(df['upper'].shift(2) > df['Close'].shift(2)) & (df['upper'].shift(1) < df['Close'].shift(1))
       & (df['R_Std'].shift(1) < df['Ret'].shift(1)), 'Signal'] = -1

df.loc[(df['lower'].shift(2) < df['Close'].shift(2)) & (df['lower'].shift(1) > df['Close'].shift(1))
       & (df['R_Std'].shift(1) < -df['Ret'].shift(1)), 'Signal'] = 1


In my opinion, we would need to have a 'knee jerk' reaction to enter a long or sell position which means the return should be higher than the standard deviation. The returns plot also looked better once I changed the code which makes me think there could be a typo iin the initial code.

Currently, the code is as follows:
df['Signal'] = 0

df.loc[(df[‘upper’].shift(2) > df[‘Close’].shift(2)) & (df[‘upper’].shift(1) < df[‘Close’].shift(1))
& (df[‘R_Std’].shift(1) > df[‘Ret’].shift(1)), ‘Signal’] = -1

df.loc[(df[‘lower’].shift(2) < df[‘Close’].shift(2)) & (df[‘lower’].shift(1) > df[‘Close’].shift(1))
& (-df[‘R_Std’].shift(1) < df[‘Ret’].shift(1)), ‘Signal’] = 1


Lastly, shouldn't we shift the signal when calculating the strategy returns in:

df['Str_ret'] = df['Signal']*df['Ret']

To me we could implement instead as:

df['Str_ret'] = df['Signal'].shift(1)*df['Ret']



Let me know what you think,
Thanks,
Adrien
1 Like

Hey Adrien,



Yes, looks like you are right. We will fix this and update you. Thanks for pointing this out!

Hey Adrien,



The notebook has been updated :slight_smile: