8.1 The Strategy Pair Trading

8.1  The Strategy Pair Trading

Show Video

So for the next strategy we're going to look at it's called market neutral meaning reversion or bear trading. So bear trading is actually a very popular trading strategy in the professional trading environment. So most property trading firms hedge funds are going to be running some type of Fair Trading Strategies prey trading that has actually started in the 80s and it was started by Morgan Stanley or they were the ones who really made it public anyway way. But since the 80s you know a bunch of other firms are starting doing it and it makes a lot of sense. You'll see why in a bit here.

But it's something that's very popular in the field and ever since then you know I've worked at multiple prop shops and you know most of them that strategy is very similar to this. You know you'll find a lot of professional traders do this. Why. Because market neutral strategies and mean reverting strategies make a lot of sense for one mean reversion what does mean reversion mean. It means that things are coming back to their mean it's not momentum and you know what you'll realize if you trade for a long period of time is that most things don't have momentum. You know we all remember where we all see you know the phase books and the Amazons and you know the companies that really went in one direction that had strong momentum.

But we always forget all these other companies and coins or whatever that you know keep going up down up down and they're just reverting. The thing is most of the time things just reverse OK. Percent of the time the markets are in meaner version only about 20 percent of the time.

Are these momentum so mean reverting strategies tend to work often. Now market neutrality. What does that mean. Well market neutral means being invested in multiple assets in attempt to avoid or eliminate market risk which we've looked at. This is often achieved by being long and short assets simultaneously.

So a lot of firms what they're going to do is that they're going to have half of their money go in long positions. And the other half go in short positions. Why. Because they know that they cannot guess where the market is going to be going. Right all the time. So for example if you have some long positions and some short positions if the market is very you know is moving sideways you might make money on your lungs and your shorts if you don't if you bet on the right longs and older right shorts.

Now the problem occurs when there's a market crash. Well if you only have long positions all day long positions would lose. Now if you have long and short positions well you will lose on your long but you will make on your shorts. And that way you eliminate the risk of you losing all your money if there's a market crash. And it's the same thing if the market skyrockets.

If you only have short positions well you would just lose. But if you have shorts and lungs. Well you would lose on your shorts but you would make on your long eliminating again the market risk. And that is why firms implement market neutral strategies because they're in for it for the long run. And if you're trading for 20 years well guess what you're going to go true crashes and explosions. So what you want is to eliminate that market risk.

So if something like this happens you know you you eliminate that risk. This is why it's very popular. So then comes in the strategy that we call fair trading which is basically a market neutral mean reversion strategy.

How does that work. OK. Well the way it works is we come off of the concept you know our philosophy for running a story is like this is basically we can't predict when the market is going to do these major moves and that's same thing that almost everybody agrees on.

We can predict specific currencies or specific stocks or specific products. But the global economy itself the global market itself is hard to predict when there's going to be a huge pool. So when to eliminate that.

OK. And the other thing we believe in is that when things diverge to converge back. OK. So to do this we find two positions. We enter two positions one long and one short that have deviated from each other. And we expect them to revert back to their mean.

So for example we we take two currencies let's say I see X or let's say for example we need two currencies that make sense that are correlated that moves together. So for example we take out ISIS X and n it we take I see X and an okay. And why do we take ISIS and am well because maybe we know that they are very correlated and these two points are actually very correlated.

Why. Well because there are some fundamental reasons behind that. Maybe the team is creating this other project maybe there. This coin uses the technology from this coin. Something makes it that they're very correlated.

OK. Now I'm not going to get into the fundamentals of D2 but it could be anything it could be that one coin is actually generating the other coin it might be that one coin is the gas for the other coin. So it's used. So there's some fundamentals behind it why they're very correlated or sometimes there's no real fundamentals. But if you find correlation without fail fundamentals it's gonna be as good.

That's something that has a fundamental reason why they're correlated. So you think these two currencies and you look at their charts and you see that when one let's say I see X is going up you see that E.ON for some reason is also going up right. So that tells you they're correlated. Now what we're looking at we're looking at two currencies like this that are moving together and if they deviate from each other let's say at one point this one goes up but I see X instead of going up it actually goes down right.

And let's say we start looking at the historical difference between these two let's say their prices let's say when we started here this one was trading at five dollars and this one was trading at ten dollars and there was also always a five dollar difference between them but maybe at this point there was a 15 dollar difference between them you know maybe this one was at 10 bucks. And this one was at twenty five. So looking at it like this it we kind of predict that.

OK. These two currencies that are very correlated that move together have now deviated from each other. And if they deviated from each other what we believe is going to happen is that they're going to converge back. OK. So we expect them to converge back to one another.

So what do we do. We're gonna get into two different positions. Okay we're gonna get into a long position we're gonna buy this one which is ISIS we're going to long and we're going to go in this one and we're going to short this one right because we expect this one to go up and this one to go down for them to converge back. Right. And in this way we have a market neutral position because we're going to get into you know 50 let's say we have we're investing 10000 or we're trading 10000 and we want to buy 5000 dollars words worth of ISIS and we're going to short 5000 dollars. Words of AIM.

So our net exposure our net exposure to the markets is going to be zero dollars. We're not exposed. If the market goes up or goes down we don't care because half of our money is betting that the market goes down half of our money is betting that the market goes up. So you know we eliminate that market trust we can sleep well at night without the fear of market crashes.

OK. Now a few things might happen. Well one the market could you know let the market could not do anything right. The markets could stay flat.

Now if the market stays flat. What do you think is going to happen. Well maybe these things that converge and there is a high likelihood that the converge back maybe this one goes up a bit. This one goes down a bit and we find ourselves at the usual five dollar range between them. So the converse back so we make some money right and make some money on both of them but other things might happen. Maybe the market actually crashes freight.

Maybe the market crashes so if the market crashes we're going to. Everything is going down everything. So even ISIS is going to drop. So maybe we'll lose five bucks ISIS because it goes back to five dollars.

But you know what's going to happen is a on is probably going to drop so much more and since we're short we're gonna be making money on that so maybe it drops about I don't know maybe drops back to 15 bucks. So then it's it's a 10 and this one is a five. They come back to where they started out at. So in this situation if the market drops we lose maybe five bucks on one of them. And then we make 15. On the other.

Right. Because this one word long. So we wanted to drops we put a plus here this one we're long. So when one drops we lose money.

But this one will shorts when it drops will make money. So we lose some money on one of them but we make more money on the other. So in the end we make money right. We make a little bit of money not too much but we make money. Now what happens if the market doesn't drop and the market goes up. Well in that situation I hear well in that situation our short position everything is going up.

So our short position we're going to lose money on it because it is going to go up. But our long position since it's so undervalued compared to our long it's probably going to go up faster. So for us to find each other at like that five dollar range between them that's usual. So yeah if the market goes up we are going to lose some money on our short position but we're going to make way more money on our long position. Right. So in the end we are going to make money.

So you see that in this situation what we've done is we've made it that regardless of what the market does We still generate some profits. And this is why this strategy is very popular because you know all these firms they don't want to go bankrupt if there's a huge market crash or if there's a huge market explosion. So they don't want to be exposed to any market direction and that's why they are market neutral. And you'll see that if you research that market neutrality is very popular. Why.

Because it permits you to have stable returns. You know if if you look at your profit and lost you'd rather make a little bit of money all of the time. You don't even if it's less money then you're not making a lot of money at a loss. You know when the market goes up and then if the market drops losing a lot of money and have very volatile returns.

And then if there's a huge market crash you lose everything. And then we've seen how hard that is to come back from from huge losses. So this is why market neutrality is very popular. So how do we really trade this or how do we analyze this. We have a function. You know if you read on pair trading and there's actually a bunch of good traders on it the one that I like is E.P. Chang Ernie Chang.

He actually has a few books. They're more technical and some of them are our mission type of books. But he actually was working at Morgan Stanley in the 80s. So if there's somebody to tell you about you know fair trading I recommend this guy.

So to analyze pair trading there's a function we use OK and this function is going to be like this it's going to be Y equals. You just get this on here. It's okay it's all right Y equals. And then you have your first coin. So I'll call it coin a minus your second coin which is going to be times the ratio of these two points. Okay.

Now why is that. Because if I don't have a ratio and I just have coin a minus queen bee then in this situation what I'm going to have is basically here coin a let's say ISIS let's say on this coin a because I put it as the most expensive let's say this coin. This is going to be okay. So bond is at ten dollars so I'll go Y equals 10 minus five. And then the pair is at five.

Now the problem with this is if I if the prices go up if both coins go up 100 percent then I'll go on is gonna be twenty dollars. And ISIS is going to be ten dollars 20 dollars minus ten dollars. Give us ten. So then we might think that hey diverged but they didn't actually diverge because both of them went up a hundred percent. They're still the same. They went up similar prices.

So what I need to do is I need to add a ratio to take into account the difference of price and pricing that they have. So in this situation the ratio is the difference between. So this is a and b is going to be the difference between A versus B. So I'll have to do a divided by B. So my function is going to be a coin a minus Queen B times the ratio which is a divided by B okay.

That's the ratio. So in our situation what is the ratio. 10 divided by five. So ratio equals 10 divided by five which is going to equal two right so whenever I am calculating the the the pear function which we call it is the spreads which don't get this confused with the spread between one coin. We call this the spread between the pair.

So the two coins. It's sometimes confusing so if you are market making when you say the spreads just the difference between the bid and ask. But when you're fair trading when you're talking about the spreads you are talking about the difference between the two points. OK so in this situation what I'll be doing is I'll be doing OK while the pair is going to be equal to 10 minus five times two which gives me zero. Now as the prices go up by 100 percent it'll be. And let's say this one is worth twenty dollars minus this one is ten dollars now times two.

Well guess what. It still gives me zero percent because they didn't deviate. They both want 100 percent. If for any reason let's say this one only went up to I don't know eighteen dollars and the other one went up to ten dollars. So it's in minus 10 times two. This gives me minus two.

So now I know there is a deviation deviation is that. This one didn't go up as much. Right. This one should have went up more. And if this one was let's say something different let's say this one went up to twenty five dollars well if twenty five minus 10 times two.

That gives me five. Again there's a deviation. This one went up too much. And this one should be shorter than this one should be long. So by using this function what I'm saying is that look is the function gives me zero when they deviate from zero.

That means the either are too divided or too converged. Right. And I can get into a position because remember if they converse too much if they are way too close to each other then we expect them to re diverge. So in fair trading you can either buy this one and short this one to expect them to converge or do the opposite where you're longing this one and shorting this would expect them to re diverge. OK so this function here is going to be actually plotted we're not just going to just put it here. We're going to draw it at the at the bottom of the chart.

OK. So what we're gonna have is at the bottom of the chart we'll have this other chart here. And on this other chart what we're going to draw is the function. Right. The function will just stop Y equals a minus B times ratio okay. And here it's going to be at around zero.

So you'll see that when when the price is around zero from due ratio there's not gonna be much. But then here when they diverge it's going to go up so if here let's say they diverge 15 dollars from each other. Well actually not 15 because we're not just looking at dollars. But if this one is at fifteen dollars and this one is at ten dollars Y equals 15 minus 10 or let's say here is thirty five.

Okay let's change that. Thirty five and ten. So if we have thirty five minus ten times to that it gives me thirty five minus 20 which gives me fifteen. So here it's going to be at 15. That means there. They've way diverged too much and did average fifteen dollars from each other.

They should get back to zero. So here I would get into a short position of the pair. And when I say short position of the pair what that means is I'm shorting the first coin and longing.

The second OK. Expecting the prayer to re converge. Now let's see at one point the prayer drops to let's say right now the prices let's say prices keep going up and then at one point pair one which a John is at optimal 40 bucks see X is at I don't know. Thirty eight dollars. Well when I put this into the function I have Y equals forty minus. And I'm actually put certifiable puts thirty five year thirty five minus thirty five times two so minus seventy and this gives me minus 30.

So if the bear drops to minus 30 here I'll see this on the chart and I'll be like hey this is too low we're too converged I have too long the pair and when you long with the bear that means what's that means your longing. The first currency. Right.

So I'm gonna be buying a bond and shorting ISIS because I think you're and has to go up or ISIS has to go down or bought but they need to diverge from each other. So this is what you're gonna be looking at you're going to be looking at another charts. Okay. And this chart is going to be the graphical representation of the deviation between these two currencies and as these two currencies diverge too much from each other you're gonna be buying one and shorting the other if they converge too much to each other you're gonna be buying the other one and shorting the other one until the reeds diverge. Okay so I know a lot of material here but you know you can read a lot on pair trading. I've read you know books that are hundreds and thousands of pages long just on pair trading.

It's a very interesting subject there's a bunch of videos on it. I don't expect you to get it right away. You know I've done some market neutral trading for cryptos in our firm and you know traders why thought how to do this. Well it took you know a long time teaching them that it's not something that you catch right away.

You have to practice you have to test you have to read on it. You have to rethink about it. You know it's an online strategy.

It's not a simple strategy. People get trained to do strategies for weeks before attempting them. So you have to understand that I'm teaching at you now.

But it's not an easy strategy. OK. So don't get bummed out if you have a hard time understanding it re watched this video many times. You know Google ask questions do all of it's OK but that. Yes.

So I'll show you how we draw dysfunction in a second here. But this is going to be very useful. Now what type of coins are we looking at.

We're looking at highly correlated coins right. We want them to be highly correlated so for them to move with one with one another now we aren't just looking at correlation because some things are correlated. And let me actually close all of this up here.

Let's see if this relation. Yeah. Let's close all of this up some stocks or coins are highly correlated but they're not very good pairs because what correlation means is when something goes up the other one goes up and when something goes down the other thing goes down. Right.

So I can have here let me actually try this. OK. We have a and b OK correlation means that when a goes up when it goes up let's say here or it or I put B first so when B goes up a also goes up.

OK. And yet every time B goes up it goes up B goes up. It was a B goes up and when Beagle when B goes down it goes down and we have all of these variables maybe one day a went up 2 percent and B went up 3 percent. And maybe the other day V went down 2 percent and they went down 1 percent. So there's a correlation right.

And this is how you drop relations right. You plop all these points of how B moved and how a moved and you look at the relationship between them and then you can draw a slope which is you know the best fifth line we call and the best fit line is just going to be the line that is represented by the line that minimizes the distance between itself and all these points. Okay. And if you add all these error terms all of these distances together they'll give you about zero all the positives and the negatives. The difference between them this is how you find correlation no correlation is not a good is not what you want to use to find good pairs. Why.

Because some things that are very highly correlated and now we're getting into advanced optics by the way some things that are very highly correlated. The correlation does not have a very good distribution. So basically they might have some points like this and this is not a good correlation because yes the error terms here make it that this is the best fit line.

But if you can if you see here basically when let's say this one is a this one is B when a is going up let's say 1 percent 2 percent B is going up by way more let's say 3 percent 4 percent. And when a is going down OK well B is going down by way more right. So if the market is going in one direction let's say the market is just exploding up well a is always going to be going up less than B is going to be going up. And what that tells us is that if the market is going in a direction for for a long time well they're going to keep diverging because B's always going to be going up faster than e and we don't want that. We don't want that because there are going to diverge. And our objective is to not bet on what the market is doing right.

And if we don't want to bet on what the market is doing then we have no choice then then to not have something that has a bad correlation like this one. Okay. Because they'll just keep diverging or keep converging. So they are impacted by the market.

So what we want is we want pairs that are correlated but that their distribution for their correlation is better where the points here are well distributed. So yes sometimes a is gonna go up faster than B and sometimes B is going to go faster than 8 but we can't know if the market is going up or down. It's not going to give us a better indication of if they're going to keep diverging or not. So what we actually are looking for is four pairs that are not only correlated but are cool integrated. Now I'm not getting get in deep into the map of Quinta Grecian but you can read up on it.

There's a bunch of books on it. There's a bunch of articles on it to find a good point the reason you can do that the dick dick her fully test or the Johanson test. So these are the two tests go into variation. So you have this test that you can do that the curve fully to fuller tests and you have the at angle and grandeur to step approach where it's and the Giants and tests. OK.

So you have a bunch of different tests that you can do for integration. The reason why I'm not going to go into the math here because I've actually learned this while I was doing part of a Masters in Financial Engineering so it was an advanced mathematical course which was very very very deep. So the math behind it is actually if you do the math it's a bit complex but you can use Excel and other tools to give you the results of these tests or simpler. You can just visualize it on a chart which I'll show later. But what what it does basically is it looks at these error terms here and it does a.

It checks if there is any dependence between if a error term is going to be below or above the slope based on if the other error terms were below or above the slope. So it makes sure that these error terms are independent of one another and there's no relationship. And if they are then it's good because you know then when you're looking at a the peer chart like I've talked about before it will be you know moving like this where it deviates convergence deviates convergence.

But when you're looking at the the the peer chart the function that we've talked about of something like this will you'll see that sometimes it diverges too much. It keeps diverging and then it keeps converging. And we don't want that. We want something like this.

OK. Now the reason why I thought that with integration is that it's you're somebody who loves math and you want to go deeper you can go up you can go and do that. OK. Now how are we going to spot if something looks like this or not.

Well that's easy. We are going to draw it on a chart. And let me bring it up here. So the great thing about treating you OK and you might have seen here that sometimes I have these coins that are two coins is the trade that we've just talked about. We can drive here.

So we said do we have a on let's put a on you as deep. This is the price of an USD Well I don't want to look at it on Tuesday. I want to look at the relationship between a non USD and ISIS USD.

So what I want to do is I want to see what is the ratio between them. So this is the price of a gun. Let me open. Let me open actually three charts like this.

OK. A on USD. I'll have it here. I see X USD. I'll have it here and then I'll open a calculator and we'll see what is the difference between their prices. So a whereas and this is a.

Yeah I see it's perfect. So Ian first is trading at zero point 0 9 0 6 6 6 7 cents and then I see X is trading at zero point twenty three 6 7 4 0 9. So the ratio here is point 3 8.

You'll need to keep all 0 points read. So what I want to do is I want to try to draw a chart between this coin and this one and I can draw this here. I'll remove this. I can draw it all on one chart. I can go here and say hey I want to draw on you as D minus.

I see X USD then times the ratio which is three point thirty eight. And this here is going to draw. Here we go. This here is going to draw for me the chart that I just looked at that I just drew on top of a below the other charts.

It's going to draw for me the relationship between a on an icy X okay. And I see here this is a relationship I can put on one hour charts and this is the relationship between both. This is a on by itself.

This is I see X by itself. And this is both of them I can see here when a went up ISIS X went up because they're correlated but here I see that it's very stationary right and stationary means that's when one goes up they come back down. So the relationship between them keeps changing and on a stationary product like this right. You can see it. It keeps the keep moving up coming back down. If I add an indicator like Bollinger Bands look at this.

Look at this every time it goes below the mean comes back down goes back up comes back down hour goes back up goes down comes back up goes down comes back up. What I'm looking at here this chart is basically this year. This at the bottom I'm looking at the function right.

I'm looking here at Y equals a minus B times art right. I'm looking at the bear function. The outputs of this is drawn here and by looking at this I can move the diverged a lot or if the conversion allots. OK. And in this situation I can look at it right now and be like OK well right now right this moment there you know it's I need there a little bit diverge not too much I need to buy a long and short I say I would wait a bit more but I know that a on my nice I'm six times ratio is now giving me something lower than the mean. So they're a bit diverged.

OK. Or actually a on is the first one so we have a um. Yeah. So basically what you want to make sure is when it's at it's dropping here and we can look at any of these.

I can actually. Well actually we'll look that will look we'll go to some examples in the next lecture but yeah you have both of your charts. You know that they're correlated and then you draw another chart that shows you the relationship between them. See because you have here I can draw both charts here as well actually. So let's actually put them in one I have a on here.

Let's put a line chart. This is iron I'm going to compare it to I see x. Okay. Use the and here's ISIS.

Okay. So you see here that I have bought a on an ISIS X in one charts I can't say let's actually let's put this here. Right. I can draw a line on ISIS.

Someone charts you see that these are correlated right. You can see that. When when they deviate from each other they would converge back. So what you're doing is you can short this one here or you can short this one by this one. And then when they get back together you short this one and by this one. And when they re diverge you short this one and by this one and they're going to keep reading surging and re conversion rates here.

You can chalk this one by this one when they come back together do the inverse. So you have two coins that are very correlated and you know you you can really see it here. Right. And I can put any type of chart hourly I can put here you can put any type of chart and you're going to be seeing that they're very correlated and co integrated so that the reason why we draw this other chart that I just looked that's is really because it helps us into knowing how diverged how much diverged they are or how much converged they are.

OK. So I think I've said a lot for this lecture so let's leave it at that for this lecture and we're going to build on top of this and the next lecture. I hope it's not too much re listen to this video. You know ask questions.

Look on Google. Join our chatroom ask questions in there. Bounce ideas off other traders. It's a very you know it takes time for this to make sense to you and it takes some practice. But you know it's worth it.

So give it a shot. And that being said let's build on all of this. And the next lecture.

2021-05-17 05:42

Show Video

Other news