Rotation Strategy Between The S&P 500 And Gold Miners (Amibroker Code)
The strategy in plain English:
- At the close of September, we buy the S&P 500 (^gspc).
- We hold the S&P 500 until the last day of April.
- At the close of April, we invest in FSAGX.
- We own FSAGX until the last day of September
- Rinse and repeat every year from 1985 until June 2021.
Click here for the original article.
Amibroker code:
Here is the Amibroker code if we have many different stocks in the database. The code only test the tickers we want to test, we make an if function:
setOption(“MaxOpenPositions”,2);
SetPositionSize(49.75,spsPercentOfEquity);
f( Name() == “^gspc” )
{
Buy= Month()==10;
BuyPrice=Ref(Close,-1);
Sell=Month()==5 ;
SellPrice=Ref(Close,-1);
Short=0 ;
ShortPrice=0;
Cover=0 ;
CoverPrice=0;
}
if( Name() == “FSAGX” )
{
Buy= Month()==5;
BuyPrice=Ref(Close,-1);
Sell=Month()==10 ;
SellPrice=Ref(Close,-1);
Short=0 ;
ShortPrice=0;
Cover=0 ;
CoverPrice=0;
}
Disclosure: We are not financial advisors. Please do your own due diligence and investment research or consult a financial professional. All articles are our opinions – they are not suggestions to buy or sell any securities.
