Last active
February 26, 2020 08:26
-
-
Save quantra-go-algo/7deafd4454f020d1b5110302079d2eb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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="2014-04-01", api_key= '') | |
data2 = quandl.get("CHRIS/MCX_PB1", start_date="2014-04-01", api_key= '') | |
# 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 Co-integration | |
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment