good afternoon!
I would like to make a momentum portfolio from 1998 to 2020 from US stocks (SP500 or nasdaq)
backtest rules
1 if sma 160 (spy) is above the spy, then turn on the risk on mode it
in risk on mode, we selects the 20 stocks that performed best in the last 40 days of trading (in equal proportions)
stocks with capitalization above $ 2 billion
2 if sma 160 (spy) is below the spy, then go to defense - tlt
we trade once two months
please help with backtesting!
P.S. in the backtest I indicated how you can collect a set of shares for selection