Dual Momentum Rotation Code

Hi - I am trying to work out how to code a Dual Momentum system that I have read about.

The system comes from a book - Dual Momentum Investing by Gary Antonacci. I highly recommend getting it because of it's strong rotational system performance.

In it he describes a monthly rotation that uses a previous 12month ROC as the positionscore, and buys the strongest performing ETF, as long as that ETF is performing better than T-Bills.

So I have a watchlist of:

SPY
VEU
some other SPDR select ETFs, such as XLY, XLU...
BIL (SPDR Bloomberg Barclays 1-3 Month T-Bill ETF)
and TLT

SetBacktestMode( backtestRotational );
SetOption("WorstRankHeld",1);
SetOption("MaxOpenPositions", 1);

BuyPrice = Closearray;
SellPrice = Closearray;
SetTradeDelays(0,0,0,0);  

mn = Month();
monthendflag = mn != Ref(mn,-1);

PositionScore = IIf(monthendflag, BIT BELOW, scorenoRotate);

Where I am confused is how to do positionScore for this system.

  • Calculate the 12-month returns for both SPY, VEU, XLP and XLU. Choose the ETF that has performed better.
  • Compare the best performing ETF to the returns of BIL. If the best performing ETF has performed better than BIL, then buy that ETF (either SPY, VEU, XLP, XLU....).
  • If BIL has performed better, then buy TLT.
    -Repeat steps 1 – 3 at the end of each month and replace one of the three ETFs with the strongest performing asset. ---> this step I know how to do.

Any help much appreciated. Thank you.

Move SPY, VEU, XLP, XLU and TLT to a WL.

SetBacktestMode( backtestRotational );
SetOption("WorstRankHeld",1);
SetOption("MaxOpenPositions", 1);
SetTradeDelays(0,0,0,0); 

BuyPrice = C;
SellPrice = C;	

mn = Month();
monthendflag = mn != Ref(mn,-1);

ROC_BIL = ROC(Foreign("BIL","C"), 12 );

if ( Name() == "TLT" )
	Score = ROC_BIL;
else 
	Score = ROC(C, 12);

PositionScore = IIf(monthendflag, 10000+Score, scorenoRotate);
5 Likes

Thanks fxshrat. The man with the plan as always :smiley:

1 Like

5 Likes

BTW, Setradedelays and buyprice/sellprice can be removed because:

Important:
The rotational trading mode uses "buy price" and "buy delay" from the Settings Trade page as trade price and delay for both entries and exits (long and short)

SetBacktestMode( backtestRotational );
SetOption("WorstRankHeld",1);
SetOption("MaxOpenPositions", 1);

mn = Month();
monthendflag = mn != Ref(mn,-1);

period = 250;

ROC_BIL = ROC(Foreign("BIL","C"), period);

if ( Name() == "TLT" )
	Score = ROC_BIL;
else 
	Score = ROC(C, period);

PositionScore = IIf(monthendflag, 10000+Score, scoreNoRotate);

2 Likes

LOL good old Hannibal :slight_smile:

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.