Monday, February 21, 2011

Trading the STI with RSI - Student's Post

Having looked at Bollinger’s bands it is relatively elementary to adapt the backtesting code to test RSI. Thus the opportunity must not be refused.
Theoretical discussion
Since both portend reversals  by exceeding a certain limit I suspected some kind of mathematical similarity between them, but could not prove it. However the mathematically inclined will note the close similarity between taking EMA(U,n) and EMA(D,n) for the RSI and taking  for the Bollinger Band. Based on rough, back of the envelope calculations the standard 30-70 Band for RSI seemed to translate into only a ~1 S.D. Bollinger Band, which means that RSI trading would tend to be more active than BB trading (as the prices cross the bands more often) and perhaps not as profitable.
Testing the RSI
A few things were of interest to me:
  • Does RSI make money with “normal” rules or with “inverted” rules?
  • Does RSI improve if we change the length of periods?
  • Does RSI make money on short and long legs?
Saving my usual chart-filled melodrama, here are the summary statistics (backtesting RSI trading on STI from 1975 to present):

  • Just like Bollinger Bands, it is necessary to “invert” all buy and sell signals in order to make money. (the “window” tests you see have all inverted their signals as well) The “Normal Rules” trading loses 92.8% of its money over time.
  • Inverted RSI makes some but not much money on the short leg; however adding the short leg to the long adds another 3.2% per year. Using the inverted rules for RSI trading also turns strategy returns into positive skew – this is a very nice feature to have.
  • A smaller window (5 day) performs better than the normal 14 day window (“Inverted Long”) and both do much better than a larger window (25 day). Window lengths beyond 50 days show no appreciable advantage over buy and hold.
Because PDT cares about data visualization though, here is the chart (based on the principle that one picture is worth a thousand charts) (note, on these charts I plot the results from 1990-present, just to see if any of the results have changed in more recent times; i could equally do the charts from 1975-present, but that would literally not add any information to the table above.

Bollinger Bands On the STI - Student's Post

Bollinger Bands differ from the Moving Average in that it is commonly (but not exclusively) used as a signal of impending reversal, while the MA is used as a signal of continuing trends. In this sense BBs have more in common with DVaR strategies in attempting to pre-empt large reversals that can do severe damage to a trend-follower.
Some background reading here, and here.
A theoretical discussion on reversal indicators
As the empirical evidence for trend following is well established, any speculator attempting to take on a reversal position is putting himself at a relatively high probability of small loss by going countertrend. His expectation can only be brought into the black by a corresponding high payoff when the reversal does indeed happen. Since the general expectation for a long-only trend following strategy is positive, it follows that a countertrend strategy that adopts precisely the inverse of the original strategy will be lossmaking. Thus it is mathematically necessary that, for a given moving average window, a reversal strategy must be more selective than the inverse of the trend following strategy in order to have any hope of being profitable in the long run.
Bollinger Bands
Bollinger Bands achieve this required selectivity by only taking pricepoints outside a 2 standard deviation range from the average as trading signals, thus eliminating close to 95% of pricepoints. However there is no one agreed upon or systematically consistent way of using the BBs for trade entry, as John Bollinger himself concedes. There is even less of a consensus on using BBs for trade exits (Investopedia conveniently neglects to discuss this).
Testing
What’s a tester to do? I built a generalized bollinger band trading program that allows for a few options:
  • Varying the sizes of the moving windows
  • Inverting the “normal” buy and sell signals
  • Trading long-only or short-only or both
  • 2 kinds of exit strategies – “reversion to 1 S.D.” and “hold to extremes”
This allows us to investigate Bollinger Band strategies systematically.
Exit Strategy 1 – Reversion to 1 SD
In this strategy, the “normal” buy signal is triggered when the price goes below the lower BB, which is 2 S.D. from the middle band, and the position is held until the price returns between 1.S.D and the middle band.
Without inversion, long-only
This graph shows the equity lines for long-only trades without “inverting” the normal buy and sell signals. The other charts for short-only trades and long-and-short trades show the same deal. Thus, this strategy consistently loses money on both the long and short sides. It stands to reason that “inverting” the buy and sell signals would make some dough, and so it does:
With inversion, long-and-short
This chart, unlike the first, shows the equity line from the long-and-short trades, not just the long-only: we see that it benefited on the long side during the 1997 Asian Financial Crisis (time period ~2000) and on the short side during the 2008 Global Financial Crisis (time period ~4500). This indicates that Bollinger Bands actually have better value as a trend following indicator than as a reversal indicator.
Exit Strategy 2 – “Hold to extremes”
This strategy buys when the price drops below the lower band and hangs on for dear life, selling only when the price rises higher than the upper band. Thus this strategy is much more involved in the market than strategy 1; we anticipate, from our theoretical discussion above, that strategy 2 will result in lower profits because of the “drag” from trading countertrend.
Without inversion, long-only
Without “inversion”, this strategy performs in much the same way. Same for the short-only side. Not much to report.
With inversion, long-and-short
With Inversion, the strategies work beautifully. the only task left is to compare the best of these strategies (it is the 25 -day window for the both of them).
We see that my original intuition was wrong – the CAGR for the Exit 2 strategy was actually higher. This could be because that the Exit 2 strategy actually winds up benefiting more from the trend strategy than I suspected. However, it suffers much worse and longer drawdowns than the Exit 1 strategy.
Cutting to the chase:
Bollinger Band strategies are useful as “trend-following-plus” strategies, not as “reversal” strategies.

Combining DVaR and Moving Average Strategies for Market Timing - Student's Post

Combining the trading strategies of DVaR and Moving Average produces this result on the STI from 1975 to present:
The relevant parameters are 5 and 25 for the short and long MA signals, and 1.5% for DVaR. Summary statistics are presented here:

Clearly we already knew that Moving Avg and DVaR strategies were going to improve both Return and Sharpe. But now we are able to put these in perspective when we linearly combine (multiply) the trading signals that result from the two strategies. We are able to see a few surprising things:
  • DVaR massively decreases the “fat-tailed” distribution of the STI; Moving Average also does the same to a small extent.
  • Curiously, while DVaR decreases kurtosis, it increases daily standard deviation. This means that less of the daily variance is actually a result of infrequent extreme events, which we like.
  • Moving Average massively decreases the negative skew of the STI; DVaR does the same to a small extent. This result is corroborated by the “Worst Day” statistic.
  • Despite the only incremental rise in Sharpe when adding DVaR onto Moving Avg for the Combined strategy, we see a large rise in CAGR of about 3%. This may be attributed to volatility drag, but of the second degree – because DVaR lowers the Kurtosis of the combined strategy, annual return is increased. This effect might even be called “kurtosis drag”.
The matlab program to do this is available upon request.

Does Technical Analysis Work? Results from the past 5 years - Student's Post

Taken from http://processdriventrading.wordpress.com/page/2/

Here’s some lighter PDT reading for you this rainy Friday. A lot of people, certainly the vast majority of the Singapore Investoblogosphere, use copious amounts of technical analysis. The way I approach technical analysis is in skeptical but openminded fashion – the burden of proof is on TA to show that it works, instead of the burden of proof being on me to show how it does not work (this is the true scientific method in investing – nothing can ever be shown to be true, but it can be shown to not have been proven false yet). In other words, my uninformed expectation of the value of much of the technical analysis being done out there is so close to zero it can be safely ignored^, thus I see no need to put in the effort to rigorously check if it has negative value.
However when the opportunity comes to quickly and authoritatively test TA, I welcome it with open arms. I ran the Bloomberg BTST screen from 2006-2011* on daily and monthly intervals, using long-only and long-and-short trades. The results are below:
Using the data:
  • btst guide is the official guide to what each of the fields mean as well as how each indicator was calculated.
  • For Bloomberg newbies, each chart has been sorted according to final profit/loss figures (the number in green and red). This shows the final amount you would have gained or lost after starting off with $100k of capital in 2006. However, as this final figure could have come with a lot of downside variability, I will make reference to the corresponding Sharpe ratios as well.
  • You will notice the glaring omission of some very popular technicals – head and shoulders, elliot wave, etc. This is because they are NOT objectively codifiable in any conceivable way and thus impossible to backtest**.
  • You will also notice the omission of volume-based technical indicators, which is unforgivable.
  • Bloomberg tries to make up for this by introducing some you have never heard of – “Fear and Greed” indicator anyone?
There are a lot of numbers here, so let’s look at them in some semblance of order:
  • First look at the STI and HSI “long daily” charts.
  • I believe these two charts are the most relevant to so-called “punters” who trade on technical analysis as they are generally unable to go short. We see that moving average-based strategies perform well, improving the index Sharpe ratios from 0.5 to about 1.9 and 0.68 to about 1.93 respectively.***
  • We also see what doesn’t work, and the list is stunning: Bollinger Bands, RSI, MAO, ROC.. a veritable who’s who of popular technical analysis indicators. What is going on here? Maybe, TA believers say, it is the ability to predict movements both up and down that is important.
  • To check this, use the STI and HSI “longshort daily” charts.
  • Here, shorting is enabled, and the results are even more stunning in Singapore. The rewards for following moving-average-based strategies INCREASE from 1.9 to 2.5 Sharpe. Moving average rules make money on BOTH the long and short legs, whereas all other technical indicators lose money on BOTH the long and short legs. Again, moving averages are better predictors of upward AND downward movement than Bollinger Bands, RSI, MAO, etc.
  • The story is a little different in Hong Kong: SMA Sharpe DECREASES from 1.93 to 0.97 (though EMA remains at 1.90) and generally the moving average indicators do not make money on the short legs. However they all still outperform all the other indicators, which lose most of their money on the short legs of their trading.
Okay, you say, those are the super active day traders, and we know those guys are losers long term (not really, if you use moving averages religiously). How bout monthly trading intervals (i.e. if I traded and looked at the technical indicators only once a month)?
  • STI and HSI “long monthly” charts.
  • Stunningly, we see a brilliant reversal. Moving Averages UNDERPERFORM other indicators and UNDERPERFORM Buy and Hold!!!
  • STI and HSI “longshort monthly” charts.
  • SAME RESULTS!!! In particular, Rex (The Rex Indicator), TE (Trading Envelopes), ROC (Rate of Change) and MAO (Moving Average Oscillator) do well in both HK and SG.
  • Surprisingly too, RSI and Bollinger bands are missing from the list of indicators that have performed well in both markets.
  • Sadly…
  • This would be an interesting result if not for the fact that Bloomberg’s BTST is a laughably neanderthal product for proper backtesting. The source of the problems is that the BTST strategy parameters do not adjust with the periodicity of the data. So my backtest of “SMAvg”, which was based on 50 days as a parameter, is now 50 months, or 4 years. However the other strategies’ parameters are less affected for some as yet unknown reason.
  • It is also worth noting that none of the strategies gain substantially much from being able to short, so they do not predict downturns well enough for us to use them for that purpose.
Conclusion
I began this study looking to disconfirm technical analysis (anything that isn’t moving averages, see footnote ^), and confirmed my suspicions in the daily timeframe, but was pleasantly surprised by the monthly result. It may be a good idea, going forward to calibrate monthly expectations using Rex, TE, ROC, and MAO, and then trade on a daily basis using moving averages.
Footnotes
^Please note that I do not personally consider moving averages as technical analysis as the momentum effect is well examined in academia and has achieved the status of scientific validation. However I include them here as most authors would list them as part of TA. I also include sentiment indicators, insider transactions, investor holdings information and so on under my mental category of technical analysis, but most authors do not classify them this way.
*For some unknown but surely annoying reason Bbg does not allow daily backtests further than 5 years. However, this is an improvement over no backtesting at all.
** Short of sitting down a few hundred technical analysts to look at charts as they move through time without telling them what stock and what time period they are looking at… Now THERE’s a great  idea for a lab experiment!
*** It is quite accurate to say that all forms of moving averages are just linear combinations of the simple moving average at different speeds. I can state this in terms of pseudomathematical proof. For example, the 5 day EMA is simply x1 times the 5 day SMA + x2 times the 4 day SMA + … + x5 times the 1 day SMA where x1 + x2 + … + x5 = 1 and xi is determined by your choice of exponential parameter. Thus if fast SMAs work better than slow SMAs, then any given X-day EMA will work better than its corresponding X-day SMA. If fast works poorer than slow, then EMA will underperform SMA. (Upon inspection, the DMI indcator that does so well in the HSI appears mathematically similar to the moving averages, but I won’t bother proving this.)

Market Mean Reversion (ft. a 20 Sharpe Strategy?) - Student's Post

Taken from http://processdriventrading.wordpress.com/page/2/
Picking up from where I left off on my previous post on this topic, I have completed the backtesting of the Andy Lo strategy on survivorship-bias-free data collected right from the most direct source possible. I will let the results speak for themselves:

We see a Sharpe Ratio of ~7. This is pretty good, but the big jump 3 weeks in to 2011 leads us to suspect that there may be some kind of big reversal at some future point. Since survivorship-free data does not exist before 2011, we are forced to wait to collect this information.
What is interesting is that Khandani and Lo predict this strategy will do much better for illiquid stocks. Here is the same strategy on the 100+ stocks on Catalist:
Observe not only is the equity line smoother, but the average return to this strategy is also more than twice that of the one on the Mainboard. Annualizing these returns would indicate that one could get a market-neutral >90% profit every year, unleveraged. The annual risk (stdev) from this strategy would only be ~5%, so the return would be much higher if this strategy was scaled up to the same risk as the market.
Ok.. so what?
This is plainly ridiculous and if it sounds too good to be true, it probably is, but for a very legitimate reason – the difficulty of shorting. The strategy involves going short stocks that outperformed the simple market average and vice versa in order to maintain its market neutrality.
However we can also simulate a long-only version of this strategy by setting all negative weights to zero. This is what we get:

Sharpe actually improves for the Mainboard stocks, and declines but remains at an acceptable 13.4 on the Catalist. Notice also that cumulative profits are approximately halved, allowing the correct inference that the profits from this strategy are equally strong on both the long and short legs.
The money is there, if you want it enough.
Related Posts Plugin for WordPress, Blogger...