import numpy as np
import pandas as pd
import statsmodels
from statsmodels.tsa.stattools import coint
import statsmodels.api as stat
import statsmodels.tsa.stattools as ts
import matplotlib.pyplot as plt
from nsepy import get_history
from datetime import date
S1 = get_history(symbol = 'HDFC',
start = date(2020,1,1),
end = date(2020,8,27))
S2 = get_history(symbol = 'HDFCBANK',
start = date(2020,1,1),
end = date(2020,8,27))
#lookback 40 days
result = stat.OLS(S1[['Close']].tail(40), S2[['Close']].tail(40)).fit()
#adf test
a = ts.adfuller(result.resid)
#adf test results
a
#adf - The test statistic.
a[0]
#pvalue - MacKinnon”s approximate p-value based on MacKinnon (1994, 2010).
a[1]
#used lag - The number of lags used.
a[2]
#nobs - The number of observations used for the ADF regression and calculation of the critical values
a[3]
#critical values - Critical values for the test statistic at the 1 %, 5 %, and 10 % levels. Based on MacKinnon (2010).
a[4]["1%"], a[4]["5%"], a[4]["10%"]
#icbest - The maximized information criterion if autolag is not None.
a[5]
#end of file