## 14.1 – Position Sizing

I know, the discussion on pair trading was to end with the previous chapter, but I thought I had to discuss a special case before we finally wrap up. I’ll also try and keep this chapter really short ☺

So here you go.

I ran through the pair trading algo y’day evening (28^{th} May) and found a very interesting trade. Here are the regression parameters –

- Stock X = ICICI Bank
- Stock Y = HDFC Bank
- ADF = 0.048
- Beta = 0.79
- Intercept = 1626
- Std_err = 2.67

What do you think of it? Perfect isn’t it? Its ICICI and HDFC, two of the largest private sector banks, both have similar business landscape, both have a similar revenue stream, both regulated by RBI. Perhaps the perfect candidate for a pair trade, right?.

The Adf value is 0.048, which means there is only 4.8% chance that the residual is non-stationary or about 95.2% chance of the residuals being stationary, which is fantastic.

The std_err is +2.67, which is a perfect residual value to initiate a short pair trade. The trade here is short HDFC and go long on ICIC.

So, how do we position size this? Here are the price and lot size details –

- HDFC Fut Price = 2024.8
- HDFC Lot size = 500
- ICICI Fut price = 298.8
- ICICI Lot size = 2750

Remember we discussed position size in the previous chapter. We look at the beta and estimate the number of shares required for this trade.

The beta is 0.79, this means, every 1 share of Y needs to be offset with 0.79 shares of X. The lot size of HDFC (Y) is 500, this means to offset the beta, we need 395 shares of ICICI (X).

Do you see the problem here? The lot sizes simply do not match.

We cannot simply trade 1 lot each here like we did in the TATA Motors and Tata Motors DVR example, discussed in the previous chapter. If we do, then this won’t be a beta neutral trade.

Hence to position size this, we need to work around with the lot sizes –

The lot size of ICIC is 2750, beta is 0.79, lot size of HDFC is 500. Given this, that the lot size is higher than HDFC, what should be the minimum number of HDFC shares which will beta neutral 2750 shares of ICICI.

To figure this out, we simply divide –

2750/0.79

= 3481.01

Since the lot size of HDFC is 500, we can round this off to 3500. Considering the lot size of HDFC is 500, this will be 7 lots of HDFC against 1 lot of ICICI.

## 14.2 – Intercept

Alright, now that we know the position size as well, here is the big question – will you take this trade?

Everything seems perfect, right? ADF has a desirable value, residual is at 2.67 SD, the two stocks are highly correlated, the business is similar. So what can go wrong?

Yes, I agree, everything looks good, but on a closer look, the intercept reveals a slightly different story.

To understand this, we need to quickly revisit the regression equation –

** y = Beta * x + Intercept + Residual**

If you think about this equation, we are trying to explain the stock price of Y in terms of the stock price of X multiplied by its beta. The intercept is essentially that portion of the y’s stock price which the model cannot explain, and the residual is the difference between predicted y and actual y.

Going by this, a large intercept implies that a large portion of Y’s stock price cannot be explained by the regression model.

In this case, the intercept is 1626. The stock price of HDFC is 2024 per share, this means, 1626 out of 2024 cannot be explained by the regression equation. This means, the regression equation cannot explain nearly 80% (1626/2024) of Y’s stock price or in other words the equation can explain only 20% of the equation, which according to me is quite tricky.

This further implies, that if we are trading this pair, then we are essentially trading a very small probability here. I’d rather avoid this and look for another opportunity than trade this. Of course, I know traders who would love to jump in and take this trade, but for someone like me, I’d look at risk first and then the reward ☺

Good luck!

Thanks for the further insight

Good luck, Kalpana.

Hello sir

I have a doubt.

HDFC= 0.79*ICICI+ INTERCEPT+RESD

For every 100 shares of ICICI we need 79 shares of HDFCBANK. 1 Lot (ICICI)= 2750. Thus we require 2750*0.79 or 2172 shares of HDFCBANK. Therefore we need 2172/500 or 4 lots (approx) of HDFC to trade.

1 lot of ICICIBANK and 4 lots of HDFCBANK, i think, is a combination.

Thanks

For every 0.79 shares of ICICI, we need 1 share of HDFC. Given the lot size of ICICI as 2750, we need 2750/0.79 = 3481 shares of HDFC, therefore rounded off at 3500.

Thank you, sir. I got it.

Cheers!

Hi Sir. Thanks for bringing in another angle which we couldn’t think of. Its like inhaling a trading wisdom!

Just wanted to find out below;

– What are chances of getting stopped out say for ex: out of 100 trades (Just to asess success rate) both in 1st method pair trade method (correlation) and 2nd method (regression).

I’ve stopped using the first method long ago, Thirumal, and for the 2nd method, I think the success ratio is fairly higher something around the region of 6 of 10 trades working in your favor. The key here is to keep a sharp eye on risk parameters.

Thank you for the information sir

Welcome!

What intercept value is right you think?? Pair I am tracking explains 71.83 of NIFTy(y).

70-80% or higher is a good equation according to me. I’d be hesitant below that.

In today’s session it fell down to 63% , Do you think I should wait before it jumps back above 70% to take the trade.

Yes, that would be better, Akshay. Better safe than sorry 🙂

Hey Karthik,

Just wanted so Thank You, since you started this pair trading chapter I spent most of my time thinking about perfect pair trade setup.

I have finally found out using multiple regression method an equation that explains almost 99% of dependent variable.

Is it too perfect to be true?

99% seems too good to be true, Akshay 🙂

Which pair is this?

I am using more than one independent variable to predict just one dependent variable, like using few heavy weights to predict Index.

Yes, this is possible in a multivariate regression. But we have not really discussed that here 🙂

I tried using regression concept between two stocks but it was quite difficult to find stationarity, so I reduced my time frame & used multivariate regression. This is providing better results & stationarity.

Nice, good luck Akshay!

Hi Karthik,

Amazing write-up!!!

Just a query on hdfc hdfc bank pair. In last 15 days there was a deviation but it never reverted which is strange given it is a highly co-integrated pair.

Request your detailed analysis as a live example on this pair:

1. Whether trade was there in the first place ?

2. Which date would have been the best entry ?

3. Did it hit the stop loss? What should be the SL in such cases ?

4. Is averaging suggested if it moves against you ?

Thanks in advance.

Regards

Deepu

Deepu, I don’t track HDFC and HDFC Bank as a pair so I wont be able to answer this question.

On your query with averaging, no its not a good idea to average it out. Not just with pair, but every other trade.

Hello sir

I too run the regression b/w HDFCBANK(y) & ICICIBANK(x) for last 200 days starting from 7 Aug,2017. On 28-May-18 i got the following data:

Beta= 0.75, intercept=1639, std.error=67.74

But the ADF value was 0.732

On seeing the graph of residual it is clearly evident that the plot was continuously diverging from the mean from last 50-60 days.

Thanks

Hmmm, there is a big difference in the ADF values.

If you wish i could show you the plot. On seeing the plot i couldn’t convince myself that the ADF value could be that low.

Sure Mayank, but currently too many things on the plate. Maybe I’ll look at it one of these days. Thanks for your co operation.

Hello Karthik,

I have been trying to develop the script as you have motivated, currently, i am also getting the same results as KUMAR MAYANK posted above. If you could provide few things from your side, it would be great help to develop my code :

(1) Any 200 Day data of Any two stocks

(2) Output of Linear Regression on these data

(3) Output of ADF Test from your script for these particular data,

If you could provide these then it would be helpful to find out if my script is generating right data or not.

Thanks

Kalpana, you can download the data from here – https://www.nseindia.com/products/content/equities/equities/eq_security.htm and run the liner regression like explained here – https://zerodha.com/varsity/chapter/linear-regression/, you can even download the linear regression sheet. Unfortunately, I wont be able to share the ADF code as it does not belong to me.

https://docs.google.com/spreadsheets/d/1zUUTKwoTT3NfyEsHVEv1EMWJ13li3BF-pUWNlc_0Mmk/edit?usp=sharing

Hello, KarthikJi.

Good Evening,

gone through the last example you shared and it helps me a lot to accurate my trade decisions.

as u mentioned : In this case, the intercept is 1626. The stock price of HDFC is 2024 per share, this means, 1626 out of 2024 cannot be explained by the regression equation. This means, the regression equation cannot explain nearly 80% (1626/2024) of Y’s stock price or in other words the equation can explain only 20% of the equation, which according to me is quite tricky.

what if Intercept Value is negative (-) or sometimes greater than Value of Y stock Price ?

kindly go through the sheet i shared once pls

thanks

Mohit

Interesting point on intercept being -ve. I will get back to you on that soon. Meanwhile, if the beta is -ve, you cannot really trade the pair.

Enjoyed the whole module sir, is there a book or two that you can recommend to further my learning in advanced statistics?

is it prudent to pair HDFC with Nifty, since it has high weight-age in index calculations, also is there any rule that has to be followed while selecting pairs sir?

Hope I am not bugging you with too many questions, I see that you have split automobile segment in 2-wheeler and 4-wheeler, like that is there any sub category in IT and FMCG space?

No Mani, you are not bugging me 🙂

IT can be split as IT large enterprises like HCL, TCS, Wipro, Infy and medium enterprises like Mindtree, Sonata, etc. Same with FMCG.

Mani, we will have to run through the regressing to test to identify if this is worth as a pair.

Check this book, Mani – https://www.amazon.com/Pairs-Trading-Quantitative-Methods-Analysis/dp/0471460672

Hello Karthik ji,

As mentioned above in this case we had 1626 Intercept for Y stock HDFCBANK price at 2024.

In some cases I had negative values of intercept and in some cases it is more than Y stock Price .

Kindly suggest on how to interprete it.

Thanks

Negative values cant be traded I guess. Will get back on that. Dont think it can be more that y’s price.

Hello Karthikji,

Pls clarify the doubt about it, m confused still …

Thanks

What is the doubt, Mohit?

Hello sir

You said that the intercept should be much lower with respect to “y” or “beta times X”. I have a doubt. What if the intercept is low but the variance of it is very high or the value of t-stat is very low? Will you take a trade if all parameters are fine save this?

If intercept is high but its variance is quite low or the value of t-stat is very very high. Will you trade it if all other conditions are met?

Thanks

This is the reason we filter them with the ‘Error Ratio’ 🙂

Sir

Next topic can be on Personal finance

Thanks

Thanks Siva, will give this a thought.

Hi sir, could you please share the latest pair data sheet

Thanks

Here is something you may like – https://twitter.com/ZerodhaVarsity/status/1004200948531585026

Many Thanks

Welcome!

Hi karthik,

How many modules do u plan to write???

I’m tempted to write 2 more – Mutual Funds and Financial Modelling 🙂

What about Quantitative analysis ??

Is there a Chapter on above topic?

This is quantitative, Ravi 🙂

I think, you are missing a module on Qualitative Analysis.

Hello Karthik Sir ,

Will you please consider to write a few chapters on “The ugly side of the markets” like the operators circle , the fake multibagger messages and how prices are manipulated by biggies . If possible how to identify it , either for our benefit or to completely stay away from it . And would also completely love to hear some of stories about this.

Interesting suggestion, Atharva 🙂

Will think about this.

Hi,

Can the ADF plug in utility can be have for a price or can I get in touch with the developer?

Suggest you find a developer for building the algo.

Dear Karthik,

I saw tweet about finishing of this module.

I request you to please consider module regarding excel modeling for analysing stocks, options, futures etc.

Thank you

Pramod

The discussion on Pair Trading is done, Pramod. There is more to discuss in this module. We already have enough content on Futures & Options in Varsity – https://zerodha.com/varsity/

Hello Sir, Thanks for all the modules of the varsity. I am a regular varsity reader and all this materials have just increased my confidence to trade. Was curious to know if this is the last module or you plan to introduce some more concepts?

Also, kudos to Zerodha for attaining the most number of active traders in such a short span. Its a pleasure to have brokers who are great mentors too.

Pritam, I’m so glad you liked the content here. I plan to discuss few more trading systems in the module. Post this module, I may stop adding new content for a while. But I do intend to have a module on financial modeling and personal finance sometime soon.

Hello sir

I got a trade opportunity b/w SBI(X) and Baroda(Y) on 5 June with 200 data points.

Beta= 0.438

Intercept= 28.76 (22% of Y)

Z-Score= -2.678

ADF= 0.0109

But i faced a problem with the position sizing. If i long 2 lots (8000) of Baroda then ideally i should have shorted 3504 shares of SBI whereas one lot of SBI has 3000 shares. If i try to balance the size then capital (8 lacs) requirement goes beyond my reach. Still i have been tracking it on paper with 2 lot of Baroda and one lot of SBI.

I want to know your views on the 1) Trading signal 2) Position size.

Btw, the trade is in green 🙂 and touched the profit of Rs 2600 when zscore was at -2.255. Got some relief after a setback in Baroda-IndianBank pair.

Thank you very much, sir 🙂

ahh.it was a profit of Rs 26000 on paper. Have missed to add one more ‘zero’ 🙂

Hope this translates to real money soon 🙂

Hello sir

I have been tracking the SBI and BOB pair and logging the details. On 11 June the trade was at 28000+ profit with Z-score of -2.11. Now today 18-06-18 the trade ended with the loss of -19500 and z-score 3.11 (dynamic Z-score is -2.84). I checked the adf value and it was 0.1214.

I wish if your comment on this trade, sir 🙁

Thank you

Kumar, its just unfortunate that this pair is taking so much time to converge. This is, in fact, the drawback of pair trading – you need liquidity and patience to hold the pair.

This should also give you a sense of optimizing each pair – not all pair may be worth initiating at 2.5/2.7 and closing at the mean, sometimes, based on the pair, you may want to initiate and close quicker.

Yes, this seems like a valid trade and the best possible position size is 2:1 on BOB:SBIN.

1) Perfectly valid signal

2) 8000 BOB vs 3000 SBI

Ideally, you should close the position when you hit ard -1 on Z-Score.

Is it advisable to track the pairs live during trading hours or end of day better?

Yes, it does. You need to track the Z-score.

hi karthik where can we find the trading pairs list, like u said u will publish the same every week

Will upload the file today in this chapter.

Hi Sir,

Thanks for such a wonderful chapter about pair trading. The way you teach is quite remarkable. Eagerly waiting for the next trading system.

Could you please suggest some books (not pure statistics books) for multivariate regression which is applied for trading along with any case study.

Manoj, unfortunately, there isn’t much content on Pair trading itself, forget Multivariate 🙂

All you can find is few SSRN papers on the concept.

I will probably discuss an easy way to trade calendar spreads next 🙂

Hello Sir,

This was an excellent module, enjoyed reading it.

I wanted to know, while looking at the intercept, what percent do you consider should be explained by equation for Y (dependent variable) ?

Thanks, in advance.

Glad you liked it, Pritam. Intercept should explain at least 70% of Y.

Thank you for writings..

What will be the next module Karthik gaaru

Next chapter will be on Calendar spreads, hopefully next week 🙂

can we get any purchase link for the ADF test plugins

I think Mayank Kumar had suggested few links in one of his comments, maybe you can check that.

Hi Karthik,

You have mentioned in this post that, this post is risky because 80% of HDFCBANK cannot be explained. Can you specify below what % of Std. Error it is safe to trade on the pair. I get that 80% is definitely high. But below how much % would you have considered this trade as safer?

Thanks for the brilliant post on this topic. You have really simplified the paid trading topic.

Pratik, I prefer pairs where the intercept explains at least 70% of the dependent variable.

Hi Karthik,

Thank you for the fantastic work but the topics are very heavy for the common people. Your creation of any topic and teaching method is fantastic. Your way of viewing in each topic always stunned me and I learnt a lot. My small suggestion is Personal finance for the next chapter with lesser math but with new idea.

Sankar, thanks for the kind words and suggestion. I have always wanted to do a module on PF, will try and do the same shortly. Thanks.

In 12 Jun pairdata list y stock bank Baroda and x stock sbin beta neutrality 4000/0.44=9090

Then we need to sell 3 lots of sbin for every 1 lot bank Baroda buy, Is it right?

Thanks in advance sir..

Nope, 2 lots of BoB with 1 lot of SBIN.

Hi Karthik.when can we expect financial modeling…

Sometime this year, Shiva 🙂

Is it possible for you to upload the sheet where we can get the trade signals?

Trying to do that, Shivu. May take some time.

Hi Karthik, The entire strategy series was lovely. I had read linear regression earlier but thanks to you now I am learning to apply them on trading setup. One request/suggestion on the next topic in the line of many such requests. There are many traders who are using Market Profile but there is not very good study material available on web. Can you plan some chapters on this topic & its usability along with price action.

Thanks!!

Glad you liked the content, Sumit. Content on market profile has been on the radar for a while, will try and put this up sometime soon, thanks 🙂

Glad to know that MP is in the radar. thanks!

Cheers!

Dear Karthik,

Can you please tell me how to calculate change in bank nifty ( or any other index) due to change in stocks.

say HDFC bank having weightage around 34 %. If HDFC bank rose by Rs 25 how much likely change in bank nifty considering other stocks being constant.

please help me how to do this in excel for all constituents of bank nifty.

You can use the Nifty Sensitivity tool here – https://www.equitymaster.com/india-markets/nse-replica.asp?utm_source=submenu

Thank u karthik ji .

But only has the nifty and sensex and not bank nifty.

Could please elaborate on how to calculate on excel

Sorry, Pramod. I’m not sure if I understand your query. Can you kindly elaborate? Thanks.

I want to check which stock is driving bank nifty on any single day if bank nifty is in good momentum.

That is why i want to know how much points are contributed by any bank nifty constituent stock say ICICI bank.

Eg

If icici bank changes by 4 points how much change there will be in bank nifty is other stock are assumed to be constant.

Is this kind of working possible in excel? if yes.

Then can u please help in doing this analysis

Thanks you

Equity Master has this sorted out already, check this (look for Nifty Sensitivity) – https://www.equitymaster.com/india-markets/nse-replica.asp?utm_source=submenu

I really like knowledge shared here on varsity. It is very useful to a trader like me to understand various aspect of trading.

I follow this pair trade section particularly.

I found something on ADF TEST.

I DID NOT KNOW SINGLE THIS ABOUT IT

BUT MAY BE MR. KARTHIK TELL US WEATHER IT IS USEFUL OR NOT.

http://www.spiderfinancial.com/support/documentation/numxl/reference-manual/statistical-tests/adftest

I’ve never used this, Vihar, so I really cannot comment on this. But sure does look good enough.

Hi Karthik,

The two pair data sheets uploaded with last 2 chapters have got tata motors & tata motors dvrm pair as both (x & y) & (y & x) each. Does that mean we can trade both of these pair?

Sumit, I think the only valid pair is TMDVR (X) and TM (Y).

Hi Karthik,

I regressed Bank Nifty & Nifty using last 200 days data. The stats coming for 1) BKNifty(x) & Nifty(y) was intercept coeff = 2498 & Std error of intercept/Std error = 2.175. Other pair 2) BKNifty(y) & Nifty(x), intercept coeff = -1283 & Std error of intercept/Std error = 2.55. My q is If we go by smaller error ratio, pair 1) the value of intercept coefficient is big. The value of intercept coefficient is less for 2nd pair but error ratio is big. Should we still go ahead with pair 1)?

We cannot go with a -ve intercept, so your 2nd option is not viable. The first one has a large intercept I guess. So either ways, it may not be a great pair to trade 🙂

Sir please provide commodity pair data sheet too.. Thanks

Have not developed one, Kehav. Will check if this is possible. Thanks.

Hi Karthik, thanks for the prev response!!

I have set up few other trades using regression data from 12th june excel and am tracking the trades. Pardon me for a long post ahead.

My question are on another trade setup between Andhra – Allahabad bank pair. Set up – (Allahabad Bk = y & Andhra Bk = x, Beta = 0.76. Z score was -1.72 at the time of trade). To make a beta neutral pair, I did long on Andhra BK(10000 lot), short Allahabad Bk(10000 lot) and long stocks of allahabad Bk (2346 Stocks in spot). What happened is that trade moved in favour and z score changed to -1.68 but profit went down due to excessive loss in 2346 extra stocks I purchased for beta neutrality. If I remove this long position than my actual profit has gone up since the trade execution.

1: Is it that by using beta neutrality I did a trade off between risk of z-score going further away from mean & amount of profit that pair will make If z score goes toward mean ?

2: Should we make every pair beta neutral?

3: Practically how long can we use same set of regression data without calculating again?

4: If we find a particular pair has stationary residual, will the pair remain intact unless their is substantial change in fundamentals of any stock. In other words, do we need to keep on running adf test on a particular pair very often?

Thanks again

1) Not really, Sumit. Beta neutrality ensures your risk is in check.

2) Yes, at least in this way to pair trade

3) Ideally for every new trade

4) Not really, all else equal, adf remains same.

Hi Karthik,

Thanks for the excellent write up time and again.

Quick observations:

1. The stop loss in most cases is given as 0.5 SD but what I have seen that it goes to+- 3 SD and reverses many a times so is it advisable to keep the stop loss as 3 SD ?

2. Further in highly co-integrated pair like Tatamotors the pairs does eventually reverts so should we hold on to the trade ?

3. Is it always ideal to enter at +-2.5 SD level or we should wait for reversal then make the entry ?

4. After reversal also many a times it does not sustain and starts travelling in the unfavorable direction ? How to identify proper reversal ?

Request your views on the above points.

Thanks in advance.

Regards

Deepu

1) Yes, keeping the SL at 3DS makes sense. So you usually initiate the trade around 2.5 and keep an SL at 3sd

2) Yes, for this you need both patience and conviction 🙂

3) It is best if you can enter around 2.5, things like ‘waiting for reversal’ can add subjectivity in your analysis

4) This is tough

Good luck.

When can we expect another pair data sheet.

Thanks

Keshav, I will try and upload the file sometime today or tomorrow.

Sir have u uploaded the pair data file.?

Ah, no. Will do today.

hiii sir,

can you tell me how to calculate z score of pair stocks and how to calculate sigma and which intercept we have to take while pair trading??

is that intercept work which will revived after regression??

and i am not sure how to calculate z score please help me with this

Ricky, have explained this in the previous chapters. Can you please take a look? Thanks.

yes thanx for your help sir,

i have understand about intercept but still i cant figure out how to calculate Z score

The latest residual divided by sigma gives you the Z-score.

thanx for such a help sir,

and m sorry if i m bothering you,

but how to find sigma

No problem, Ricky.

Sigma = Residual/Standard Error. I’ve explained in this chapter.

i havent find any thing about sigma in this chapter sir,

but thanq so much for your help…

now i have new query.

which residual we have to use for calculation of Sigma??

is it RESIDUAL OUTPUT or ANOVA RESIDUAL which we had after liner Regression

Look for it in the previous chapter.

Sigma = Today’s residual / Standard Error of the residual

yeah i have found it..

its in one line so i have missed it.

my bad..

and again thanx for your help sir..

sir i have read again previous chapter and from i have discover in that chapter you had take live example of Tata motors and Tata motors dvr. in which you calculate std_err as same as you comment me how to calculate sigma so sir my question is you are saying that we can take std_err as Z score to open/exit potions in trade…

do i understand correctly or wrong sir..

Yes, that’s correct, Ricky.

Good luck, Ricky!

thnq very much for your help sir,

this will help me complete my code…

Good luck, Ricky!

Excellent contribution sir.. one query, why one can not perform pair trading using Options ?

Thanks in advance

Pair trading works best when there is only 1 variable to tackle i.e the direction. When there are multiple variables like for an option, you can’t really set up a pair trade.

Sir u r not uploading pair data sheet

Hi Karthik,

Just wanted clarity on something. The time period of closing price data to analyse is for 2 years and this will be rolling 2 years right? In the sense, if today i measured the adf test value and residual for (say) HDFCBANK vs BajFinance for 2 years of data (6th September 2016 to 6th September 2018) then tomorrow I would repeat this for 7th September 2016 to 7th September 2018?

Thanks in advance!

Jayram, yes, this is the rolling data.

Thank You!

Hi Karthik,

I find that the length of data series is significantly affecting the parameters. Is two years closing price the best for analysis ?

Appreciate your response !

Regards.

Rajiv, I know traders who work with last 6 months data. It is best if you can calibrate the model and figure out which time frame yields the best possible results.

Thanks a lot for your response Karthik , I must say just like others have commented earlier , you have done an exceptional work with this varsity.

Keep it up 🙂

Many thanks, Rajiv 🙂

Happy learning!

Karthik,

Some trades close within a expiry but some takes more than 2 series to close.

Why this huge difference is? any way to guess how much time it will take to close the trade?

Thanks.

Swapnil, no, predicting timelines against stock price movement is a very hard task 🙂

You have mention that you would upload update pair data sheet in one week or 15 day interval, where i should look for it ? and that data sheet will include std|_err, sigma column.

Salim, for some reason that has not happened, will try and look at this again. Meanwhile, do check out the free link readers have submitted.

Sir, How to use pair trading system to trade options rather than futures??

Can i get a detailed explanation?

I’ve never explored that angle, Karthik. So I don’t think I can comment on this.

Dear Karthik, what do you suggest on which expiry we buy or short the futures of current or current +1 or current +2 months?

This depends on the pricing of futures. As a thumb rule, you buy the cheaper futures and sell the expensive one.

Dear Karthik,

One thing is clear that -ve beta cannot be traded with a valid reason behind it but what issue -ve intercept is creating, i m not understanding? anyway we are minimising intercept (error ratio), hence whether it is +ve or -ve, it won’t matter as far as it is minimised.

Pls clarify

Dear Karthik,

reply is still awaited, pls clarify my issue.

One thing is clear that -ve beta cannot be traded with a valid reason behind it but what issue -ve intercept is creating, i m not understanding? anyway we are minimising intercept (error ratio), hence whether it is +ve or -ve, it won’t matter as far as it is minimised.

Dear Karthik,

Talking of beta neutral, we r using it for investing equal amount in both the paired stocks. But dont u think we also need to be neutral such as in the form of hedging. If one stock goes down by 10 points then another stock if pulled up by 10 points, I am at No Loss.

For this to happen, arent we suppose to invest equal lot size in both the pairs so that both stocks counter balance each other’s P&L and give us profit?

Talking of beta neutral, we r using it for investing equal amount in both the paired stocks —-> No, this is not true, Arun. Beta neutrality ensures we are equal weight on risk, and not on the amount invested. Rupee neutrality on the other side ensures we are equally invested in both the paired stocks.

sir , bank nifty vs nifty has correlation 0.93 can we take as intraday 30 minutes data for last 60 days ?

as you mentioned in commodity topic , gold vs silver has good correlation above .80 for intraday purposes .

and what is your opinion sir ?

Yes, Jaya. 0.93 is a strong correlation, you can consider this.

sir thank you so much .

Welcome, Jaya!

sir weekly options on nifty

low cost ETF ICICI NIFTY VALUE 121

RATIOS 11420/121 = 94 UNITS MULTIPLE WITH 75 TOTAL 7050 UNITS

INVESTMENT VALUE NEARLY 853050/RS

SELLING OTM VALUE 100000

SIR IS THIS METHOD RIGHT ?

HOW CAN WE SELECT RIGHT STRIKE FOR SELLING OPTIONS ?

SIR WILL YOU INCLUDE THIS SPECIAL TOPIC FOR “PASSIVE INCOME STRATEGY” IN DETAIL ?

Will probably include passive income in the personal finance module, Jaya. Btw, you can select the strikes based on 2-3 standard deviations away from the current market price.

Dear Karthik,

As posted by Kumar Mayank on 31 May 2018 at 11.30 A.M. that ADF test is 0.732. I have run ADF test for the given period given by Kumar Mayank and found that this test is in constant only parameter. But I asked you some days back that which parameter should be chosen and you told me that no constant parameter should be chosen. I am very much confused. Pl clarify.

Rohit, use the no constant and no trend parameter for ADF test (in the context of pair trading).

Dear Karthik,

In spiderfinancial.com, there are four parameters for ADF test viz no const, const only, const + trend, const + trend + trend^2. Is no constant and no trend parameter is equivalent to no const which is given in spiderfinancial.com. Pl clarify me.

Rohit, I’ve not really used spiderfinancial. I guess you should speak to them for support, especially since its a paid software. Please check with is the no constant, no trend equivalent on their application. Thanks.

Dear Karthik,

If all parameters like z-score, adf test are fine, is it necessary to consider the explain of intercept of y variable which should be at least 70% before initiating pair trade? Pl reply me.

Yes, you need to look at that as well.

Dear Karthik,

Thanks for reply. I have calculated pair trade of idbi and canbk as on 22-8-19 as under:

idbi(x) and canbk(y)

z-score – -2.14

beta – 0.361

ADF – 0.027

Intercept – 242.77

spot of idbi – 24.45

spot of canbk – 209.8

All parameters are ok but Intercept is very high as compared to y stock. I want to ask you whether sometimes intercept can be higher than y stock price and I think that this type of pair trade should be avoided. Am I right?

Yup, but please do backtest for the same before concluding.

Dear Karthik,

Sorry for inconvenience to you.

The answers that you gave in this chapter asked by different persons which has created many confusions to me as under:

1. Pl refer to Dated June 11 2018 at 11.23 am in which you answered about position sizing that the possible position size is 2:1 on BOB:SBIN. This is contradiction because according to data i.e. SBIN(x) and BOB(y) and Beta is 0.438 which are given by Kumar Mayank on dated 11 June 2018 12.34 am, position size should be calculated according to the chapter of Live example -1 as: for every 1 stock of BOB(y), I need to have 0.438 of SBIN(x) which according to this, the lot size of BOB is 4000, so I need 4000*0.438 = 1752 shares of SBIN and lot size of SBIN is 3000. So according to this calculation, the ratio should be 1:2 on BOB:SBIN. Am I right?

2. Pl refer to 21 June 2018 at 11.36 am in which you answered that “the first one has a large intercept I guess. So either ways, it may not be a great pair to trade.” This also created my confusion because according to first pair of data given by Sumit on dated 20 June 2018 at 6.47 pm that Bknifty(x) and Nifty(y) and Intercept is 2498 and price of nifty was 10772 and Intercept of explain on Nifty is 76.8% then how can you say that intercept is large on nifty which cannot be explained. Pl clarify this.

Awaiting of responses would be appreciated.

Response of above queries are awaiting. Pl reply me.

Rohit, in terms of lot size it works out the same right? i.e. 2 lots of BOB versus 1 of SBIN? As far as the intercept is concerned, I’d suggest you look for a lower intercept and ignore the beta. A low intercept implies a better is the linear relationship between X & Y.

Dear Karthik,

What is based on the low intercept? Pl clarify me and give one illustration.

The regression equation should explain at least 70% of the variation of Y based on X. This, of course, is based on the trader’s perspective which is again dependent on the risk-reward temperament of the trader.

Hi Karthik,

I was reading a article by The Economist about Bridgewater and how it manages the hedge fund by doing Quantitative analysis. The article explained how Bridgewater and other Hedge Funds have now started using AI. So do you think that with the emergence of all this Quantitative analysis and AI, the way that Trading and Investing is done presently will get vanished in the future?

Thanks in advance. And wishing you and your family a Happy Vijayadashmi.

The techniques and approach may change as it has for many decades now, but the core underlying fact i.e. the markets being driven by human’s greed and fear will remain the same 🙂

So do you think that Fundamental and Technical analysis will still strive in the coming decades?

My guess is that both will continue till the foreseeable future 🙂

Thanks 🙂

Dear Karthik,

Sorry for my silly questions. Last month i.e. September month, I got opportunity 3-4 different pair trades method 2. But now for the last more than 30 days, I am not getting suitable different pair trades of stocks of different sectors viz banking(psu & pvt), IT, oil, auto(2-wheelers & 4-wheelers). Is the same occurs with you as well? As I want to trade pair trade method 2 atleast one every month. But this time I am not getting one. Please help me.

This is a common thing, Rohit. You can have many dry weeks, sometimes few months without a pair trade. The idea is to just wait patiently.

Karithik,

Thanks for reply. Now my doubts have been cleared.

Happy trading, Rohit.

so what percentage of intercept is acceptable according to you?

SIR PLEASE, ADD NEW TOPICS ” HALF LIFE CALCULATION AND HURST EXPONENT ” IN PAIR TRADING THANK YOU SIR.

I’m not sure about the relevance to the topic, I need to understand that first. Will do.

Hi Karthik – I am a member of Zerodha and I have gone through the approaches. I must say very well written and explained, thanks for these. I just wanted to enquire are you publishing any daily pair trade file identifying the pair trade opportunities which I can access ? Thanks.. .Romit

No, Romit. We were unable to continue doing that.

Hi Karthik, great module.

I get the entry, sloploss and target points.

But how to actually calculate the loss/risk before entring into the trade. If I take entry at 2.5sd and I know that I’ll exit at 3sd but how to calculate the loss for.this scenario beforehand. And the same applies for the target as well, so that I can calculate the profit and understand the risk reward ratio of the trade.

Thank you, awaiting your reply

It is hard to get the Rupee value of risk here. You need to develop a sense for how much the P&L for every 1/2 SD, so that you can extrapolate.

Hi Karthik, could you please throw a little insight as to what to understand with such high z-scores.

I did this analysis with 224 historic values. I didn’t expect the deviation to be this high.

Also, i have calculated correlation as well as p_values, for all these values the supporting values of correlation and p_values are very good.

correlation >0.95 and p_value <0.01 for all the shown data

But the z_score is much father away from -2.5 and 2.5 and how to take trade in this scenario?

Thanks 🙂

index 147

beta 2.719

corr 0.962557

intercept 93.434

p_val 0.00191435

residue_error 24.7655

xstock APOLLOTYRE

ystock M&M

Name: 0, dtype: object

zscore: -4.283645159104744

index 214

beta 1.422

corr 0.961086

intercept 138.68

p_val 0.00066019

residue_error 13.2215

xstock APOLLOTYRE

ystock ADANIPORTS

Name: 3, dtype: object

zscore: -4.052991606604638

index 699

beta 16.405

corr 0.953977

intercept 3005.08

p_val 0.00361484

residue_error 605.017

xstock AXISBANK

ystock BOSCHLTD

Name: 8, dtype: object

zscore: -3.0311053309864517

index 1020

beta 3.151

corr 0.943505

intercept 48.64

p_val 6.34319e-05

residue_error 6.57083

xstock NATIONALUM

ystock EXIDEIND

Name: 10, dtype: object

zscore: -3.219869547946847

index 2091

beta 0.724

corr 0.956734

intercept 243.759

p_val 0.00597968

residue_error 25.8498

xstock AXISBANK

ystock RAMCOCEM

Name: 14, dtype: object

zscore: -3.6732927070244323

index 2364

beta 0.364

corr 0.984302

intercept 21.036

p_val 0.000680491

residue_error 3.61731

xstock CANBK

ystock BANKBARODA

Name: 16, dtype: object

zscore: 3.455939216430429

This is weird, I’m unable to point a finger to this. Let me check with this with few others.

Thanks, I would also like to add that the calculation is done between cross sector stocks also, again, the correlation and p_val are still very good, picking one from above table :

index 2091

beta 0.724

corr 0.956734

intercept 243.759

p_val 0.00597968

residue_error 25.8498

xstock AXISBANK

ystock RAMCOCEM

Name: 14, dtype: object

zscore: -3.6732927070244323

I don’t know why these companies have this high corr of 95% and pval much less than 0.01.

And i have good very supportive values like this throughout my dataset in these cross sector companies.

But the z_score is still the pain?

could you please through some light on both

1)high z values

2) good values between cross sector stocks

What is advisable to do

Thanks, awaiting your reply 🙂

Btw, why are you even attempting to pair two unrelated stocks! Do this for two stocks from the same industry and check the variable again.

Are there any plans to include a chapter or two on multivariate regression or would you please refer some good books or websites on the topic. I’m pretty curious to know. Anyway thanks, great chapter, a very unique insight

Not for now, looks like that will be an ultra-complex topic to breakdown 🙂

Hello Karthik Sir,

when you say the regression equation cannot explain 80% (1624/2024) of Y Stock price.

That implies we should trade those pair whose regression equation is low.

Regression equation should be like 0.30 or below. Yes, risk/reward parameters are different for everyone.

Also found a developer who can help me build algo at a good price.

Thank You.

It’s a tricky problem, Anil. If the regression is strong, you get reliable trades but will be rare. If the regression is not strong, you get frequent unreliable trades

Go for R2 of 0.7 or higher.

Dear Karthi Sir,

In one of the Pair trade, Nestle & Britannia.

1.) Britannia(Y) and Nestle (X). Std Error is 0.76. Also, the Regression Equation Can Explain 76% of the Equation(Intercept).

2.)Nestle(X) and Britannia (Y). Std error is 0.58. Intercept is 42%.

before proceeding for ADF test, which combination should I consider, I mean which stock should be X or Y.

Before this chapter, I would have selected 2 option as the Std Error is Low.

Need your help to understand this better

Go for the first one.

Thank You Sir!!

So in General practice, before calculating ADF value, should I calculate regression Equation(Intercept) first.

Because in Live Example 2, ADF value:0.04, Z-score: 2.67 which looks perfect to trade but Large Intercepts is unable to explain the 80% of the equation.

So in Britannia(Y) and Nestle(X), I calculated the Intercept first.

Once Intercept can explain 70-80% of the regression then I am going ahead with ADF and other parameters.

Please correct me, if this not the right way to look at it.

Thank you so much for your help.

Thats right, good luck, Anil.

Small Confusion, when you say go for R2 of 0.7 higher.

Should I consider R2 variable which I get from the linear equation?

or

Intercept/current stock price?

because In live example 2 HDFC vs ICICI, =1626/2024= 0.8 . where equation can explain 20% of the equation.

Linear equation.

Thank You so much it will help me a lot!!

Happy trading 🙂

Hi karthik.

i m slightly confused with position sizing.according to live example 2

hdfc(Y) price rs.2024 lot size 500

ICICI(X) price rs.298 lot size 2750 .beta 0.79.after calculations 3500 shares of hdfc required to offset 2750 shares of icici bank for beta neutral trade.accordingly i m slightly confused in position sizing of nifty(Y) and bank nifty(X).

nifty price (Y)price 11400lot size 75

bank nifty (X)price 22500 lot size 25.how to evaluate position size nifty(Y) against bank nifty(X) for beta neutral trade.

Look at it from the value of the contract and not just the lot size.

Thank u karthik.struggling with adf test.not able to find it online in some links provided.doing it manually is cumbersome task.as the mean value of stocks in good correlation too are not close to each other.failing the first test test of stationarity.

I think Anil has posted a link for ADF test, its an excel plugin.

can u plz update the new pair data excelsheet.

We stopped doing that, Manish.

We see no discrepancy in the current sheet.

I have one doubt, the stop loss of z-score is 3 , so is the stop loss for real time basis or is it at the closing of the day ?

It can be either, depends on your risk appetite. I’d keep it in real time.

Hi Sir

I have few doubts:

1) I am using no constant, no trend in ADF. Is this correct?

2) What should be the lag order? (Taking 200 observations)

cube root of observations — i.e. (200)^(1/3) = 5.8 ~5

OR

— 12* [obervations/100] ^(1/4) = 14

3) What method do we need to use — AIC or BIC or t-stat

Thanks

Animesh

Hi Sir

Requesting for your help

How can I help, Animesh?

Hi Sir

I have few doubts:

1) I am using no constant, no trend in ADF. Is this correct?

2) What should be the lag order? (Taking 200 observations)

cube root of observations — i.e. (200)^(1/3) = 5.8 ~5

OR

— 12* [obervations/100] ^(1/4) = 14

3) What method do we need to use — AIC or BIC or t-stat

Thanks

Animesh

1. Correct

2. 5 in this scenario

3. T-stat

Sir is there any article which you would refer for developing our algo keeping as a reference

And if Ive no idea,who can help me

I think Learnapp has introduced a course, you may want to check this – https://learnapp.co/adv-courses/python-algo-execution-programme , figure out if this is what you are looking for before you subscribe.

sir does the price paid for stock y and x match or we should blindly go with beta based position sizing

Prices wont really match, there will be differences.

Can we make same trade in options instead futures

Nope, not possible, Sourabh.

Can pair trade concept be applied to 2 stocks for total different industries ? Eg. TCS n HDFC. Provided they pass the Error Ratio n ADF prerequisites?

Because since we are analysing the trade statistically, so whether scripts are of same same or different industries may/may not matter right ? Backtesting can provide more insight to this, but currently I don’t have algo developed to test this n so asking the question.

Yup, technically you can. In fact, many traders do not apply any subjectivity to their pairs i.e. wipro and TCS should go hand and hand. They simply trade pairs by stats.

Sir, when we have positive beta value then we proceed live we did in live examples. But if all other condition satisfies and beta is negative then how we will long and short the respective stocks?

This is an issue, Sarthak. -ve Beta wont work.

Hi Karthik,

Trust that you are doing well. Not sure if you are still tracking messages here. But still let me try.

I read thru all the chapters on pair trading in one go. Excellent info and very lucid style. Probably I am joining the party late (almost 2 years after you wrote this).

I had couple of questions:

1. Should trades be avoided during results, since z-score may easily go to 2.5sd as you may have results from one company announced but not from the other.

2. Also, once results are announced, based on the quality of results the relationship may change and the would need some time to settle.

3. Since it is 2 years now since you wrote this, any fine tuning is necessary or the process holds as is to date.

Regards,

Hi Srinivas, yes, I do keep track of messages –

1) Better to avoid during results, fundamental events tend to disrupt the natural state of the pairs

2) YOu can set up the trade maybe the next day, maybe give a day for the dust to settle. But this really depends on your risk appetite.

3) Not really, content and concepts remain the same.

Hi Karthik,

Thanks very much for the quick response. For 3 above, we can still stick with 200 day history?

Regards,

Yup, you can.

In your last chapter you discussed about multivariate analysis as well. I am having decent understsnding about multivariate analysis. Can you suggest some book or some reading material for the same. Tha ks

Unfortunately, there aren’t any books on this topic Pradeep. At least, I’m not sure of such material. Most of the concepts should be developed by your own R&D.

Hey Karthik

Can you please provide some more insight and teach on Multivariant Regression with real time examples. It would be really great.

Regards,

Ravi

Ah, not sure. Let me try 🙂

Thanks Kartik Eagerly waiting for your post!!!!

Sorry, I missed the context, post about?

Hi,

I am having two questions with regard to pair trade.

1) While doing the backtesting, should we use adjusted closing prices (adjusted for splits, dividend, rights) or closing prices (adjusted for splits).

2) at most of the places, i have read that one should use adjusted closing prices for backtesting. however, the problem with using adjusted prices is: suppose we are trading stock A (trading at 100) and stock B (trading at 120). so the spread of 20 doesn’t generate any signal for us. however, 1 month down the line, A has a dividend of 3Rs when we adjust previous prices, then 100Rs of stock A becomes 97 and then the spread of A vs B becomes 23 and our models generates a signal. however, in reality, on that day, stock A was actually trading at 100 and so no signal. i feel when we are using adjusted prices, we are actually having look-ahead bias.

so would like to know what’s the right thing to do or your thoughts on the same given you have been doing the same for quite some time.

1) Yes

2) That’s ok, but if you are not using adjusted price then the issue is that you are actually using the wrong data to build your pair trade model

Hi Kartik,

In order to get the number of futures of Y, suppose if i divide X by beta and i get something like 600 shares of Y wherein the 1 lot of Y contains 400 shares then how do i go about it. because 600 shares means 1.5 futures. thanks

Traders usually buy 1 lot plus 200 shares in such cases.

Sir,Thank you for sharing these much valuable information’s with us. We are keen to study multivariate regression.When can we expect that?

That will take sometime, Abu 🙂

Hello Karthik Sir,

I have one more doubt.

In pair trading, when all the conditions as you’ve elaborately mentioned over the pair trading module 2 is met, we go long and short on two Futures contracts belonging to two different underlying.

While doing so, futures of which expiry should we choose? Current Month, Near Month, or Far Month..?

It is best if you can stick to just the current month contract, Abu.

Thank you for your valuable feedback, Sir.

Good luck, Abu!

Suddenly everything starts to makes sense and people says, “math formulas won’t be useful in your practical life”, well here you go! 😀

I want to thank you that you are providing us with such amazing content and that too with instant support. I am really lucky to have people like you here!

Thank you so much!

Hahah, ppl use math quite a bit in trading. It goes too deep and I even tried understanding a few concepts, but it is beyond me. I gave up. But I hope the material here encourages you to learn more! Good luck 🙂

Can you please suggest me resources to learn quantitative trading? Books, courses or anything else

Check willmot forums, it used to be super active back then, not sure now.

Thank you for suggestion! will check

Sure. Good luck!

Hii Karthik thank u for this module.

What if Intercept value is higher than Stock y or negative?

Most pair Has higher Intercept value can you tell how frequent trading oppertunity arise for you?

here are some example of it

https://www.equityfriend.com/traders-tool/pair-trade-opportunity-and-analysis.html

If intercept is large, it means a large portion of stock Y is not explained by stock X, this is a risk. We are trading on deviations of part of Stock Y, and other component (intercept) changes can affect your trade negatively. A short recommendation is, if intercept is < 20% its fine, 20 - 30% is border line, high values are risky.

Ok

In such a scenario trading opportunities are not very frequent

Yes, pair trading opportunities are not frequent.

Hi Karthik. I recently went over the whole chapter. Kudos to you and you’ve really explained all the concepts very well. Just wanted to ask you how this strategy has been doing recently and also is there somewhere that you are updating the Pair Datasheet? Would be a great help if the updated version is available. Thanks a lot.

Dhruv, thanks. Glad you liked it. No, we have not been updating pair data anywhere. I’ve not tested this strategy in recent times, but I’d suspect it would have done reasonably well if its well-calibrated.

Can an intercept turn out negative. If yes what does it imply

Dear Sir,

I have learnt so much from your contents in varsity. Especially, I am studying this pair trading concept in depth. I had 2 queries, if you can please help me with that.

1. while placing the trades, will there be a problem, if I hedge the positions by buying options? as I feel, it will negate the risk drastically.

2. Do we need to check the fundamentals of the pairs? for example, if a pair occurs between a larger and smaller company stock, like wipro-coforge, is it prudent to take the trade if all other criterias match? coz these two have huge difference in their MCap.

1) It will, but it will also introduce new risks. YOu need to figure that well

2) Broad-based fundamental check will be good, just ensure the pairs belong to the same landscape.

1) Noted sir. I guess you are talking about the IV and theta related risks.

2) Sir do you mean only sector/sub-sector or like company size and earnings also?

1) Yup

2) No harm paying attention to both 🙂

Respected Sir! Many a times you mentioned that data should be clean ie., stock split, bonus, company actions, dividends etc should be accounted for. How do we do that? Is there any separate reading material for this?

Here is a video on the same topic we released recently – https://www.youtube.com/watch?v=MX-6rdHDPbE&list=PLX2SHiKfualEyD05J9JsklEq1JFGbG6qJ&index=10

Hi Karthil, I am struggling to do ADF test and get the p value on excel. Can you guide us on how to do the same on python. TIA

sir, given the complexity this model from chapter 7 to 14 ,this model needs a lot of research and time for developing his own algo . first model from chapter 1 to 7 is quite simple and straight forward . am i right ? because I am not from programming background . but I can learn this because I think this is not rocket science .

Yes, you can stick to the 1st technique and get comfortable with the idea. Once you do, then probably you can shift to the 2nd method.

Hi, I am programmer. I tried all of this logic with backtesting on existing data. I saw something interesting PnL goes negative even if the trade goes as per expectation. For example, if We are going long with zscore of -3.7 and closing on -1, the PnL for this trade becomes negative even though in the context of z-score this is a successful trade, which is strange. I wanted to ask if this is possible, or should I check for logic in my code.

It sounds non intuitive to me, maybe you should check the logic again, step by step 🙂

Hi Karthik,

I Hope you are doing good

Revisiting varsity after many days

Trading systems was the one which excited me, which I used to do manually on paper and pen

Right now I have done FRM

I would like to understand more on trading systems

Do this concepts still work and because of large firm automations and what’s your view are they’re any major changes in this systems after more than 1 year and is this part of your trading.

Thanks Chandra. Remember seeing your DP and queries from long ago 🙂

Congrats on FRM, I know its not easy to crack that. Institutions have an edge where latency is critical as they can afford to optimizes on all fronts – systems, software etc. But these are not latency critical strategies. Their success is dependent on how well you understand the concept and build your models.

Good luck.