I am reading Chen’s Algorithmic Trading and plan to rewrite the strategies in Python. This is the first post of this series. I’ll put the core code here. For the result and comparison with the original Matlab code please refer to my ipython notebook here.
For short, ADF test can be achieved by statsmodels.tsa.stattools.adfuller, and statsmodels.regression.linear_model.OLS can be used to fit a linear regression.
def adf_hl(price): |