Pair Trading - Exploring The Low Risk Statistical Arbitrage Trading Concepts

VJAY

Well-Known Member
@VJAY, the strategy rules I mentioned are the rules that I follow and comfortable with. You need not have to follow the exact rules, each trader has his own personality and the strategy rules should be in sync with his skills and psychological growth stage. I suggest you can select few pairs and start observing it and I am sure after few days you will come up with your own rules which will match with your personality. Day trading is more of skill and our emotional maturity to trade systematically. This will come only with experience and sufficient screen time there is no free lunch.

Coming to answer your queries on the strategy I follow, the details are as follows:

I dont track only few of the eligible pairs regularly, Based on my observation,I have found that the stocks in those pairs on average moves about 3-5% each day, and when the zscore moves above +/-2 SD, the action starts and the pairs start to mean revert, usually 1 stock move more than the other, But it is difficult to predict which direction they will move. Hence I place opposite trades on the 2 stocks of the pair so that one of them get triggered. I dont force trade, once the trade is executed I manage the trade as follows:

1.When we enter trade using 30 min bar after trigger are we need to put SL @ abv/blw 30 bar?
>> If our trade goes through as per our analysis, only one of the trades is executed first and both stocks should move in the same direction. This give us a hint on the direction for the day. However if both are not moving in same direction and see that the trend is exhausted and reversing (Based on the price action of subsequent candles) I will wait to see if price pull back more than 50% of the 1st 30 min bar in opposite direction. This means there is some change in sentiment, hence higher chances that the price move will be stong in the reverse direction. In this case I will place a SL reverse order (Double the quantity of the stock traded). You can refer to my ALBK-ANDHRABANK trade example that I shared in earlier post.
2.So if 30 bar is big one and we expect move in our side we wait for next 15 bar and trade as per that bar ...here we use triggeres in 15 bar for both scrips?
>> If the 30 min bar is nearer to the average daily movement of the stock, then I will skip trading it as there is no point trading it as risk-reward ratio will be small. However I sometimes do try to observe if the trend has exhausted. For example say both the stocks have moved up more than 3% in the 1st bar, then I will focus on the stock to be shorted on the 15 min candle. You can refer my TATAMTRDRV-TATAMOTORS trade shared earlier.
3.If 30 bar close near lows/highs(big bar) we not jump into trade wait for 15 min bar.
>> If the close is very near to the low of the 1st 30 min bar then, I will wait for a small pullback and then place the SL trade order. Else there is high chance that after hitting our SL the trend is reversed. I dont chase the price, I want it to come to me at the price that I choose and not the other way around.
4.Please explain with example for bolded risk part...how can we calculate risk?
>> Lets say the 1st 30 min candles of both the stocks are 3% long, then we will be placing a buy order at the top of the 1st stock and a sell order at the bottom of the other stock. In this case the risk is 3% as once the first trade is executed and the price reverses then by the time the 2nd stock sell order is executed we would lose 3% in the 1st stock.
Thanks ncube bro for detailed reply...it helps
 

ncube

Well-Known Member
Dear ncube,
Is any chance to get these figures(marked red) from notebook?

View attachment 27026
@VJAY , we can get these values by running linear regression on the stock pairs, there are standard libraries avaiable for these in python. However this is not required for day trading pairs, these values help when we need to take the positions overnight, so one need to know how the pairs are related statistically and how much quanitities of each stocks one need to carry each day so that it is properly hedged. These involve other complex analysis and hence I suggest you can explore these later once you have more experience trading pairs.
 

UberMachine

Well-Known Member
Scanning 500 nifty stocks you can easily find pairs more than 2000 pairs with high co-integration scores. I know its tempting to see so many options, but pair trading is not about trading so many pairs, but to understand few pairs and master its movement. It is humanely not possible to track so many pairs and its not required to make consistent profit.

I would suggested select few pairs that look interesting and have high co-integration significance values and monitor them regularly so that you understand the pattern in which the pairs moves. Also the excel sheet I have shared is just for your reference, stocks that you are not interested in you can delete it from the sheet, this will reduce the effort of daily updation.

For the few pairs that you have identified, do the following regularly:
1. What is the average movement the pairs trend each day.
2. Is it really moving in the same direct together, what happens if the movement is in opposite direction? does it sync by end of day
3. Does the pairs respect the zscore values, and what is the ideal zscore for the pairs to initiate the trades.
4. Finally you just need 1-2 pairs which you understand well to make money.
5. Pair trading is just a low risk way of trading stocks, and you can define your own trading and money management rules to trade it successfully.

Fully agreed.
 

UberMachine

Well-Known Member
Haha, I think high beta and high correlation needs to be revisited again :D:D:D
I think there is a simple rule.
If the number of co-integrating pairs is more than the prescribed threshold, then we can be sure for better.
(Eg)
Say for NIFTY 50, there are 1225 combinations.
At a p-value of 0.05, I would easily get 1225*0.05 = ~61. I am sure to find 61 highly correlated pairs anyhow. But I need to adjust my system so that I could deal with it.

Frankly speaking, I amn't able to tweak the system and also not finding an efficient method either for backtesting or pair hselection instead of an wait and watch method. (Again this raises a further question I think backtesting needds to be revisited again :))
 

travi

Well-Known Member
@ncube do you have a python script that parses the NSE ABCD EoD file for close price and appends to the csv master file ?
 

travi

Well-Known Member
Could you upload the file?
If I get it right, you have eod files in a directory and you need to append them to master file at the end of the day?
Basically the NSE EOD Bhavcopy is a comma delimited .txt file, so pandas.read_csv() should be able to assign it to a df.

so now, you have df from your notebook and df1 with EoD Data.

Pseudocode:
1. read comma delimited txt file into df1

# assume, the master CSV has only 100 scrips, originally you have 500 which is now master.csv.
2. A generic script would take each scrip from header in df and search in df1, then return corresponding close from that row
3. returned close is appended to df
4. df dumps its data back to master.csv

sample EoD file attached. They use simple format
scrip, date, O, H, L,C, V

Thanks
 

Attachments