Pair Trading - Exploring The Low Risk Statistical Arbitrage Trading Concepts

ncube

Well-Known Member
#1
Pair trading is a low risk statistical arbitrage strategy, however it is not very popular in India as many think it involves complex logic to identify the pairs and trading them effectively. Also many feel that it is more suitable for institutional players due the resources at their disposal and avoid exploring it. Based on my analysis and limited live trading experience I see there is lot of potential and one can easily design systematic low risk strategies with some simple opensource libraries & basic coding experience.

I have created this thread so that people interested in this type of statistical arbitrage strategies can share their knowledge and experience and help each other develop good ideas and trading strategies. I have recently started trading this strategy and will be happy to share my experience and provide guidance by answering your queries and clarifying concepts which I am familiar (I am still learning). However please dont ask me to share my code here as I use complex algorithms and machine learning processes which are tightly integrated with Pair trading logic and other strategies and it would be difficult for me to separate and explain. Also I would prefer people to explore their own ideas and not just clone me, but I will share the logic wherever possible.

People who are new to pair trading, I would suggest them to go through this wonderful article written by Karthik Rangappa on zerodha varsity as I will not be able to beat that simplicity even if I try to explain it here. URL: https://zerodha.com/varsity/module/trading-systems/

Once you are familiar with the concepts there, you should be able to trade basic strategies, however if you want to explore complex concepts you may later refer to these following books:
Pairs Trading: Quantitative Methods and Analysis by Ganapathy Vidyamurthy
Algorithmic Trading: Winning Strategies and their rationale by Ernest P. Chan

In the varsity tutorial Karthik has used excel to analyze the pairs, those who are strong in excel can work & extend on it, however I am not comfortable in excel & prefer to use python for coding the logic and use Jupyter notebook as the IDE (Browser based python programming interface) which is open source and easy to learn, hence recommend other to do the same as it will give more flexibility to users.
 
Last edited:

VJAY

Well-Known Member
#2
Dear nucub,
Thanks for opening a thread for pair trading ...its helpfull many to get insights of pairtrading as you told its not much familier with small retail traders here...thanks a lot
 

ncube

Well-Known Member
#3
As the basics of pair trading is very well covered in the zerodha varsity tutorial, I plan to cover the following topics in the next few posts. However I expect good participation and interaction from members so that I know it is helping else there is no point in me putting the efforts. My intention is that everyone learn & explore further and share their experience so that new ideas and strategies can be built on pair trading concepts.

Topics:
1. My understandings and thoughts on Pair Trading.
2. How to use Pair Trading with a Day trader mindset.
3. Installing and running Python & Jupyter Notebook
4. A simplified python framework for running the Pair Trading logic. If possible I will prepare & share the Pair Trading Jupyter notebook which you can directly run in your environment.
5. Queries and clarifications based on the interest and participation by members.

Feedbacks or suggestion for additional topics are welcomed. However I will be able post & reply to your queries only when I get time..so please bear with me...:)
 
Last edited:

VJAY

Well-Known Member
#4
As the basics of pair trading is very well covered in the zerodha varsity tutorial, I plan to cover the following topics in the next few posts. However I expect good participation and interaction from members so that I know it is helping else there is no point in me putting the efforts. My intention is that everyone learn & explore further and share their experience so that new ideas and strategies can be built on pair trading concepts.

Topics:
1. My understandings and thoughts on Pair Trading.
2. How to use Pair Trading with a Day trader mindset.
3. Installing and running Python & Jupyter Notebook
4. A simplified python framework for running the Pair Trading logic. If possible I will prepare & share the Pair Trading Jupyter notebook which you can directly run in your environment.
5. Queries and clarifications based on the interest and participation by members.

Feedbacks or suggestion for additional topics are welcomed. However I will be able post & reply to your queries only when I get time..so please bear with me...:)
Am eagerly looking forward it .....Hope many members will come too as this type of trading not popular in this forum
 

VJAY

Well-Known Member
#5
Dear ncube,
As per our intractions yesterday and per my testing with excel file ...if today I applyed those things in intraday then it given good trade today ...
Icici long and HDFC short...where icici triggered hdfc not.....Need good command in selecting pairs...hope this thread will help me alot .....
 

ncube

Well-Known Member
#6
My understandings and thoughts on Pair Trading:

To start with let me first make it clear that Pair Trading is not a Holy Grail system, however it provides us with a tool to systematically identify trades with statistical edge on our side. Main challenge for traders especially those who day trade is to be able to consistently execute trades without emotional bias. Hence I always suggest to make your trading rules mechanical or systematic so that chances of making errors are reduced leading to better trading results.

Now if you have gone through the basics of pair trading on Zerodha Varsity (If not go through it first), you would have understood that pair trading is based on the concept that 2 stocks which are fundamentally related in some way (Same sector, dependent sectors etc) behave similar in their price movements and trend in the same direction. However due to dynamic nature of the market sometimes their will be temporary deviations and this is what pair traders exploit to their advantage. If the stock pairs have shown historic co-integration, and if they deviate by a certain threshold (Standard deviation) then there is a higher change that they will mean revert in the coming days.

Consider the attached Tata motors pair, what we can learn here is just that there is a temporary deviation in prices between TATAMOTORS and TATAMTRDVR which is more than 2 SD from mean and there is a high probability that the prices of these 2 stocks will mean revert in the coming days. As per the attached image it says the dependent stock (Y) TATAMTRDVR will go up and independent stock (X) will go down. [When zScore is -ve it mean Y is undervalued & when it is +ve Y is overvalued] However this is not guarenteed as mean reversion will happen when one of these stocks move more than the other. i.e in this case the mean reversion can happen under 2 situations:

1. TATAMTRDVR go up more than TATAMOTORS as per the details in the image or
2. TATAMOTORS fall more than TATAMTRDVR in the coming days.

TM Pair.png


Hence we cannot be sure which stock in the pair will go into profit, sometimes both, hence what positional traders will do is they will just short 1 stock and long the other. I.e Short TATAMOTORS & long TATAMTRDVR and wait for them to mean revert. Now what may happen is that

1. If TATAMTRDRV move up more than TATAMOTORS, then their profit will be more in long TATAMTRDVR than loss made in short TATAMOTORS
2. If TATAMOTORS falls more than TATAMTRDVR, then their profit will be more in the Short TATAMOTORS than the loss in Long TATAMTRDRV.
3. If TATAMTRDRV move up and TATAMOTORS go down, then they will profit on both.
4. However If TATAMTRDRV go down and TATAMOTORS go up then their is some structural break down in these to pairs, hence one should keep a SL target to comeout if the trade goes wrong.

I know most of the members in this forum are day traders, hence I will not go in depth on positional pair trading and in the next post will explain how one can use this concept for day trading...:)
 
Last edited:

NJ78

Well-Known Member
#7
Once you are familiar with the concepts there, you should be able to trade basic strategies, however if you want to explore complex concepts you may later refer to these following books:
Pairs Trading: Quantitative Methods and Analysis by Ganapathy Vidyamurthy
Algorithmic Trading: Winning Strategies and their rationale by Ernest P. Chan
Mark Whistler is another well-known name in the area of pair trading. His book "Trading Pairs" though a little old, offers theoretical & practical insights into the subject. His relatively newer book "Macro to Micro Volatility Trading" explores the application of standard deviation to trading.
 

ncube

Well-Known Member
#8
How to use Pair Trading with a Day trader mindset:

Though I mentioned in my previous post that pair trading is suitable for postional traders as a low risk strategy in the portfolio, it can be easily extended to day trade. The main challenge in day trading is that one need to be clear about the trend direction and even after the trade is executed there is the risk of hitting the stop loss and then trend continuing in the original direction. Hence it is difficult to hold on to the trade with confidence. This is where pair trading is useful, we do not place the stop loss for the first stock but the position is hedged with the second stock in the pair.

For day trading we use only the simple concepts from pair trading, we need not perform complex linear regression to derive the intercept & beta values between the stocks. We are just interested to know whether there is co-integration and if yes then what is the current zscore. While selecting the stocks to trade we make bet that when the zscore exceeds some threshold, then there is high probability that the stocks will mean revert and one of the stock will move more than the other.
 

ncube

Well-Known Member
#9
You guys would already be having some strategies to day trade, you can use the same to place your trades, however you do not keep stop loss orders, instead you will place the opposite order on the second stock. Day trading is a skill, and there are multiple ways to execute your strategy, however I use these simple rules which I had explained in general chat thread:

Day Trading Strategy:
For day trading we can short stocks and use margins, so for the identified pairs fix same rupee value you want to trade for each stock, for example 25K per stock, so calculate the respective quantities of stocks that you can go long or short. With margin It will be about 10K for both the stocks combined together (50K).

Trading rules:
1. Wait for the 1st 15min or 30min candle to be formed.
2. Keep a SL MIS buy order at the high of the candle for the stock you want to go long
3. Keep a SL MIS sell order at the low of the candle for the stock you want to go short
4. Close the open trades before 3:15pm

Reasoning on why it will work:
1. If the stocks trend in our identified direction (usually the pair will move in same direction) only 1 of these trades will be triggered and will go into profit.
2. If the stocks trend is opposite to our identified direction both trades will not be triggered and no trade for us. (The price diversion will increase by end of day..so higher chances they will mean revert in subsequent days)
3. If the stocks trend in our identified direction and later change direction after the 1st trade was executed then the 1st trade will start going into loss, however the 2nd pair trade will get triggered and the position is now hedged. Usually in these cases by end of the day trend reverses (due to mean reversion force) giving small profit else during the course of the day they will come to a point where it can be close for break-even or small loss.

The reason why I select the same rupee value say 25K for each stock is that we are interested in the daily returns of each stock, since we know that one stock will more more than the other even if both the trades are executed in our favor we will have the difference in return as our profit.
For example, if stock1 return is 2% and stock2 return is 5%, then even if both got executed we will still end up with 3% profit. If only 1 is executed and if we are lucky we can end up with 5% profit.

I usually keep a target of 1% if both the trades are executed and about 3% if only 1 trade is executed, else I will allow it to run till the end of day as I am confident that my trades are hedged.

I think this much detail should be sufficient for day trading pairs and in subsequent 2 posts I will explain how to setup the python environment for pair trading and you guys will be set to go. Dont worry if you are not technically strong or have experience in coding, it is very easy to use python on Jupyter.
 

VJAY

Well-Known Member
#10
Dear ncube,
Is there anyway to know the correlation between 2 scrips which we selected in excell without ADF?means looking anything otherthan ADF we select scrips for pairtrading?though maybe its not accurate like ADF but we can use.....
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?