- 14 hours ago
Category
π
LearningTranscript
00:00Hello everyone. I'm sure you'll agree with me. The success of a trader or an investor is primarily
00:05determined by his or her ability to find an edge or a gap in the market. Over the years,
00:10people have built or are in the process of building tools that can help them find these
00:14hidden gems. In this video, I'll be talking about one such powerful tool and the tool that every
00:18trader or investor should have in his toolkit. And the tool in question is the relative rotation
00:23or sometimes as it's commonly called as sector rotation graph. We'll be taking a closer look
00:27at number one, what this tool is all about and how it works. Number two, review the Python code
00:32that I had built that will construct this tool for you. And number three, we will also discuss
00:36how we can use this tool for better decision making. So let's get started.
00:42If this is your first time here, welcome. My name is Vivek and I'm a financially independent
00:45algo trader. This channel is all about building a community of algo traders. We discuss everything
00:49about algo trading using Python, building and backdesting trading strategies, market updates,
00:52much more. Please do visit our community website fabtrader.in. Also do check out my other YouTube
00:56channel Fab Wealth, where I talk about my own financial independence journey and share tools,
01:00methods, and strategies that help me achieve my financial freedom. Thank you.
01:08This video is part of my algo tools series, where we will be building a range of Python-based
01:12trading tools. Now, you might be wondering what's the purpose of these individual tools,
01:16right? So think of a skilled mechanic. His efficiency depends on the tools at his disposal.
01:21The same goes for an algo trader as well. While these tools may seem small and standalone right now,
01:26I ask you to trust the process. As we progress, you will see or you'll start seeing the bigger
01:31picture. Soon, it'll be crystal clear how combining these tools can completely transform
01:35your trading game. So stick around. It's going to be worth it. If you're already familiar with
01:40relative rotation graphs, feel free to skip this section. For those who aren't, I'll do my best
01:45to break it down with a simple or maybe slightly unconventional example. It might not be perfect,
01:49but I promise it's the easiest way I could think of explaining this concept. So please bear with me.
01:57You've probably heard of horse racing, right? Now imagine you're invited to one and someone
02:01presents you with a challenge. There are four horses running in the race. And if you can't pick the
02:06winner, you'll walk away with a million dollars. Take a few seconds and think what are the two top
02:11key factors you would consider before placing your bet. So you're ready with your options. Let's see if
02:18we are on the same page. As far as I'm concerned, the first factor is, is the horse strong enough?
02:24Does it have the stamina to last the entire race? Strength is key. And number two, the second factor,
02:30strength is great, but can the horse run fast? At the end of the day, speed is what wins races.
02:34Correct? Now let's break this down logically and plot it on a chart. The horizontal line represents
02:42the strength of the horse. So the positive side is where the horse is stronger and this is where it
02:47is weak. And similarly, the vertical line represents it. How fast is it? This is the fastness and this
02:51is the slowness. So automatically, you get the picture where I'm trying to go to. For example, these
02:57four horses, the horse A is both strong as well as fast. Horse D is stronger, but it's slower.
03:04Horse C is both weak as well as slow. And horse B is faster, but it's not a great shape
03:11right now.
03:13So suddenly, when you look at things this way, it becomes very clear or resented. Horse A, no doubt,
03:18is the horse that you want to bet on. And the relative rotation graph is very similar to the
03:22same concept. Let's now look into the actual RRG itself. If you haven't joined our Telegram group,
03:28please do so. I share market insights, algo trading tips and new video notifications. And this way,
03:32you can stay up to date with our community news and events. The RRG is very simple. At the same
03:38time,
03:38it's very beautiful and powerful as well. It basically has two indicators. The one is called
03:43the JDK-RS ratio, which is nothing but your relative strength ratio. And JDK is nothing but the
03:47person who invented it. I think it was Julius De Kempener. So it's named after him. And then the
03:52second indicator is the JDK-RS momentum. And when you combine these two indicators, whereas the relative
03:57strength measures the security strength against the benchmark performance, whereas the momentum
04:02indicates the rate of change in its relative strength. So when you combine these two indicators
04:06together, and that's what actually makes the RRG. Now let's discuss these two indicators in a bit
04:13more depth. The first one, which is the relative strength. Relative strength, as you know, is nothing
04:17but the security that you're trying to analyze. You compare it with the benchmark. All you're trying to do
04:22is you have the securities returns divided by the benchmark return. So whenever you have a value
04:27more than one, it automatically means that your security is doing much better than the benchmark.
04:32Anything less than one, your particular security is not able to beat the benchmark. Typically,
04:37they multiply the final value by 100. So always the RRG ratio is mentioned in terms of 100. So 100
04:43being
04:43that your security is exactly the same as the benchmark. Anything more than 100 is basically your
04:48security is beating benchmark. Anything less means that it's trailing your benchmark. That's what the
04:52relative strength basically indicates. So the relative strength alone is only a part of the
04:58puzzle. It doesn't give you the complete picture. You need one more ingredient to make it whole,
05:02which is where the momentum comes in. From relative strength, you first establish that your security
05:07is doing much better than the benchmark, which is number one. It's very important. And number two,
05:11you're trying to establish that it also has momentum and that is indicated by the RS momentum.
05:16Right now, you don't have to worry about the formula for calculating these
05:19indicators. It's all provided in the blog as well as the Python code. So right now, you don't have
05:24to worry about it. Now, if we take these two indicators and then do a similar plot, a scatter plot
05:29of the same values, for example, in this case, the X axis is going to be your relative strength and
05:32the Y
05:33axis is going to be momentum. This particular quadrant, which is the first quadrant, the strength
05:37is still weaker, but you're seeing a good momentum. And then the stock is about basically, you know,
05:42pick up speed. And this is where it's called the emerging leader. And typically, this is where you
05:47look for buys as well, because you want to get into the trend early on so that you can catch
05:51that alpha.
05:51So this is where you look for buys.
05:55This second segment or quadrant is where the momentum is high and also the strength has picked up. So
06:01your stock is automatically in the high performing stock. So at this point in time,
06:04you don't look to sell it. You're basically holding your position.
06:08And then in this quadrant, you're clearly seeing weaknesses. The momentum has kind of dropped.
06:13It still holds some strength in it, but the momentum is completely lost.
06:17This is where it's called the mature trend. And you typically look for ways to get out of your
06:21holdings at this point in time. And finally, the last quadrant where it has clearly lost momentum,
06:26also the strength, and it is an underperformer at this point in time in the market. And this is
06:30definitely the stocks or the sectors that you try and avoid. You never buy at this stage.
06:38So I guess the concept is overall clear. Now, let's take an actual example of how an ARG looks.
06:44This is how a typical ARG looks. The same four quadrants. We have the improving quadrant,
06:47at which point in time you look for buys. And then the leading quadrant, where you look to hold.
06:51And then the weakening quadrant, as soon as it enters here, you look to sell and get out.
06:55And then the lagging quadrant, you try to avoid like hell. So ideally, what we're looking at is
06:59basically a stock, which is increasing in momentum, gaining strength, and then all the way going up
07:04to this range. And this is exactly the range that you're trying to make use of. And then this is
07:10the
07:10range that you try and avoid. The items on an ARG is typically shown as with a head and a
07:15tail.
07:16I know it kind of looks like sperms under a microscope. But the reason why it's given is if you
07:21just give
07:21the head portions alone, you can clearly see which quadrant they are in. But when you clearly see the tail,
07:26you can see the trend that that particular stock is taking, which tells a lot more story than just
07:31looking at which quadrant it belongs to, right? So you can actually increase the tail, you know,
07:35the duration of the tail. And then you can also clearly see the pattern. And I think one thing that
07:39we clearly mentioned from this picture is that you see a natural way the stocks are going cyclical, right?
07:45Typically, what we think is that when we look at the price of a stock, it's all just random. There's
07:49no real sense to it.
07:51You know, that's how we feel it. But if you really look at this charge, the complete picture basically
07:55jumps at you, which is that most of the stock actually have a cyclical nature of how it operates.
08:00And when you know the secret and when you know where they are right now within the, you know,
08:04the overall four quadrants, you can either pick or avoid and make better decisions.
08:11Let me just quickly jump into its Python implementation. This code is available in the blog post. I'll provide
08:16the link in the description as well as I'll pin this on the comment section so you can download it
08:20and try it for yourself. This actually currently uses both Python and Streamlit. And then I'll show
08:25you how to execute this. For people who are not familiar with Streamlit, you basically give Streamlit
08:30run and then you provide the name of the Python file to run. So this is how the web app
08:37would open.
08:39You could provide the benchmark here. In this case, I've given Nifty 50. It can be any indices that you
08:43want.
08:44And then you give the list of tickers that you want to compare it against. The period at this point
08:48at the time, I've given 180 days. Again, you can increase or decrease this however you want.
08:52And the tail length, I've given five days. Again, you can increase it, you know, the way you want it.
08:56So you can clearly see that I've given most of the, you know, the most popular sectors here.
09:00And the graph would clearly tell you where each of those sectors are. And depending upon this,
09:05you can make better decision as to, you know, whether to exit those sectors or hold on to them or,
09:09you know, look for buying opportunities. So that's how this map, this graph is very, very useful.
09:15And you can also go ahead and change it to anything that you basically want to check,
09:19TCS and INFI. And then it will show up. This is TCS and this is INFI. TCS looks like it
09:25says
09:25an improving quadrant. INFI, for obvious reasons, this quarter is currently in the lagging still,
09:29right? So that's how simple it is. And then if you want to see, you know, the path that it's
09:33currently taking, TCS clearly, you can see that it's improving, whereas INFI is still stuck at the bottom.
09:38So that's how simple the implementation is. So like I had mentioned, all the information
09:43that I just told you, or in fact, more information that what I just spoke is already available in
09:47this blog article and I'll give link to it. And it also contains the entire implementation,
09:50the Python implementation, the code is available. All you can do is just simply copy.
09:54The only change that you might have to do is supply your own function that gives the historic data.
09:58Right now I'm using Xeroda. You may want to change it to include your own function to get historic data.
10:02RestAll would work as this. And then in terms of how to run this, since it's a Streamlit app,
10:07like I said, just type Streamlit space around space and then provide the name of the Python file.
10:12And that should open up your app in a web browser like this. And the blog also gives you some
10:18practical
10:18applications of how you could effectively use RRG. So please do read through this. So that's pretty much
10:24it for this video. Please try this out and let me know how it went. Thank you. Thank you. If
10:30you
10:30genuinely found this video useful, please consider subscribing and liking the video.
10:33And I will see you soon in another video. And until then, take care and happy trading.