Category Archives: Indicators and Edges
Perhaps one of the most difficult decisions faced by discretionary and system traders is how to allocate capital effectively to get the most bang for the buck. In other words, how do we choose which stocks to trade? Of course most traders will have a method (could be technical or fundamental) they use to screen for eligible candidates, but invariably the number of candidates will exceed what can be managed with available time and capital. I can remember spending many many hours in the evenings pouring over charts, looking at setups, and trying to decide which setup was better than another.
All other elements of a setup being equal, the final arbiter of stock selection should be volatility. Volatility will determine whether one stock is likely to move farther/faster than another over a given period of time. This is bang for the buck.
Lets go back to our hypothetical trader with 20 eligible setups, but only enough capital available for 5 positions. The 20 setups should be ranked based on their volatility, and the 5 most volatile stocks should be selected. These stocks will be more likely to produce larger gains (or losses) than their brethren.
This one simple addition to a trader’s toolbox will save time through simplification of the selection process, and assuming one is in possession of a positive expectancy strategy, will increase returns.
In case you hadn’t noticed, there is a new sheriff in town, and his name is DV2. The DV2 is a new indicator developed by David Varadi of CSS Analytics blog fame. For the best overview of how this indicator works, including how to calculate it, see this series of posts.
While there has been a great deal already written about this indicator (geeks are easily excited by such things as new formulas), one aspect that has been mentioned but not yet reviewed in the quant blogosphere is that a divergence between DV2 and RSI2 may allow forecasting of future returns.
Entry: Go long the SPY if the difference yesterday between RSI2 and DV2 < 5 and the difference today > 5.
Exit: An n day exit (geek speak for a time based exit) will be used.
All trades are opened and closed at the close, and no commissions were used. While I prefer testing opening and closing trades on the open, my rate-of-change calculations were already set up using the closing prices.
The blue line illustrates the average daily change after buying the SPY when the difference between RSI2 and DV2 is greater than 5. The red line is the average daily rate-of-change of the SPY, calculated using all of its history.
The graph demonstrates that there is an edge. In terms of efficiency (profits per day) it appears that the edge is strongest over the next 4 days following the divergence.
The results show that there can be situations where RSI2 has risen to extreme heights without confirmation from DV2. Traditionally, a high RSI2 would have signaled to sell a long position or go short. The addition of DV2 can help traders judge when the market might have room for additional upside, despite an extreme RSI2 reading. This phenomenon is best illustrated by looking at a chart of the two indicators with the SPY (below).
The green arrows show all raw entry possibilities. There were many times over the past several months were DV2 did not confirm RSI2, and a divergence developed. The divergence can alert traders to the possibility of more upside.
In the future I will examine what happens when the opposite divergence occurs (DV2 is higher than RSI2). Also, an extreme divergence where (RSI2-DV2)>50 will be examined to determine any implications for forecasting future returns.
Should anyone find the DV2 to be a valuable addition to his toolbox, Mr. Varadi will be releasing the DV2 along with a whole suite of indicators, including a super-charged DV2, in the very near future. Be sure to visit his blog for more information.
The MACD is one of the best-known indicators, or more precisely, centered oscillators. It is used in a variety of ways by many traders. A popular way of using the MACD is to trade the moving average crossover of MACD above its 9 day EMA. As this setup is so widely popular I’ve often wondered how well it works, partially due to my natural skepticism but also because if it works, perhaps there is a system that can be built using it.
Testing the MACD
Entry: Buy the close if the difference between the 12 and 26 day exponential moving average (MACD) has crossed above its own 9 day EMA.
Exit: A time exit between 1-20 days will be used, with the trades being executed at the close.
How do we know if it works?
The 1 day and 20 day rate-of-change will be compared with the baseline data. Also, I may work up a simple test with money management rules to see the system drawdown and equity curve.
When I backtest ideas, I like to be sure that I am testing them in a way that can be re-created in real-life trading. It bothers me that there can be bullish MACD crosses when the cross barely registers, because if one were trying to recreate this trade in real-time, it would probably be impossible to know for sure if the cross was going to happen in time to get the order filled. Therefore, I calculated the difference between the MACD and Signal and required the result be above a minimum threshold.
Requiring the threshold performs two functions in the testing. The first is that it helps to make it more possible for the trade to be replicated in real life. Secondly, we can evaluate the results to see if they are improved by requiring a strong MACD bullish crossover.
Four separate tests were run. One test did not use a threshold, and the 3 others tested thresholds of .01, .03, and .05 A threshold of .01 is very small, and as represented in the histogram of a typical MACD graph, may even be imperceptible unless the graph is magnified.
I am also including below 4 graphs, each showing the average ROC, from 1-20 days out, following a positive MACD cross. Pay careful attention to how the threshold criteria affects the ROC.
1985 – 9/09/2009
Results: 1990-1999 (Bullish Period)
Results: 2000 – 9/9/09 (Bearish Period)
MACD can provide a slight edge on the day after the cross. Even during the bearish period when a bullish MACD cross did not work well at all, the day after the cross provided almost double the average one-day return.
Adding the threshold requirement puts an interesting twist on the MACD cross, at least in my opinion.
Almost without exception, a strong MACD cross (one that closes with the histogram greater than .05) results in a period of negative, or lowered expectancy.
Over a longer period, as measured by the 20 day rate-of-change, a MACD cross is often much worse than a random entry.
More than anything, these MACD studies show that for the better part of 10 years, the universe of stocks has been subject to a strong tendency to mean-revert. Likely the best way to use the MACD is to filter for a reading that is very extended above/below the zero line, and then short/buy the stock, expecting a reversal to the mean.
Comments, concerns, and criticism on this research is welcome, as always.
I included the above chart to show just how small a cross of .05 is, in comparison to how much it affects future returns.
Since it has taken me a while to get this series going, here are two articles to refresh the memory:
In the first Baseline Results post, I asked for a review of my methodology for developing a baseline. I received lots of very good feedback. Most of it can be read in the comments section of the post. I also received a few emails. Let me summarize the salient points:
- Since this will be a database of stocks that will be actively traded, the database should filter stocks for volume and liquidity.
- The database should be split into bullish and bearish periods to allow for more precise comparisons.
- An average 1 day rate-of-change should not be extrapolated out over a period of days.
- Use de-listed data.¹
These suggestions were very helpful, and all were implemented except for using de-listed data.
The Volume and Liquidity Filter
Each stock was filtered to have a 20-day average volume of greater than 100,000 shares.
To filter for liquidity (we want a reasonable bid/ask spread), I multiplied the 20-day average volume by the 20-day average of the closing price. The result must be over $1,000,000.
If at any point in time any stock could not meet the minimum criteria, that period was dropped from the database, and then later data included once the filter was again satisfied.
Bullish and Bearish Markets
One database starts on 1/1/1990 and ends on 12/31/1999. This is my bullish database.
The second database runs from 1/1/2000 to 9/9/2009. Of course, this is the bearish database.
A third database includes all data I had available, from 1985 to the second week of September, 2009.
ROC1, ROC20, and % of Up Days
To avoid having to extrapolate a 1-day ROC out over 20 days, I ran more tests to determine the average 20-day ROC for each database. I also calculated the percentage of days that closed up.²
Baseline Data: Major Exchange Tradeable
Just as I during the first round of testing, I excluded all over-the-counter issues and any issue that traded under 1 dollar.
It is interesting that the filters did not significantly change the results of the 1985 – 9/9/09 database compared to the original database covering the same time period.
I feel that the baseline results are now robust enough to begin testing indicators against them. I am glad to have this part of the project out of the way so that I can now begin the fun stuff!
¹ I use Norgate data and can easily purchase their de-listed database. However, I do not have a single strategy that buys cheap or value stocks to hold for any length of time, therefore I would derive little benefit as those would be the bulk of the stocks in the database. However, any stock that was acquired would also be included in the de-listed data, and those might have been ones I would have traded. Long story short, the database is not perfect.
² For a great explanation of why the % of Up Days is low, read Rob Hanna’s excellent post on the topic: A Long Term Look at the Nasdaq Advance/Decline.
I kindly request any quants and system developers to let me know if there is any data I present that seems to be out-of-line with your research or not congruent with the results from other similar tests.
When testing how well common indicators work, there must be something to which their performance can be compared. Simply put, a baseline is needed.
Developing a baseline has not been an easy task. I took the path that would allow the most robust results without exceeding the capability of my software, databases, and my free time. Still, these results are nowhere near perfect, although I do believe they will suffice. I will list some limitations of my approach to developing the baseline results in the footnotes.
I am a short-term trader. I typically do not like to hold positions for more than 20 days. Therefore, when I examine an entry as signaled by an indicator, I want to see immediate results. If it takes 10 days for a signal to produce results, then I have lost half of my allotted time-horizon, and my capital has been wasted due to opportunity cost.
In fact, I think that most traders expect that something should happen after any given indicator produces a signal.
Therefore, what we are expecting is that there will be a positive rate-of-change (ROC) produced immediately following a buy/sell signal being issued from any given indicator. Rate-of-change is a commonly used measure that simply calculates in percentage terms how much the value of a security has changed over X days. For example, using the closing price, the ROC1 (one-day Rate-of-Change) for SPY from Thursday to Friday was -0.02%.
Computing the Baseline:
Major Exchange Listed Stocks
If we are using ROC, then what we want to know is what has been the average ROC of all securities on any given day. While this is simple in concept, it is difficult to measure, primarily because the hundreds of millions of data points make the database very unwieldy.
My partner suggested that I use a random number function to randomly select securities from the database. This would, through repeated tests, provide a large sample size, yet each run’s database would not be too large for Excel to handle.
The process worked this way in AmiBroker: The random number function would compile the ROC1 of 5% of securities in my database, listed on any major exchange. The major exchange requirement filtered out OTCBB and Pink Sheets isssues. Each randomly selected security produced all of its history, in terms of ROC1. After each run, what I ended up with was a database of approximately 1 million rows, with each row containing the ROC1 for each day of security’s history.
Simply put, each database contains the complete history, in terms of ROC1 (what a stock did in percentage terms each day of its life) of 5% of the securities listed on a major exchange. I ran this test 20 times, making 20 databases, which provided almost 20 million one-day rates of change.¹ The average of each database was then averaged, which produced the result you will see in the graph below.
- The ROC1 averages across each database did show some variation. The highest average was 0.1223 and the lowest was .0723, which produced a range of .0499
- While the variation is a concern, I ran other tests previous to these, and the results of these tests are very similar to the previous tests, even though the method was different.
- There was very very little variation in the % Up Days.
The bulk of my database goes back to 1985, but there are some securities for which I have older data. As you will see, I have much more history for some of the broad indices.
The Broad Indices
I also want to compare the performance of indicators against the broad indices. For every index except the Dow Jones, I have all history available. For the Dow Jones, I could only go back as far as 1901.
I used the data on the indices exactly the same way as I did with the major exchange listed stocks, which was to figure each day’s ROC, and then average all the days together. I also counted the number of days the index closed up.
There are some interesting trends in the above data. It appears that indices with more history exhibit less variation than those with a shorter history. It may also be explained by the law of large numbers, or perhaps it is simply survivorship bias.² Also, the standard deviation of the ROC1 (not published here) grew as the average ROC grew. This should be a reminder that higher volatility will produce a higher rate-of-change.
Throughout testing of the major exchange listed (MEL) stocks, the % Up Days exhibited very little variation. I’m curious as to why the % Up Days on the MEL stocks is much less than the % Up Days on the indices. If anyone can offer an explanation, or even a guess, I would appreciate the input.
The above graph takes the average ROC1 of each index and adds the ROC1 to itself for each day going forward. I am going to use this graph in two ways.
First, we are going to look for what happens one day after the indicator gives a signal.³ An indicator that can produce ROC1 of .20 will beat the indices by a factor of 8 and will beat the MEL average by a factor of 2. (Imagine an indicator signal that produces a ROC1 of 1%. Now imagine that there are 10 opportunities a day. Theoretically, one could make 10 trades a day, averaging 1% in each trade.) The point is that we want to see the indicator immediately producing a ROC1 that beats the indices and the MEL average. If it does not beat these averages, then perhaps the indicator signal is to be faded.
Secondly, not every indicator is going to produce a high ROC1, right from the start. Perhaps the indicator is signaling that the conditions are ripe for a positive change over time, but not right away. To examine if this is true, I will record the ROC from 1 to 20 days out, and then plot these results next to the indices and MEL average. This may be hard to conceptualize, but once I start plotting the results, it should make more sense.
I’m going to let this post float around the blogosphere for a few days in hopes that there is some commentary or criticism generated by quant/system trading bloggers. I want to be sure that the foundation of my research is sound before moving forward. If my baseline results are deemed robust, then I will begin testing the MACD, sometime this week.
¹ I know that some symbols’ histories were randomly selected more than once. It is possible the same stocks were selected three or even more times. It is also likely that some symbols were never randomly selected at all, and therefore their ROC1 are not included in the average. Also, some stocks had histories that may have started in 2000, while others went back much further. Obviously a stock that IPO’ed in 2007 is going to produce an average ROC1 that will be much different from one that IPO’ed in 1990.
Stopping at 20 runs was a somewhat arbitrary decision. I could have run the test 40, 100, or 200 times, and then averaged those averages. I simply did not have the time to do that.
² I do not have delisted data, so survivorship bias is a concern.
³ I will eventually begin discussing ROC as Profits Per Day (PPD), as popularized by BHH at IBDindex. PPD describes what we are looking for, which is how much profits per day are produced by a given indicator over a given period of time.
This post will serve as the introduction for a series of posts which will likely span several weeks or more. When I’m finished, I hope that the series will serve as a reference of sorts for the newbie/rookie trader who seeks the aid of indicators when making trading decisions.
When I started trading, luckily I did not buy into the indicator craze, as I am somewhat sceptical by nature. However, there may be many traders out there who want to use the standard indicators, and hopefully, late at night, they are wondering, “Do they work as described?” I will attempt to answer this question, and will do my best to answer any more questions that are generated from the testing results.
The most important thing to realize is that the professionals have already run these tests, and they may or may not be taking the other side or your trades.
Of course, in the vein of Michael Stokes’s post, this information has likely been covered in various books, such as this one. However, there is a great deal that I stand to gain from running these tests myself, mainly from familiarizing myself with the intracies of the indicators as well as the experience that will come from coding the backtests. So yeah, there is something in it for me, too. I do hope though that this format, being interactive, can be more beneficial than a chapter in a book.
In this series I will test indicators several different ways.
First, we will look at what happens the day after an indicator gives a buy/sell signal. For example, what happens when the MACD crosses and gives a buy signal? Is there any edge the next day? Finding an indicator with a large short term edge can be a gold mine. Imagine an indicator that provides an average trade of 0.5% over the next day and has five opportunities per day. The point is, if an indicator provides a large edge and enough opportunities over a very short time frame, that is where money should be placed (assuming you have a short-term time horizon).
Secondly, we will examine the edge provided by an indicator looking out over X days. For example, when a MACD cross occurs, what is the average profit per trade 20 days later?
Finally, we will look at indicator settings that have given the best results over the last fifteen years or so. I think what we will find is that the settings currently being used are likely not even close to being optimal. Maybe not. We’ll see…
As mentioned in the introduction, this will not be a series that can be finished quickly. Each indicator will probably need three or so posts to flesh out the results as described above. I plan to get started this week. The first indicator to be examined is the very popular Moving Average Convergence/Divergence, otherwise known as MACD.
Be on the lookout for this upcoming post: Indicators and Edges: MACD.