Pair Trading - Exploring The Low Risk Statistical Arbitrage Trading Concepts

lvgandhi

Well-Known Member
@lvgandhi , sometimes OS dependencies would cause python installation errors. If one faces these issues and new to python it is recommended to install anaconda as it bundles all the important packages and takes care of dependencies. However it is about 600MB in size and will occupy about 1.5GB after installation on your computer harddisk.

You can download anaconda from the following url:
https://www.anaconda.com/download/

Nice guide by @UberMachine , to explain the installation steps:
http://www.traderji.com/community/threads/python-installation-for-trading.106753/#post-1297784
Thanks.
I installed whl file for statsmodels. Then all modules suggested by you are installed.
Jupyter also installed. It opens in browser. But in running, i get as in pic in running.
pythone1.PNG

how to go further?
 

ncube

Well-Known Member
Thanks.
I installed whl file for statsmodels. Then all modules suggested by you are installed.
Jupyter also installed. It opens in browser. But in running, i get as in pic in running.
View attachment 27359
how to go further?
You need to upload the PairTrading.ipynb files I have shared in Google drive from the files tab next to running tab.Then open it and run. You may first go through the introduction YouTube videos I have shared few posts earlier to get familiar with jupyter notebook interface.
 
Tried two pair trades in small quantity yesterday. Trade entry and SL are based on first 30 min. high/low.
1. Bajaj-auto and Heromotoco, Zscore -1.057. Long triggered in Bajaj-auto and hit SL. Short in Heromotoco did not trigger. Never traded these two stocks. Took the trade as the two are from same sector.
2. Relcapital and Relinfra, Zscore +1.122. Short triggered in Relcapital. Profit booked, losses from other trade recovered. Long in Relinfra not triggered. I regularly trade these stocks, not as a pair but independently. Took the trade as they usually go up or come down together.
 

ncube

Well-Known Member
Tried two pair trades in small quantity yesterday. Trade entry and SL are based on first 30 min. high/low.
1. Bajaj-auto and Heromotoco, Zscore -1.057. Long triggered in Bajaj-auto and hit SL. Short in Heromotoco did not trigger. Never traded these two stocks. Took the trade as the two are from same sector.
2. Relcapital and Relinfra, Zscore +1.122. Short triggered in Relcapital. Profit booked, losses from other trade recovered. Long in Relinfra not triggered. I regularly trade these stocks, not as a pair but independently. Took the trade as they usually go up or come down together.
@Vevensa_P, For day trading, pairs provides us a statistical edge by systematically identifying stocks which are highly co-integrated (High change that they will move together) and help us predict the direction the stocks will more likely to move in coming days. How to use this information is based on the day trading strategy one is comfortable with as day trading requires certain skills and ability to take descretionary calls. Hence I would recommend everyone to explore ways to include pair trading concepts into their day trading strategies to increase the edge rather than change the strategy itself.

BTW if anyone interested can check the APOLLOTYPE-CEATLTD pair for monday as its looking good. Explore this pair in the notebook to identify the Co-integration value and zScore..:)
 
@Vevensa_P, For day trading, pairs provides us a statistical edge by systematically identifying stocks which are highly co-integrated (High change that they will move together) and help us predict the direction the stocks will more likely to move in coming days. How to use this information is based on the day trading strategy one is comfortable with as day trading requires certain skills and ability to take descretionary calls. Hence I would recommend everyone to explore ways to include pair trading concepts into their day trading strategies to increase the edge rather than change the strategy itself.

BTW if anyone interested can check the APOLLOTYPE-CEATLTD pair for monday as its looking good. Explore this pair in the notebook to identify the Co-integration value and zScore..:)
@ncube, Sorry for the delayed response, last week I took break from trading and related activities.
Sure, not going to change the system/strategy I am currently following. I shall try to utilize the method shared by you for identifying stocks and trade as per my system. Thanks for the advice.
 

VJAY

Well-Known Member
Dear ncube,
If we trade pair trading as positional then it must be in Futures...so we use cash data to find the pairs and zscore then enter in futures am right?How you entry take at morning ?is it same way as intra using 1st 30 minuits or any other way?Also please share the steps to balance lots as lot qty is different....
 

VJAY

Well-Known Member
@VJAY , The new PairTrading.ipynb is updated with only one function load_eod(), this is required only for members who want to use script to update the daily EOD NSE bhavcopy. If you are doing updates mannually for few stocks then it is not required. You can comment the cell with this function with a # in front of the function as follows, and this cell will not get executed.
#update_eod('C://master/stockdata.csv','C://master/eod.txt')

Also if someone wants to use date as index instead of numbers as it is easier to update manually, you can replace the first column in the stockdata.csv file with dates for all the rows. The python script that I have written just takes the first column as index so if its date then the index will be date. To replace the first column with the dates, you can download the historical data (For the number of rows in the stockdata.csv file) excel sheet for one of the stocks from NSE website to get the trading day dates and copy only the date to the first column in stockdata.csv file.
Dear ncube,
Today I tryed to update stockdata file by this scrip....but when I run the code output file removed dates and giving index numbers in date column...
1534858464729.png

1534858505917.png
 

ncube

Well-Known Member
Dear ncube,
Today I tryed to update stockdata file by this scrip....but when I run the code output file removed dates and giving index numbers in date column...
View attachment 27687
View attachment 27688
@VJAY , please modify the update_eod function in the notebook to that given below, it should work (The bhavcopy downloaded using NSE EOD Data Downloader v3.3 tool, if the format is different then it may need changes as per the format you use, usecols=[0,1,5] means field0 is Symbol, field1 is date and field5 is close price),

def update_eod(masterfile,eodfile):
master = pd.read_csv(masterfile, index_col=[0])
eod = pd.read_csv(eodfile, header=None,index_col=[0],usecols=[0,1,5])
date = eod.iloc[0,0]
df = master.append(eod.T.drop([1]).reset_index(drop=True).rename(index={0:date})).dropna(axis=1)
df.to_csv('C://master/stockdata.csv')
return

1534870357819.png
 
Last edited: