In this part of Quantpedia Explains Trading Strategies Video Series Radovan Vojtko shows you how Quantpedia experts are using EOD Historical Data (EODHD) APIs to find ideas for new trading strategies, and how you can use it to backtest that strategies and improve them.
Before to speak about Turn of the Month Effect Strategy, you’ll want to learn more of what Quantpedia does:
Our main goal is to provide inspiration for new trading strategies and to give fresh ideas for new trading systems for anybody who is interested in algorithmic trading and quantitative trading through the academic research. With focusing on finding interesting papers we do:
• Scan Research Portals
• Financial Journals
• University Web Pages
• Conference Web Pages
Once interesting trading strategy or interesting paper is identified, we extract characteristics, trading rules in plain language, the performance of these characteristics. Then we categorize each strategy by several keywords, the result of all of this work is our database which consists of nearly 800 strategies you can easily screen.
1:35 – Introduction to the “Turn of the Month” trading strategy
The trading strategy that I selected for today is called “Turn of the Month.” The turn of the month effect is a very interesting effect, it’s known for a long time. “The turn of the month” says that there is a significantly higher probability that U.S equities will perform well around the end of the month and the beginning of the new month. Now, the actual period during which we should hold the U.S equities or U.S equity index differs from paper to paper, but usually, it’s the last four days of the month and the first three days of the month.
2:09 – Introduction to EODhistoricaldata.com as a provider of historical and financial data APIs and the demonstration of using the Google Sheets add-in to access data for backtesting
Backtested performance of such a strategy is listing, and it performs significantly well in the last years, and we will try to backtest this strategy by using EODhistoricaldata.com. I will show you how.
EODhistoricaldata.com is the provider of historical data and financial data APIs. It provides over 30 years of data and multiple exchanges, along with 150,000 tickers, 20,000 ETFs, things like 1000 indices. They provide a lot of the data. What they provide is multiple different APIs that we can use to connect to their data set. What I will show you at the moment is how to use the Google Sheets add-in or plugin and how to backtest this idea in a Google Sheet. You can also use Excel add-ins and some APIs. You can read the whole documentation on their web page, how you can access the EOD historical data. The easy way is to integrate the Google Sheets financial add-in into our Google sheet, and we can easily find any data that we need.
3:09 – Explanation of how to perform a backtest for the “Turn of the Month” strategy using the adjusted close data set from EODhistoricaldata.com
So, for example, by SPY.US, I can select starting date, ending date, etc., and I will receive the pricing data directly into a Google Sheet. That’s what I did, and I asked for prices for SPY ETF, and I received the prices for SPY ETF. And then we use the adjusted close data set or an adjusted price of the close, with splits and dividends adjusted price, to backtest the turn of the month strategy.
How does the backtest look like? Firstly, we need to copy end-of-day data for SPY ETF, and then we can calculate the daily performance. But it’s easily done by dividing today’s price by the previous day’s price and subtracting one. And we can check what is the performance of the SPY ETF from the beginning. We can see that the performance is 9.67% with a maximum drawdown of 55%. Yeah, we aren’t nearly 10% of the year over the last 40 years from 1993, but we had multiple alternative drawdowns with the highest drawdown over 50%. We have a ratio so we can compare the ratio of performance or yearly performance compared to the maximum risk. So in our case, in life control, we can see that our benchmark, when we just hold US equities, we have a performance-to-drawdown ratio of 0.18, which is not bad but also not the best. As I said, we have a 10% performance but with nearly a 55% drawdown. Now, how can we improve on this performance? We can try to build this “Turn of the Month” strategy.
4:38 – Analysis of the backtest results for the “Turn of the Month” strategy, including the overall performance, drawdown, and performance-to-drawdown ratio
Firstly, we need to identify when is the first day of the month. We can do it easily by checking and comparing whether the actual date is in a new month. If it is, then we will have number one. In case there is a difference between the actual month and the previous month, this way, in this equation, we can easily find what is the first day of the month. Now, once we have the first day of the month, we can check what is D-4, D-3, D-2, D-1, and the first three days of the month. So, these four are the last four days of the previous month, and the first three days of the month.
5:18 – Identification of the specific days within the “Turn of the Month” period and their significance for the strategy
Once we identify all of those days, we will identify the period that starts four days before the end of the previous month and holds until the first day of the new month. And we will hold equities just during these seven days. And we can check what is the performance during the “Turn of the Month” season, or during these seven days. We can see that we have nearly 8% performance with significantly lower drawdown. So, our performance-to-drawdown ratio improved from 0.18 to 0.46. So, we do not need to hold equities all of the month. We can hold equities only during the “Turn of the Month” period, and we can have nearly the same performance as holding stocks outside of the “Turn of the Month” with a significantly lower drawdown and with a significantly improved performance-to-drawdown ratio.
6:06 – Comparison of the performance between holding equities throughout the entire “Turn of the Month” period and only on the first day of the month
Here, we can have a chart, and this chart is showing what is the performance of the SPY benchmark and what is the performance of this very simple “Turn of the Month” strategy.
Can we improve this trading strategy? Of course, there are some ways how you can improve it, and I will show you what we can do. The first important thing is to try to check what is the performance during each day. So, what is the performance on D-4, D-3, etc. So, we are trying to identify what are the days that are driving the performance of the “Turn of the Month”. And normally, so what are the most significant days when the equities are really outperforming or when the equities are really performing?
6:41 – Introduction of the idea of applying leverage to the strategy and the importance of identifying the days with the highest probability of positive performance
So, when we do this analysis, you can see that not all of the days are the same. The day with the significantly highest performance is the first day of the month. Most of the other days also provide their performance into the overall trading strategy, so into the overall “Turn of the Month”. But the first day of the month is the strongest. Sometimes, the “Turn of the Month” anomaly is traded only during the first day of the month. But when we trade a strategy only during the first day of the month, we do not have such strong performance as we would like. So we have only a three percent performance. Of course, our drawdown is significantly lower. Our performance-to-drawdown ratio is still interesting, not as high as during all of the seven days, but it still becomes more attractive than just the benchmark performance. But we would like to increase the performance of this first day.
How we can do it? By applying leverage. Before we apply leverage, we need to tap into mode. What we can do is we can try to apply the trend or momentum filter to even increase the probability that we will pick correctly with the highest probability of positive performance.
7:49 – Explanation of how to apply a momentum filter to the strategy and combine it with the internal demand signal
How we can do it? Let’s check how we can apply the momentum filter. Here we have again the performance of the benchmark. So it means buying and holding the ETF and holding the S&P 500 index ETF. Once again, nearly 10 percent performance with a 55 percent drawdown. We will calculate the 20-day momentum and the signal that says whether the current day price is higher than the price 20 days before. And we will use this as a filter that will tell us how to improve the performance of the underlying internal demand signal.
8:22 – Introduction of a rule that combines the performance of the internal demand signal with the previous day’s momentum to determine whether to hold the SPY ETF
Our next rule is a little more complicated. What we will do is that we will combine the performance of the internal demand signal with the previous day’s momentum. So what does it mean? We will check whether during the internal demand period, the previous day’s 20-day momentum was positive. And only in this case, we hold the SPY ETF. In case the previous day’s momentum is negative, we do not have any position.
As we can see in this example, the internal demand signal says to us that we should hold the SPY ETF, but the momentum is negative, which means we have no position. I can move a little higher. Let’s move here. So if I move here and check the equation, I can see that the SPY turn of demand strategy is telling us to hold the underlying SPY ETF. We have the positive 20-day momentum, so it means we can hold the underlying ETF in this case because the momentum is positive. And also, the internal demand period says to us that we should hold the US Equity ETF.
9:29 – Comparison of the performance when applying the momentum filter to the entire “Turn of the Month” period versus only the first day of the month
What is the performance in case we use this momentum filter on the whole 7-day period? So we can see that we were not able to improve significantly the performance of the internal demand strategy. But what is most interesting is that when we apply this filter only to the first day in the month, it is the case. So we do not apply this momentum filter to the strategy that holds the SPY ETF through all of the seven days, but only during the first day of the month. We were able to see a cut and improve the performance-to-drawdown ratio.
10:06 – Discussion of leveraging options, including using the SSO ETF to obtain leverage for the trading strategy
If you remember correctly from the previous sheet, we had a performance around 3 percent and maximum drawdown around 11 percent. The performance-to-drawdown ratio was around 0.26. In this case, we have a little overperformance, but our drawdown during the first day is less than half. So our performance-to-drawdown ratio is missing. Now we know that when we combine the internal demand period, when we hold the SPY ETF only during the first day of the month, with the 20-day momentum filter, we can significantly improve the overall performance-to-drawdown ratio.
Now it’s time to apply leverage. When you want to apply leverage, there are multiple ways how you can do it.
The easiest one is to use the ultra S&P 500 EPF SSO ETF, which is daily investment returns before fees and expenses that corresponds to four times the daily performance of the S&P 500. So, that’s the easiest way how to do it. We can instead of buying SPY ETF for the first day of the month, we will just buy SSO ETF, which will give us 200 allocation to S&P 500. It doesn’t make sense to hold this ETF for a longer period because during a longer period there is significant volatility draft for this ultra double and triple ETFs. But when we hold this ETF only for one day, it’s a very easy way to obtain leverage for our trading.
11:20 – Demonstration of applying leverage to the strategy using the EOD Historical Data plugin in Google Sheets
Let’s move back. We can use the EOD Historical Data plugin and apply it here. SSO.US ticker, we can select the period, get the prices. The accessory ETF started in 2006, so we have like 16 or 17 years long practice. Let’s move on and try to apply the leverage. So, here we are, trying to apply leverage to the sheet. In this case, we copy-paste the data, close prices for ETF, into the next sheet. We calculate the daily performance, and then once again we try to identify what is the first day of the month; we have an equation, or formula, giving us number one when the current month is different from the previous month. That means that – okay, we know that we have to hold the underlying ETF because it’s the first day of the month.
12:13 – Calculation of the performance for the “Turn of the Month” strategy with leverage and comparison against the SPY benchmark
We will check the signals for the area D-4 and D-2 and D-3, so – last 4 days of the month and the first 3 days of the month. We will apply the trend demand strategy on SSO ETF. First we will try to apply just the naive or simple strategy that holds the underlying ETF during the seven days around the end of the month and we can compare it against the performance of the SPY benchmark. So when we apply the leverage, we can see that we have – firstly – significantly higher performance, nearly 15 percent instead of 9 percent, we have a significantly lower drawdown, instead of 55 percent we have 41 percent, which translates into a significantly better performance-to-drawdown ratio – instead of 0.17 we have 0.42. The number for SPY is a little different compared to previous numbers from the previous case because we are doing vectors from 2006 because we have data for the SSO ETF from 2006, not from 1993, but we still have a 16 or 17-year period of data collected, which is nice. So, we can easily improve the performance of the SPY benchmark by using the leverage and downloading the underlying S&P 500 ETF only during the few days of the month.
13:25 – Introduction of the final rules for the strategy, which involve holding the SSO ETF on the first day of the month based on the momentum filter and the previous 20-day performance of the SPY ETF
Now let’s move on. We will try in this space to apply the internal demand strategy, but also with the momentum filter, but just for the first day of the month – so instead of using 7 days we will use the first, one day – but we will also apply the momentum filter.
What are the final rules? We will hold the SSO ETF during the first day of the month in case at the end of the month the previous 20-day performance of the SPY ETF was positive, or of the underlying S&P 500 index. So we are checking if the index has a positive momentum, shorter than 20-day momentum, so we’re in an uptrend at the end of the month, we buy the SSO ETF, which gives as 200 percent leverage for the underlying S&P500 index, and hold it for one day. Our performance is nearly 5 percent with a negligible 9 percent drawdown. The performance-to-drawdown ratio is 0.52, significantly better than the benchmark case. Our performance is half of the benchmark performance, but our drawdown is 1/6 or 1/7 or 1/50 of the original drawdown of S&P 500. So our equity curve looks in category.
14:43 – Conclusion
Thank you very much for your attention. This was the first video that I built for the financial academy webpage on EODhistoricaldata.com webpage. I will show you multiple other anomalies that are present in the financial market. I will show you how to improve these anomalies and how we can mix them into a multi-strategy portfolio using EODhistoricaldata for this purpose. Thank you again for your attention, and I hope you will join me in the next video.