Pair Trading - Exploring The Low Risk Statistical Arbitrage Trading Concepts

ncube

Well-Known Member
Dear ncube,
I fewdays before I replaced stockdata file which shared by checkmate ...Its same which I used before but more scrips in it....only today I noticed that there is some error in showing date on pair chart ....please guide me...is it due to increased scrips?

View attachment 30033
@VJAY , The first column of the new sheet should be dates, looks like it is not dates in the replaced file.
 

VJAY

Well-Known Member
@VJAY , The first column of the new sheet should be dates, looks like it is not dates in the replaced file.
no its same nothing changed in new file only added new scrips...anyway will check once again EOD

1540789186142.png
 

VJAY

Well-Known Member
Guys, Just wrote a python code to update the master file with the daily nse bhavcopy file. Please add the following codes to the PairTrading.ipynb

1. Add the following function into the cell with other functions:
def update_eod(df,eodfile):
eod = pd.read_csv(eodfile, header=None,index_col=[0],usecols=[0,5])
df = df.append(eod.T).dropna(axis=1).reset_index(drop=True)
df.to_csv('C://stockdata.csv')
return df

2. Add a new cell after after the cell which reads the master file and add the following python statement
df = update_eod(df,'C://eod.txt')

View attachment 27044

How it works:
1. Every day download the EOD NSE bhavcopy text file and rename it as eod.txt, place it in the same folder as master file.
2. Next time you run the PairTrading.ipynb it will append the master file with the eod.txt content and overwrite the master file with updated data.

Hope this helps..Enjoy Pair Trading..:)
Dear,
when i followed this step, i am getting these error. Please help me to come out of it.
regards
Bindu
 

Attachments

VJAY

Well-Known Member

ncube

Well-Known Member
Dear ncube,
Looks like you made developments in code ..:up:.what's this parameter showed here?
Hi Vijay, no I have not made any changes, its the same I have been running for last many years and have also used earlier in this thread. However this particular trades that I have taken today is slightly advanced as instead of waiting for 2 stocks to generate signal I have induced stationarity by combining multiple stocks at different ratios to generate the signal. This is the next level in pair trading and I have briefly explained this concept somewhere in one of my earlier posts, however one would need to have good programming skills to code this logic.

The parameters are backtest levels for my reference when the trade is active and it gives me the levels when to close the trade for either profit or loss instead of just waiting till the end of day.

This post is just for my reference and will not be of much help to others, I am temporarily using this thread to post the trades as my pc got crashed over the weekend and I have again lost the blog journal I maintain in my local PC. I am now looking for some online solutions.
 
Last edited:

VJAY

Well-Known Member
Hi Vijay, no I have not made any changes, its the same I have been running for last many years and have also used earlier in this thread. However this particular trades that I have taken today is slightly advanced as instead of waiting for 2 stocks to generate signal I have induced stationarity by combining multiple stocks at different ratios to generate the signal. This is the next level in pair trading and I have briefly explained this concept somewhere in one of my earlier posts, however one would need to have good programming skills to code this logic.

The parameters are backtest levels for my reference when the trade is active and it gives me the levels when to close the trade for either profit or loss instead of just waiting till the end of day.

This post is just for my reference and will not be of much help to others, I am temporarily using this thread to post the trades as my pc got crashed over the weekend and I have again lost the blog journal I maintain in my local PC. I am now looking for some online solutions.
Thanks for detailed reply ncube.....you can use Google Blog to keep journal...I too lost my previous years journals due to PC crash....now am using Google Blog for keeping my journal...