Here is a simple example to compute Cointegration between two stock pairs using python libraries like NSEpy, Pandas, statmodels, matplotlib
Cointegration is used in Statistical Arbitrage to find best Pair of Stocks (Pair Trading) to go long in one stock and short(Competitive peers) another to generate returns. Statistical Arbitrage(StatArb) is all about mean reversion, looking for deviation in the spreads and expecting mean reversion from the spread.
NSEpy – fetches historical data from nseindia.com
Pandas – Python library to handle time series data
Statmodels – Python library to handle statistical operations like cointegration
Matplotlib – Python library to handle 2D chart plotting
Sample IPython Notebook to compute Cointegration below :
References
Quantopian Lecture on Pair Trading
Python Library to get publicly available data on NSE website – NSEpy
The post Compute Cointegration using NsePy, Pandas Library appeared first on Marketcalls.