- 1 day ago
Category
📚
LearningTranscript
00:00Hello, everyone. Over the last few weeks, my inbox was flooded with messages from our Fab
00:05Trader community members. Many of you saw my previous video on the Nifty Shop strategy,
00:09where I shared my live trades and returns. And the feedback has been incredible, right? So a lot
00:15of you were excited, some of you were curious, and quite a few asked me the same question,
00:19can this be back-tested? So in today's video, we're going to do exactly that. We're going to
00:25take the Nifty Shop strategy, put it through five years of data, test multiple variations of the
00:29rules, multiple combinations of the input consideration, measure its performance,
00:33not just on the returns, but also on the risk and consistency. And finally, I'll share with you
00:37the top ranked combinations that yielded the best returns over the past five years. So stick around
00:42till the end, because I'm going to reveal the winner, the best combination that produced the best
00:46results and the returns for Nifty Shop strategy. Now, for those of you who might be new here and
00:52didn't watch the first video, please watch that video first to get a full understanding of what
00:55the strategy is all about. I've shared the link to this video in the description. However, let me give
00:59you a quick refresher on what this Nifty Shop strategy is all about. This strategy is built
01:03on the premise that the Nifty 50 stocks, the largest and the most stable companies in India,
01:07rarely stay down for too long. So we look for temporary pullbacks in these fundamentally strong
01:12stocks, enter when they are significantly below their 20-day moving average, and then patiently wait
01:16for them to revert back up to a set target before selling. There's no stop loss in this strategy.
01:22We average down when the price drops further and sell when our average cost hits the target. So it's
01:27simple, mechanical, and ideal for, you know, kind of beginners or busy professionals who want steady
01:32compounding without the stress of, you know, watching the charts all day. Again, I strongly
01:36urge that you watch the other video first before you proceed with this one. Now let's talk about
01:40the entry rules. You only need about 10 minutes a day at around 3.20 PM. As you know, 3.30 is when
01:45the market closes. So it's 10 minutes before the market close. Step one, you just scan for, you know,
01:50the Nifty 50 universe of stocks and find five stocks that are trading the farthest below their 20-day
01:55moving average. That's step number one. Step number two is from those five, pick one stock that you
02:02already don't have, right, that you already don't hold and then buy it. If all the five stocks, you
02:07know, that was chosen for that particular day are already part of your portfolio, then you look for
02:12averaging down opportunity. In this strategy, you average down only when a stock from your holding has
02:17fallen more than 3% from your last buy price. And once you do that, you buy only one stock per day
02:22that has fallen the most. And now for the exit rules, at the end of the day, before you actually
02:26begin the buy leg of the strategy, you do the following steps to sell the stocks that are
02:30eligible, right? So at 3.20 PM every day, you check your portfolio and see if any stock that is trading
02:36more than 5% above your average buy price, right? The 5% is the target and that we've kept for this
02:42particular strategy. And if you do have any stock which satisfies that condition, you just sell
02:47one stock per day. So this is the original strategy. However, based on our backtest results,
02:53we're going to change a few things to take it from good to awesome levels, right? So stay with me on
02:58that. This is an interesting part. We've come to the position sizing approach here. The original
03:03strategy, if you remember, recommended a few approaches to position sizing. However, I took a
03:07fresh look at it and I've considered the following three approaches for my backtest date. Number one is
03:11these static position sizing. So in this, we assume a set amount for each trade and that amount won't change.
03:17For example, 10,000 rupees for each trade when you buy a stock for the first time and then the same
03:2110,000 rupees when you are averaging down, right? Here, I've also considered two other variations
03:26within it, which is one is pyramiding, where if you allocate 10,000 when you buy a stock for the first
03:30time, then you allocate a smaller amount, say 5,000 for averaging. The reverse pyramid is also possible
03:36where you use 10,000 for the first buy and then you allocate 15,000 for averaging, right? The advantage
03:41with this one is that since you're basically averaging with a higher amount, the position can come up to
03:46target much faster. So for the backtesting, we will use all these variations and then you'll see all
03:50that detail shortly. The second approach is the dynamic approach, where we go for a percentage of
03:55the free cash that is available. For example, let's say you start with 4 lakhs and you already have
04:00used 3 lakhs and have only 1 lakh left within your portfolio, right? Then your position size would be
04:04like 5% of that 1 lakh, which is 5,000 per trade, right? Here as well, we will change the percentage
04:10point, increase it, decrease it, you know, and then test various different combinations
04:14within our backtesting. The third approach is the divisor approach, wherein you divide the total
04:19portfolio value by a number called the divisor. For example, let's say 40 is your divisor and your
04:24portfolio value is say 4 lakhs. So 4 lakhs divided by 40 and that'll be 10,000 per trade will be your
04:29position size. Here as well, we can change the divisor number up and down to see which divisor value
04:34gives us the best results. So given all this background, we have multiple inputs into the
04:39strategy that needs to change and we need to test all possible combinations to see which one basically
04:44comes up at the top. So to recap, what are the variables within the strategy? There are four main
04:49variables or four levers that we are going to be leveraging. Number one, the position size of the
04:55first buy. The second is the position size of the averaging, right? The thirdly, the target percentage,
05:01while the original strategy told us to keep a 5% target, we are going to change this number as well.
05:06And lastly, the fall percentage of averaging down. The original strategy told us that we only consider
05:11for averaging down if the stock in our holding has already fallen down by 3%. So what if we vary this
05:17number 3% to say 4, 5, 6% and how would that impact the overall performance of the strategy? And that's
05:23what we're going to be also doing as part of our backtresting. So as you can see, there are many
05:28permutations and combinations that would basically run into thousands of scenarios and it is humanly
05:33not possible to test every one of those. However, I've considered around 40 such scenarios for my
05:38testing and I've backtested each one of those. This is all okay, but we have a new challenge,
05:43right? We are testing so many variations. How do we decide which one is better? And that's where I use
05:48my simple framework that I learned from a friend of mine who runs a PMS, right? While there are hundreds of
05:53strategy performance metrics, it is impossible to compare all those numbers, right? So I personally
05:58broadly look at three aspects. Number one is the returns, risk, and probability. Where all these
06:03three kind of come together, that's the sweet spot in the middle that we are basically going to look
06:07for and measure, right? So for returns, we will be considering the CAGR and for risk, we will basically
06:13be looking at max drawdown, sharp ratio, and calmer. And lastly, the probability and consistency.
06:18This includes the win ratio and the number of trades, right? Because a strategy that makes money on 80%
06:22of the trades gives you a far more psychological comfort than the one that's just a coin toss.
06:27More on this when we look at the backtest results. So this is the Python implementation
06:31of the backtesting module. And this is a script that I basically used to do all the backtesting.
06:36If you want to access this code, the code is available within our community store,
06:39and I'll provide the link in the description. So you could take a look. So the implementation
06:43itself is pretty straightforward. We have all the 5050 instruments, you know, as on date today.
06:48And then we are considering five years for our testing period, starting from 2020,
06:51the July, and then until the end of June this year, right? So a total of about five years.
06:56And then if you really look at the inputs that we are providing, like I said, the position sizing
06:59approach, we are going to have three different approaches, the static, dynamic, and the divisor.
07:03So depending upon what you provide here, the backtester would basically run the backtest
07:07on that particular position sizing approach.
07:10For the static mode, we are going to be providing the fresh static amount, which is when you buy the
07:14stock for the first time, which is a fresh buy, right? And this is the amount,
07:17that static amount it's going to use. And then when you're averaging down,
07:20you could change the amount, right? It can either be same or different, right? It is all parameterized
07:24here. And when you're using dynamic mode, which is basically a percentage of the free cash available,
07:29you can again, basically for a fresh purchase, you can say what percentage, in this case, it's going
07:32to be 4%. It's just a sample, you can change it to anything you want. And then similarly, for averaging,
07:36what is the cash percentage that you want to use? And these two basically apply for the dynamic mode.
07:41And finally, for the divisor mode, again, the same concept, which is when you're buying it for the first time,
07:45what is the divisor that you want to use, right? Which is, it'll basically consider the total value
07:49of your portfolio at that point in time and divide by 50. And then that amount is going to be your
07:53acquisition size, right? That's what the divisor basically means here. We're taking the initial
07:57capital as 4 lakhs here. The target percentage again is parameterized. We're going to be changing
08:01this number and then testing that combination. And similarly, the averaging down trigger percent,
08:06right? Like the default is 3%, but we are again going to change this and see how that affects our
08:10performance. In case you're running the script, the only thing, only change that you have to make
08:15on your site is this particular function at the top, which is the get historical data. I am currently
08:20using zero to get historical data, but depending upon your broker, you will have to change this
08:24particular function to include your code here so that you get the historic data for all the nifty 50
08:29stocks. So that's the only change that you will have to do from your perspective, if you're looking
08:32to run the script on your own. All right, I'm sure you're saying enough of the suspense, you know,
08:36tell us the performance, right? I mean, what the results of the back testing is, right?
08:40So this is the final, you know, the consolidated back test results. So in total, I've considered
08:46close to about 34 specific scenarios. And then of which the first, the lighter gray that you see
08:52here, right? The first part, those are all the scenarios that are related to the static position
08:58sizing approach. And then the slightly darker next set of, you know, scenarios are related to the dynamic
09:03position sizing approach. And then finally, we have the divisor approach, right? So in total,
09:07there are 34 scenarios that I've kind of tested. To give you an example of what are the things that
09:13I've considered, for example, let's look at this first one, right? This is a static approach where
09:16we have a set amount for the first buy, right? This is the position size for the first buy,
09:20which is 10,000. And then per averaging, you're considering 5,000, which is half of this, right?
09:24This is a pyramid that I talked about. The percentage for averaging, right? This is the, you know,
09:28the 3% if it has fallen below the last buy price, right? That is what this AVG, 3% is,
09:34and the target is 5%. So we basically looked at those four important, you know, triggers. And then
09:40this is the values that we've considered. And that basically becomes one test case here, right?
09:44And when we do it, when we run the script, we basically get, you know, we capture these matrices
09:49at the top, right? It's the same way I had explained. For returns, we are calculating GAGR.
09:54For risk, we are considering the max drawdown, sharp ratio, and also the calmer ratio, right? And for
10:00probability, we're considering win rate, as well as the number of trades. So what the sheet does is
10:05basically it applies a weightage for each of those factors. And then it individually assigns a rank
10:11for each of those factors here. All six factors are basically having a rank here from, you know,
10:15starting from one. And then it finally comes up with the weighted score, depending on the weights
10:19that we have assigned, right? So this is the final weighted score. And then based on the final weighted
10:23score, we basically apply the final performance ranking, right? In the last, right? A standard template that I
10:28usually use to, you know, to rank any strategies. If I want to compare multiple strategies together,
10:33or I want to compare multiple iterations of a single strategy, this is the approach and a framework that
10:36I currently use. So let's take a look at one example from the dynamic as well. So here, what is
10:40happening is we are considering 5% of the free cash flow available as the, you know, the amount for
10:45buying the first time. And then for averaging, we're considering 5%, right? For averaging down,
10:49we basically want 2%, you know, the stock should have fallen 2% below the last buy price. And this is what the
10:54averaging down percentages, and the target is 5%, right? So that's an example of a dynamic. So here
10:59you can see all the various combinations that we have used, right? In this case, for example,
11:04we are using the same 5 and a 5. Averaging down also is 2%, but target we are considering 6%.
11:08Here it is exactly the same, but the target we are considering 8 and 10% here, right? And here,
11:12if you see, we are slightly changing the numbers, right? For the first buy, we are considering 6%,
11:16for the averaging, we are considering 5%. For averaging down, we are considering 5% here, and the target
11:21also 5%. So these are the various combinations that I basically felt was the right mix of combinations
11:25that we need to be testing. And coming to divisor, the last, here, just to give you an example,
11:30we're using a 10 divisor, which means that, you know, it takes the entire size of the portfolio.
11:34At the start, maybe if you add 4 lakhs, you will divide 4 lakhs by 10. So 40,000 will become your
11:38position size for a single trade, right? Similarly, the, you know, when you're trying to go for
11:42averaging down, it will be the same. It'll apply the 10 again, right? And the 10 divisor. The averaging down
11:47percentage here is going to be 3% and target is 5%, right? Similarly, you will see here,
11:50I've constantly changed the numbers. I've tried with 10 divisor, 20, 30, 40. I've gone up to 50
11:55devices, right? And then I've interchangeably, you know, kind of changed the target percentages
11:58also here from 5% to 8%. Now I've tried various, of course, I did not tabulate everything here.
12:03I did a lot of other tests as well, close to about 100 plus tests that I did. But I found the ones that
12:07are basically very close to what we're looking for here and tabulated them as a sample here. So there are
12:12totally 34 such test cases here. In addition to the six factors that I talked about, I've also
12:16captured a few other things that maybe you might be interested in. One is your average holding period,
12:20because this is one of the questions I get asked a lot of times, like as to how many days a position
12:23is open before a target is met, right? So that number in days, in terms of days, right? I've also
12:28maintained here. And then one to basically check if it beats Nifty, right? This particular test case
12:33or the scenario, does it beat Nifty or not, right? What I found is on an average for five years,
12:38Nifty has given about 12.3% Gagger. And if the strategy basically gets more than that,
12:43it means that it beats Nifty, otherwise it is not, right? And then finally, after brokerage,
12:48I've also captured the net P&L percentage that each of these scenarios basically produced.
12:53And now the moment you've all been waiting for, which is, you know, which is the combination that
12:57basically gave us the best results, right? So in terms of ranking, which is the rank number one,
13:02and that is this one, right? The divisor, which is the scenario number 30, where we are going for
13:0630 divisor for both your first buy as well as for averaging. And then your average percentage,
13:11averaging down percentage remains at 3%, what the original strategy talked about.
13:15In terms of the target, rather than going for the standard 5% that the original strategy talked
13:18about, the 8% basically produced the maximum results. So in terms of the overall net P&L percentage,
13:23this is the second best, which is basically about 250% in the last five years, right? And then the
13:30average holding period was about 92 days, which basically means about three to four months.
13:33Sometimes it takes as long as three to four months for a position to close. The max drawdown is zero,
13:38understandably, because we are not closing any positions in a loss. The win rate is basically 90%
13:44of the times, and it's basically a win, which is also kind of expected. The Sharpe ratio is 5.7,
13:49and the total amount of trades in five years is 692, which is actually a sweet spot because for some of
13:54those scenarios, we've gone up to almost 1200, twice the size is this, because the more number of trades you go,
13:59you, the more brokerage you're going to also pay, right? But the 692 is at a sweet spot, right?
14:02So based on all that, the ranking, you know, came up as number one. So to sum up again,
14:07the one that basically came up with the rank one is the divisor approach, where we're using 30 and 30
14:12for averaging and the fresh buy. And for averaging down, we're using 3% and target is 8%.
14:17Let's take a quick look at the performance on the dashboard itself. As I was explaining,
14:21there's a scenario number 30, which came up with the rank number one. We have 692 trades,
14:25and then the winning trades out of which is 624. You might ask like, you know, we're not closing
14:28anything at loss. So why are we still having a lesser win rate here? It should have been 100%.
14:33The answer to that is basically because we are doing averaging, the trades that we took earlier
14:38on, right, might still be at a loss. Because of the averaging down, the buy price basically comes down.
14:42And then when we close the position, we would still at an overall, you know, the stock level will
14:47still be at a profit, but individually at the trade level, some of those might be negative.
14:50They make up those 10%. The actual investment is a good number to see. It's basically the
14:55actual out-of-pocket money that you have spent from your pocket. So sometimes, you know, the money
15:00gets reinvested also. So we're not taking that into account. The actual money that went out of my
15:04pocket as investment is what is reflected here. The overall cross PNL of about 10.3 lakhs here,
15:10and then cross PNL of about 260%. After all, brokerage is 249%, which is a good number. And then the
15:16holding period is 92 days, as we already saw. Slightly longer, but kind of expected, you know,
15:20given that, you know, the turnaround takes a bit of time. The CAGR is really, really good. About 19%
15:24for almost like no risk here, right? So that's what makes this strategy so beautiful. If you take
15:29a look at the equity curve, the one in white is nifty. The same amount at the same time was
15:33invested in nifty 50. And this is what you would have gotten. But the brown part is the actual
15:37strategy equity curve, which is really, you know, you can see the uptrend here. It's quite smooth.
15:42And then almost twice as what nifty 50 would have produced, which is really, really good. The drawdown is
15:46very, very minimal, as I was talking about. It's primarily due to the averaging down,
15:49but nothing major, less than 0.02% there, almost zero. The monthly heat map here, looking very
15:53healthy. And you can take a look at it for each month across all those five years, the numbers are
15:58there along with the end of your numbers reflected here. Underwater plot, nothing to report here,
16:02because the strategy does not lose money, right? The nifty has a slight underwater here, which
16:07basically means nifty lost a bit of your investment, but not really the strategy, right? Which is,
16:11which is again, really a good positive. So in terms of the strategy versus benchmark,
16:15hands down, the strategy beats the benchmark, which is nifty 50. You can clearly see 24% nifty,
16:20almost 50% by the strategy, 4.9 here, 17% here, 19.5, 29.6, 8.8, and 22.1. This is kind of expected,
16:28because we're not considering all the trades that are still open, right? And only when they are closed,
16:31their actual PNL gets calculated. So that's why, you know, the numbers you will see slightly different.
16:36So that is kind of expected. So I would usually ignore this, and I'll probably pay more attention to
16:40these four years where it's been. The numbers have been excellent. So one of the other questions that
16:45I was asked a lot of times is like, you know, how much money do I really need initially, you know,
16:50for the things like, for example, if 4 lakhs is the total investment required, you know, the question
16:54that I was asked is, do I need to put all 4 lakhs in the DMAT account? And how long is going to sit
16:57that, you know, that money is going to sit within the DMAT account, not doing anything? Like, what does the
17:01utilization look like and all that? So this extra infographic that I added, basically, to answer those
17:06questions, which is, if you really see the first trade that we took was in July 2020, right? And
17:12that is this point, right? And then the white band talks about the money from out of our hand,
17:16how much we've invested, right? And then the brown part is, of course, how the equity overall
17:20portfolio grew, right? So you can clearly see, from starting zero, our investment, the entire 4 lakhs
17:24went in by the time it was September. So it took about two months for that entire 4 lakhs to be invested
17:29fully. And beyond that point, that 4 lakhs, we've stayed, basically, that money has stayed invested
17:34the entire period, right? That's basically gives you a clear understanding of how long it basically
17:38takes for us to basically ramp up to that funding level, right? And the other question that is asked
17:43is, like, do we have to keep all 4 lakhs in the account and the starting itself? The answer is no,
17:47it could be basically placed in either a liquid fund or a liquid piece or an arbitrage fund, and the money
17:52can be slowly drift-fed into the strategy, right? Because the strategy itself takes only one trade per day.
17:57So all it basically needs are that 10,000 or 15,000 or 20,000, whatever the position sizes,
18:00that's the amount of money that it needs. So every day that that money could be drift-fed from
18:04the liquid assets, right? So that way, the money doesn't stay within the demand account not doing
18:08anything, it stays productive. So hopefully, that's very useful to know that in this case,
18:12you know, it has taken about two months for that entire money to be fully invested.
18:15By the way, if you're wondering how you can run similar backtests on your own strategies,
18:19even if you have zero coding experience, I've built a complete course that teaches you exactly how
18:23to do it using Python and AI. It's completely beginner-friendly and will help you not just to test,
18:27but also optimize and visualize your strategies, just like the way I've done it here, right?
18:31So please do check out this course when you can. And as I had already mentioned,
18:35if you want to dig deeper into the Nifty Shop backtesting results that I've just posted here,
18:39if you really want to, you know, kind of access it and then do a bit more testing on your side,
18:43I put the backtesting, you know, the Python script, the daily screener for the Nifty Shop,
18:46all the trade books from my testing, you know, and then the full ranking sheet that you just saw,
18:51all of it is basically available on our FabTrader community store and the link is in the description.
18:56I sincerely hope this deep dive gave you not just the results, but also the process that you can
18:59replicate on any strategy that you're interested in. So thanks again for watching. As always,
19:03TradeSmart, Compound Stately, and I'll see you in the next one. If you genuinely found this video
19:08useful, please consider subscribing and liking the video, and I will see you soon in another video,
19:11and until then, take care and happy trading.
Comments