Course Name: Statistical Arbitrage Trading, Section No: 4, Unit No: 5, Unit type: Notebook
Why logarithm (np.log) is used for calculating the mean and std dev? What purpose does it have?
Code:
--------
Define z-score calculation function
def zscore_cal(data1, data2, start, end):
s1 = pd.Series(data1['Close'][start:end])
s2 = pd.Series(data2['Close'][start:end])
# Compute mean of the spread till now
mvavg_old = np.mean(np.log(s1/s2))
# Compute stdev of the spread till now
std_old = np.std(np.log(s1/s2))
# Compute spread
current_spread = np.log(
data1['Close'][end]/data2['Close'][end])
# This is the same as current_spread = np.log(data1['Close'][end]) - np.log(data2['Close'][end])
# Compute z-score
zscore = (current_spread - mvavg_old) / <br />
std_old if std_old > 0 else 0
return zscore
--------
Thanks in advance!