Pair Trading - Exploring The Low Risk Statistical Arbitrage Trading Concepts

VJAY

Well-Known Member
#31
Dear ncube,
I tryed your instructions also some other help which available in google but still am unable to do this pip install :( ...I think the problem is file location .many solutions available in google..I tryed almost all

View attachment 26962
At last able to do all installations ...cluprit is C++ 2015 not in my system..installed it now every thing is okey ...will need to check how to do run this :)
Thanks ncube brother ....I never used python ...now you guided in it too..
Untitled.png
 

VJAY

Well-Known Member
#32
Dear ncube,
When I tryed to play every cells...its giving now errors ...chart not showing ...please give step by step instructions to how to use it..its runs only once ?or we can run whenever we need after updating CSV ?

Untitled.png
 

newtrader101

Well-Known Member
#33
Hi Ncube,
Thanks for sharing your ideas. Can we apply this to commodities as well?
For example, Gold and Silver, given Silver fluctuates more, but generally seems to trend together with Gold?
 

ncube

Well-Known Member
#34
Dear ncube,
When I tryed to play every cells...its giving now errors ...chart not showing ...please give step by step instructions to how to use it..its runs only once ?or we can run whenever we need after updating CSV ?

View attachment 26965
First time you start Jupyter Notebook, you need to run 1st cell with the core functions in PairTrading.ipynb. After that you can selectively run the other cells to try different combinations:

After opening the PairTrading.ipynb in jupyter follow this sequence:
1. Run the 1st cell with the import statements once, this will load all the libraries and function into python interpreter.
#importing the required python libraries
import pandas as pd
......
2. Now run the 2nd cell to load the updated stock data. once this is successfully run, the stock data is loaded into returns & df pandas dataframe.
returns,df = loaddata('D://stockdata_20180726.csv')
3. Run the 3rd cell to select the stock pairs that you want to analyse. S1 is the Y stock & S2 is the X stock, just need to change the stock names.
S1 = returns['TCS']
S2 = returns['WIPRO']
4. Run the 4th cell to find the cointegration significance for these 2 stocks.
find_cointegration_significance()
5. Plot the pairs with zscore.

You need to run the 1st & 2nd cells only once, cells 3-5 can be repeated any number of time for different stock combination. If you need to track multiple stock pairs at the same time, copy and paste these 3 cell into a new cell at the bottom of the file and just change the stock pair names.
 

ncube

Well-Known Member
#35
Hi Ncube,
Thanks for sharing your ideas. Can we apply this to commodities as well?
For example, Gold and Silver, given Silver fluctuates more, but generally seems to trend together with Gold?
Yes, Pair trading can be applied to any instruments which are stationary & co-integrating as a pair (or group of indtruments). The possibilities are limitless. However I have not explored these commodities as its difficult to explore too many options and I have recently started pair trading, hence restricted myself to stocks.
 

VJAY

Well-Known Member
#36
Am doing some thing wrong I think ...I again followed as mentioned above but its coming error in module & data load ....when I first installed its all ok but when played with run button this problem started....:(
Untitled.png
 

ncube

Well-Known Member
#37
At last able to do all installations ...cluprit is C++ 2015 not in my system..installed it now every thing is okey ...will need to check how to do run this :)
Thanks ncube brother ....I never used python ...now you guided in it too..
View attachment 26964
As Far as I know there is no dependency on C++ for python. Anyway if its working for you its great!!

However after a clean installation of python you can run the following commands to verify the python installation:
python --version
pip --version

If pip is not working you may try to force pip usage by running the command :
python -m ensurepip --default-pip
 

ncube

Well-Known Member
#38
Am doing some thing wrong I think ...I again followed as mentioned above but its coming error in module & data load ....when I first installed its all ok but when played with run button this problem started....:( View attachment 26967
You have not run the following pip installs:

>pip install pandas
>pip install matplotlib
>pip install statsmodels

These are the libraries that need to be installed after installing python. Please refer to my earlier post on installation of python & Jupyter
 

VJAY

Well-Known Member
#39
You have not run the following pip installs:

>pip install pandas
>pip install matplotlib
>pip install statsmodels

These are the libraries that need to be installed after installing python. Please refer to my earlier post on installation of python & Jupyter
yes I done....is we need to every time install these to run jupyter notebook?
 

ncube

Well-Known Member
#40
Amazing thread ! Thank a lot ncube ! Looking forward for more such analysis
I am also trying out pair trading in Excel. Need to move towards ipynb soon

What you feel about more macro co-relation trades like crude oil v/s nifty , interest rate v/s nifty etc. I know its not exactly a pair trading but many say it gives a long term outlook , I didnt find any notable correlation between nifty and other asset ; Just wondering if you have done any research on this.
If the instrument is stationary one can use it for pair trading. But it is always better to use simple instruments for pair trading, indexes are effected by its contituent stocks, hence its better to avoid index. However its possible to use index and do statistical argitrage, but I have not tries it yet as I have recently started pair trading and resticted myself to nifty stocks.