Welcome to the second part of the article. In the first part, I gave an introduction to pair trading. If you haven’t read that here is the link – **Introduction to Pair Trading****. **Now let us proceed further and learn the step by step procedure of executing it.

I selected two companies BPCL and HINDPETRO because these two have the same business profile and also the correlation between the closing prices of both stocks is 95%.

You can check the correction of closing prices using a simple excel formula =correl(array1,array2).

Now here the question comes is how to establish the relationship between the two stocks. I am going to use **the ratio** of closing prices to establish the relationship between both of them. Anyhow you can also do that using **spread or differential.**

Before proceeding further let me take this chance to explain the overall concept of pair trading-

In pair trading since the correlation between the two stocks is 95% these two follow a similar trend. But due to some temporary market conditions like an announcement of results in a company or due to any mishaps in another company, makes the stock direction of that company to deviate from the mean value

But because of high correlation after some time, the deviated stock again try to come to the mean path. Pair trading is a market neutral strategy. We have to buy one stock and sell another.

We have to take the opportunity when the stock gets deviated and should enter into the trade if the **standard deviation** is more than 95%. Now let us get back the procedure.

After calculating the ratio we need to calculate the **mean of the ratios** and have to plot a graph of the ratio and it will something look like this

You can observe the deviation of the graph from the mean path. So next question here is When to enter into the trade? And the answer is as told before when the standard deviation is more than 95%.

**What is Standard deviation?**

In statistics, the standard deviation is a measure that is used to quantify the amount of variation or dispersion of a set of data values.

So we are going to measure the deviation with the help of standard deviation

Using the 1-2-3 rule, we can know how much the stock price deviated from the mean value.

**68%**probability of the price lying**within 1 standard deviation**of the mean**95%**probability of the price lying**within 2 standard deviations**of the mean**99.7%**probability of the price lying**within 3 standard deviations**of the mean

I hope you got a clear idea of standard deviation. Lets us learn how to calculate all three standard deviations.

Assume “d” as the symbol of standard deviation and “μ” as mean. We need to calculate the standard deviation of the **ratios. **By using the value of standard deviation and mean value of the ratios we can calculate all three standard deviations. Below give the formula for calculating all three standard deviations

1sd – μ-1d

2sd – μ-2d

3sd – μ-3d

You can read more about it **here**

If you don’t get it don’t worry at the end of the article I have attached the video of the complete procedure. You can check it out.

As I said before is the probability of stock price above 2nd standard deviation is enough to execute the trade? The answer is No, it is not.

We should also be aware of the probability of stock getting back to the mean price. To know that we should calculate the density ratios and have to make a plot to get the density curve graph. The value of the density curve lies between 0 and 1. By using both density curve and ratio graph we need to execute the trade.

Here is the table of density curve relating to standard deviations. I

Density Curve value | How many Standard deviation away | Probability of reverting to mean |

0.16 | – 1 SD | 65% |

0.025 | – 2 SD | 95% |

0.003 | – 3 SD | 99.7% |

0.84 | + 1 SD | 65% |

0.974 | + 2 SD | 95% |

0.997 | + 3 SD | 99.7% |

With the help of the above table, we need to execute the long trade when the value of density lies between 0.025 and 0.03 and we need to execute short trade when the price lies between 0.974 and 0.997

Let us take BPCL as stock A and HINDPETRO as stock B

To go long buy BPCL and sell HINDPETRO

To go short sell HPCL and buy BPCL

In the below video I presented how to execute the trade and here is the link to download the excel https://drive.google.com/open?id=1amZWZ_PtYsGdFe32ITxu0aTQEvBsqrtU

Good work brother,to share u r knowlege.thanks to u

Thank you are the response Pradeep. There are many other articles on the blog regarding investing and trading. Check them out. I hope you will like it.