Skip to playerSkip to main content
  • 2 days ago
Transcript
00:00Hello everyone. I'm back with the content that is most popular in this community, which
00:03is backtesting trading strategies. I know you all love to learn new trading strategies
00:07and even better if it includes backtested results, right? So today we are going to be
00:11looking at a rather unconventional swing trading strategy called the Phoenix Bird. This strategy
00:15was sent to me by one of our community members, Raghu. He had wanted me to help him backtest
00:20this. So in this video, I'll take you through the rules for the strategy, introduce you
00:23to the Python code that can be used to backtest this strategy, and also share some of my findings
00:28based on some very limited testing that I've done. So let's get started.
00:33If this is your first time here, welcome. My name is Vivek, and I'm a financially independent
00:36algo trader. This channel is all about building a community of algo traders. We discuss everything
00:40about algo trading using Python, building and backtesting trading strategies, market updates,
00:43and much more. Please do visit our community website fabtrader.in. Also do check out my
00:47other YouTube channel, Fab Wealth, where I talk about my own financial independence journey
00:50and share tools, methods, and strategies that help me achieve my financial freedom. Thank you.
00:54The Phoenix Bird, as you all know, is that mythical bird that rose from the ashes after it was
01:01burned down. So this bird is mostly anecdotally compared to things that bounces back into prominence
01:06after it was pushed down to the floor. So in this case, we are looking at stocks that faced
01:10similar situation. You have seen that the stock markets sometimes, in fact, most of the time,
01:15overreact. When this happens, certain stocks drop significantly in price for no apparent justified
01:19reason. It could even be due to some rumor about bad expected financial results, which is later,
01:24proved as false information. In such cases, the market catches up to reality. And we've always
01:29seen that some of these stocks quickly recover. And that's exactly what we're looking to exploit
01:33here and create a trading opportunity.
01:35The Phoenix Bird strategy is designed to identify such stocks that have hit bottom but show signs
01:40of resurgence. By applying a systematic approach to get at these stocks, we aim to capitalize on their
01:45potential rebound. So I guess the logic behind the strategy is very clear now. In terms of the strategy itself,
01:51it works on the daily timeframe. We only have long trades as part of the strategies, no shorts. The
01:57indicators, two key indicators that we use is one is the rate of change ROC indicator, as it's called an
02:01even trading view, and then the ATR, which is the average true range. The average true range is usually,
02:05in this case, usually going to be used to identify our target levels and these stop loss levels. We're going to be
02:12doing primarily on cash segment. And if people, you guys are very comfortable with futures, you could try and do so.
02:16But I assume that, you know, you'll have enough experience in doing so. Because if you do futures, typically the
02:22margin advantage that you have is pretty good, almost one is to four or more, most of the time. Stock universe, we'll stick to only Nifty 100.
02:28Ideally, you don't want to go beyond that, given the risk. The entry rules are pretty straightforward.
02:35So after the market is closed, at the end of the day, you typically run a scan to identify stocks that
02:40match the following criteria. Number one, the rate of change, which basically means that, you know,
02:45the current price in comparison to what it was 14 days ago, it should have dropped about 20%. So that
02:49indicates a sharp drop of price. So the ROC indicator basically gives you that data point. This indicator is
02:57available on TradingView as well. Anyway, the Python code that I'm going to share automatically calculates
03:01this value. So the second criteria is that we know that the price is sharply, you know, it's dropped
03:07pretty sharply, but we also want to see the rebound happening, right? So you want to see the momentum
03:11improvement, which is, you want to compare that the ROC today, after it has dropped, is much more
03:15positive than the ROC has yesterday. And the third is that you want to see the continuation or the
03:19confirmation of that momentum going up or the rebound happening. So what you do is that you wait for
03:23two days after the original signal is received. So you want to see that the ROC
03:27is continuing to go up, inch up, so that the ROC today is still more positive than what it was
03:32three days ago. So you have the first trigger that is happening, which is you have confirmation that
03:37it has dropped 20% very sharp within that 14-day period. And then you have the momentum improving,
03:42proved by the ROC from yesterday. And then you have the confirmation of that coming after three days,
03:47ensuring that the rebound is still in the path that we wanted to. So these are typically the rules of
03:53the criteria. And if these criteria are all met, the idea is that we take a trade at the next day's
03:58market open. Remember, we are only taking long trades here, no short ones. So in terms of the exit
04:05criteria, we have both target as well as stop loss. The target is basically 1x average true range. So
04:12again, there is an indicator in trading view, which will give you what the ATR value is. So you typically
04:16keep from the entry point, you have a 1x value of that. And then the stop loss, as per the strategy
04:21rules, it is 2.5 times stop loss. I know it's a bit too much, but what Raghu suggested is that he
04:29did some basic backtesting and found that this setup of 2.5 is to 1 has the maximum win rate. So we'll
04:37basically stick to what Raghu is suggesting here. And then the third is basically time basics. For example,
04:41if this goes sideways and you don't have a target as well as a stop loss hit, the price basically
04:46just dances within that range. After 10 days, you take a time-based exit. Those are the criteria.
04:54If you haven't joined our Telegram group, please do so. I share market insights,
04:57algo trading tips, new video notifications, and this way you can stay up to date with our community
05:01news and events. Let's take a quick look at the Python Backlist script. What I'll do is I'll run the
05:06script and then based on the output that we are getting here, I'll then go back to trading view and then
05:10also show you real-time how the entry is happening, the trigger is happening, and the exit is all
05:15happening. So I'll do that. All the information that I'm just talking about is already all available
05:19within the blog article here. I'll give the link in the description and pin this on the comment
05:23section as well. So it contains the overview, the exit rules, the entry rules, and the Python script.
05:27All you need to do is just copy this and run it. And then I've also attached, based on the limited
05:31testing that I've done, what the output, you know, the statistics look like, including the equity curve
05:37and draw down information. The Python script is very straightforward. In terms of dependencies,
05:42you would have to install these dependencies, pandas, numpy, matplotlib, and seaborn.
05:47The script itself is self-explanatory. I'm not going to walk through line by line.
05:51In terms of how we execute it right now, I've considered Nifty 50 as the universe here.
05:56And then for the backtest period, I've considered the 1st of January until end of March, 2025.
06:01I know this is a very short window, but for testing purposes, I'm considering a shorter window.
06:05But anyway, the script is available to you. And I would suggest that, you know, you run it for a
06:09longer period, at least for a period of about five years. Test this as much as possible from your side
06:14before you even think of implementing it. So a word of caution there. The script is run.
06:21The thing about the strategy is that you won't get a lot of trades because these are rare equations.
06:26So you'd hardly get, you know, for example, in this three months, you've got only five trades.
06:30I think I randomly checked for 2024. The entire year, you had only about six or eight trades,
06:34I believe. So anyway, this prints out all the details in terms of when the trade was triggered
06:39and when it was exited. It'll also give you the reason why it was exited. For example,
06:43was it a target hit or, you know, you're basically having a time limit exit or a stop loss.
06:48All that information is provided here. So five trades. Out of the five trades,
06:50we have a win rate of about 80. We have returns about 14.71. I've not considered brokerage here.
06:56I wanted to keep it simple. Start with profit factor of about four, which is pretty good.
07:01And then the average time duration for each trade is about 8.2 days.
07:07The script also includes some very basic reporting plots. For example, this is the equity curve across
07:12these five trades. And you see that overall, you know, the thing looks not bad. I mean, it's a good
07:17equity curve. This again is the distribution of the profit or the returns. So mostly on the positive
07:23side, you have a 4% here and an 8% here. And then a minus 4. This was the one that I think had a time
07:29exit triggered. Again, this is the monthly returns. Overall, about 14 point something returns. And then
07:37they draw down less than 5%, which is okay. Not a bad one. But again, given the number of trades is very,
07:43very less. Please do not take it on its face value. You definitely need to test this even more.
07:47Now let's take a look at those trades put out by Python. So Maintree was one of the first counters
07:55that came up. So as you can see, this is Maintree. This is a daily chart. And then I've put the ROC
08:00indicator below. And then you can clearly see, you know, the price basically dropping down pretty sharp.
08:06And the ROC indicator clearly indicates here that it has fallen below 20% here. So when that happens,
08:12this is the yellow line indicates when that trigger that did happen. And then you basically wait for
08:17two confirmations, right? You check whether the ROC is improving. And that's what is happening here.
08:21And the actual entry is taken on the 4th of March. 4th of March is where you're getting the
08:25confirmation to enter. So you typically enter on the opening of the next day, which is this candle.
08:29And in this case, what happened is it did not hit either the target or the stop loss. It went a bit
08:33sideways. And then on the 10th day, the trade basically was exited based on time exit. And I think,
08:39I believe it was a minus 4 return on this particular day. And then on the same day,
08:44it again hit and then confirmation was received. Again, the entry criteria was triggered. And then
08:51on 20th of March, the second rate was entered. But this time when it was exited on the 24th,
08:58we hit the target of 180. So this was a successful trade and this was not.
09:02The second counter was Wipro. Again, the trigger or the ROC fell sharply on the 13th of March.
09:10The confirmation was received on the 19th. In fact, it was received on the 18th. And then the trade
09:14was entered on the beginning of the 19th. And then within a few days, which is on the 27th,
09:20the target of 180 was hit. So this particular trade was a success.
09:23Overall, I think this strategy is good. But however, remember that we've only done, you know,
09:28only a couple of practices here for a very short period of time. This is in no way a recommendation
09:33for you to start using this. This is only for education purposes. So I would strongly suggest
09:37that, you know, you run your own tests. Please do not take this as recommendation again. And then once
09:42you run those tests for various time periods, please do comment and let me know how it went
09:46and what else you found so that we can share it to the rest of the community.
09:50Hope you liked this strategy. If you'd like to see more content like this, please do like this video.
09:54And that will motivate me to keep doing this. If you'd also like to share some of your strategies
09:58with the community, or you'd like me to backtest any of your strategies, please do email me with
10:01the details. And I'll do my best. Thank you. If you genuinely found this video useful, please
10:05consider subscribing and liking the video. And I will see you soon in another video. And until then,
10:09take care and happy trading.
Comments

Recommended