Monday, January 22, 2018

BackTest on MACD, KDJ, and RSI

MACD, KDJ, and RSI are three powerful technical indices. These indices are widely used to reflect trend, especially reversal trend.

Simply speaking, when one of these indices is triggered, then:

  • An upward trend may reverse to a downward trend, OR,
  • A downward trend may reverse to an upward trend


The performance of those indices are more or less affected by the extraneous parameters (like the x in "highest price in x days"), but here we assume all of these parameters set to be generally accepted parameters.

To specify, here we assume that:

MACD:

Estimation Formula:
  • EMAS(t) = Exponential Moving Average of Price in Short Term (daily close price in 12 days)
  • EMAL(t) = Exponential Moving Average of Price in Long Term (daily close price 26 days)
  • DIF(t) = EMAS(t) - EMAL(t)
  • DEA(t) = Exponential Moving Average of DIF (in 9 days)
  • MACD(t) = [DIF(t) - DEA(t)] * 2
Strategy:
  • Long when MACD is negative and increasing
  • Short when MACD is positive and decreasing

KDJ:

Estimation Formula:
  • Low(t,9) = Lowest price in 9 days (date t-9 to t)
  • High(t,9) = Highest price in 9 days (date t-9 to t)
  • RSV(t) = (Close(t) - Low(t,9)) / (High(t,9) - Low(t,9))
  • K(t) = RSV(t)/3 + 2*K(t-1)/3
  • D(t) = K(t)/3 + 2*D(t-1)/3
  • J(t) = 3*K(t) - 2*D(t)

Strategy:
  • Long when J is <= 25 and increasing
  • Short when J is >= 75 and decreasing

RSI:

Estimation Formula:

  • MEANUP(t,12) = Mean of positive returns in the last 12 days
  • MEANDOWN(t,12) = Absolute value of the Mean of negative returns in the last 12 days
  • RS(t) = MEANUP(t,12)/MEANDOWN(t,12)
  • RSI(t) = 100 - 100 / [ 1+ RS(t) ]

Strategy:
  • Long when RSI is <= 40 and increasing
  • Short when RSI is >= 60 and decreasing

Backtest Results:

Ag: Silver/ Agrentum Futures, listed on Shanghai Futures Exchange, China

Profits & Loss:

MACD:

KDJ: 

RSI:

However, there is one BIG problem.

All of these indices, are highly sensitive to different underlying assets. Those performance that is beautiful in Ag, might be pretty bad in some others.

In fact, I have also tested all the other active 34 Futures Contracts listed in China (see in *1), and none of them performs similarly to Ag. Some of the three strategies are valid for some of them, while others may not:

It is possible that good results come from pure luck, not the effectiveness of strategy itself.

Therefore, single index should never be considered the sole best strategy. Like Alpha seeking, a better strategy may be effective when more financial instruments are taken into account.

By the way, one another thing may help: decrease the cycle of investments:

For example, in these examples (MACD/KDJ/RSI), all prices are updated upon daily basis. However, investing in such a long term is more like a fundamental analysis, which is basically too risky to quantitative investments: the max drawdown may be very drastic.

But, can we really transform it into smaller cycles?

I have changed my updating criteria, from daily to every 5 minute of market-time, and all the other variables remain the same.

For instance:

  • The highest price in 9 days now refers to the highest price in 9 5-minute-time, i.e., 45 minutes

Let's see the results:

Profits & Loss:

MACD:

KDJ:

RSI:

Surprise! (In fact, not very surprise to professionals)

A beautiful smooth downward curve! It strongly supports the idea that if we keep the status quo, then all the trends captured by daily cycle would soon disappear in a 5-minute cycle.

Therefore, in determining smaller cycles, we need to be more careful.

I will do some smaller cycle analysis and combining singular trend capturing strategies in the next time.

* 1 See the performance of all the other active Futures Contracts at:
https://drive.google.com/open?id=1V1GF93pYCEmxnfwPCxeOvzqCaUE8ilzU

* 2 For some reasons, Source Code and raw data is not applicable.

* 3 I have tested the precision of MACD, RSI and KDJ prediction of the trend tomorrow. They are mostly around 45%-48%. This seems to be very frustrating but the reality is the correct trend these indexes have captured can be those drastic trend and once captured successfully a large amount of profits can be realized.

No comments:

Post a Comment