Dear ncube ,
I think you missed my this post
I think you missed my this post
def getnew_zScore(SS1,SS2,SS1_price,SS2_price,lb=20):
S1=SS1.append(pd.Series([SS1_price]),ignore_index=True)
S2=SS2.append(pd.Series([SS2_price]),ignore_index=True)
spread = S1[-lb:] / S2[-lb:]
spread_mean = spread.mean()
std_dev = spread.std()
zscore = (spread - spread_mean)/std_dev
print('Latest zScore : ',zscore.iloc[-1])
You can call this function from a cell at the end of the notebook as follows:
getnew_zScore(SS1,SS2,275,2175)
where 275 is the latest price of SS1 & 2175 is the latest price of SS2. The output will be the latest zScore...