Yield Inversion Curve Strategy (Amibroker Strategy)

The original article can be found here.

Backtest no.1:

  • When the yield curve gets inverted (ie crossing below zero), we buy S&P 500.
  • We sell 250 trading days later.

Amibroker code:

Fremmed=Foreign("^TNX","close",fixup=1);
FremmedTo=Foreign("2_year_yield","close",fixup=1);
Yield_Inversion = Fremmed - FremmedTo; 

Plot(Yield_Inversion,"Yield Curve",colorRed,styleLine);

oddis=Optimize("N-Day return",250,25,250,10);

buy= Cross(0,Yield_Inversion) ;
BuyPrice=Close;
Sell= C>0 ;
sellPrice= Close;

ApplyStop(stopTypeNBar,stopModeBars,oddis,1) ;

Backtest no.2:

  • When the 5-day RSI of the yield curve (2-year yield minus the 10-year yield) is below 20, we buy S&P 500.
  • We sell when the 5-day RSI turns above 80.

Amibroker code:

Fremmed=Foreign("^TNX","close",fixup=1);
FremmedTo=Foreign("2_year_yield","close",fixup=1);

pair = FremmedTo/fremmed ;
Yield_Inversion = Fremmed - FremmedTo; 
RSIpair=RSIa(Yield_Inversion,5);


buy= RSIpair<20 ;
BuyPrice=Close;
Sell= RSIpair>80;
sellPrice= Close;