Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Created February 21, 2020 08:23
Show Gist options
  • Select an option

  • Save quantra-go-algo/dfbc2c413a67728420d41f2b07b8be34 to your computer and use it in GitHub Desktop.

Select an option

Save quantra-go-algo/dfbc2c413a67728420d41f2b07b8be34 to your computer and use it in GitHub Desktop.
#importing libraries
import statsmodels.api as stat
import statsmodels.tsa.stattools as ts
import quandl
#fetching financial data for two securities from Quandl
data1 = quandl.get("CHRIS/MCX_AL1", start_date="2016-11-01", api_key= 'U_PJwA55r5u8Lz_uFJ6L')
data2 = quandl.get("CHRIS/MCX_PB1", start_date="2014-04-01", api_key= 'U_PJwA55r5u8Lz_uFJ6L')
#printing the first 5 rows of our fetched data
print (data1.head())
print (data2.head())
#performing ADF test on the closing prices of fetched data
result = stat.OLS(data1['Close'], data2['Close']).fit()
c_t= ts.adfuller(result.resid)
#checking whether the pair of securities is co-integrated and printing the result
if c_t[0] <= c_t[4]['10%'] and c_t[1]<= 0.1:
print("Pair of securities is co-integrated")
else:
print("Pair of securities is not co-integrated")
NewerOlder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment