Overall Statistics
Total Trades
694
Average Win
0.57%
Average Loss
-1.72%
Compounding Annual Return
5.198%
Drawdown
47.500%
Expectancy
0.139
Net Profit
198.673%
Sharpe Ratio
0.377
Probabilistic Sharpe Ratio
0.063%
Loss Rate
15%
Win Rate
85%
Profit-Loss Ratio
0.33
Alpha
0.057
Beta
-0.059
Annual Standard Deviation
0.141
Annual Variance
0.02
Information Ratio
-0.095
Tracking Error
0.233
Treynor Ratio
-0.898
Total Fees
$1189.17
Estimated Strategy Capacity
$5100000.00
Lowest Capacity Asset
GSG TKH7EPK7SRC5
# https://quantpedia.com/strategies/asset-class-momentum-rotational-system/
#
# Use 5 ETFs (SPY - US stocks, EFA - foreign stocks, IEF - bonds, VNQ - REITs, GSG - commodities).
# Pick 3 ETFs with strongest 12 month momentum into your portfolio and weight them equally. 
# Hold for 1 month and then rebalance.

class MomentumAssetAllocationStrategy(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2000, 1, 1)  
        self.SetCash(100000)
        
        self.data = {}
        period = 12 * 21
        self.SetWarmUp(period)
        self.symbols = ["SPY", "EFA", "IEF", "VNQ", "GSG"]

        for symbol in self.symbols:
            self.AddEquity(symbol, Resolution.Daily)
            self.data[symbol] = self.ROC(symbol, period, Resolution.Daily)

        self.Schedule.On(self.DateRules.MonthStart(self.symbols[0]), self.TimeRules.AfterMarketOpen(self.symbols[0]), self.Rebalance)
            
    def Rebalance(self):
        if self.IsWarmingUp: return
        
        sorted_by_momentum = sorted([x for x in self.data.items() if x[1].IsReady], key = lambda x: x[1].Current.Value, reverse = True)
        count = 3
        long = [x[0] for x in sorted_by_momentum][:count]

        invested = [x.Key.Value for x in self.Portfolio if x.Value.Invested]
        for symbol in invested:
            if symbol not in long:
                self.Liquidate(symbol)

        for symbol in long:
            self.SetHoldings(symbol, 1 / len(long))