Different Output when Run from Local Machine (Section 5, Course: Trading Alphas)

Hello,



In the Jupyter notebook for Section 5 ("Trading with Autocorrelated Data") of the Trading Alphas course, I have noticed that when I try to run the code for the section entitled "Comparison with the Benchmark" on my local machine, I get a different output. The regression equation produced on my local machine is positively sloped y=0.02 + 0.01, whereas the notebook gives a negatively sloped y = 0.01 - 0.03x. The exact code that I am running (copied from the course) is as follows:







import pandas as pd

import numpy as np

import matplotlib.pyplot as plt



pathway = "…/data_modules/spy_daily_1993_2022.csv"



spy = pd.read_csv(

    pathway,

    index_col = 0,

)



spy.index = pd.to_datetime(spy.index)



a = spy.resample('3M').last().Close.pct_change().fillna(0)



plt.figure(figsize=(15, 7))



plt.plot(a, np.sign(a)a.shift(-1), 'o')



m = np.polyfit(a.shift(-1).fillna(0), np.sign(a.fillna(0))

               
a.shift(-1).fillna(0), 1)

xx = a

yy = np.polyval(m, xx)

plt.plot(xx, yy)

plt.grid()



plt.title(f'y = {m[1]:.2f} + {m[0]:.2f}x', fontsize=16)

plt.xlabel('Benchmark Returns', fontsize=14)

plt.ylabel('Strategy Returns', fontsize=14)

plt.show()



>>> output y = 0.02 + 0.01
x





EDIT:

I have also noticed that the risk-adjusted returns of the benchmark calculated later in the same jupyter notebook do not produce the same output on my local machine either. Is the dataset used in the Jupyter Notebook different than the one included for download at the end of the course?







 

Hi Dylan,



You can re-download the zip file, the notebook is now producing the same output.



Thanks,

Rushda Ansari

Hey Rushda,



Thanks for the help. I have re-downloaded the .zip and am now getting the proper output