Overall Statistics
Total Trades
10970
Average Win
0.08%
Average Loss
-0.14%
Compounding Annual Return
3.906%
Drawdown
27.300%
Expectancy
0.101
Net Profit
121.558%
Sharpe Ratio
0.374
Probabilistic Sharpe Ratio
0.080%
Loss Rate
28%
Win Rate
72%
Profit-Loss Ratio
0.52
Alpha
0.037
Beta
-0.001
Annual Standard Deviation
0.099
Annual Variance
0.01
Information Ratio
-0.142
Tracking Error
0.204
Treynor Ratio
-48.521
Total Fees
$15605.52
# https://quantpedia.com/strategies/asset-class-trend-following/
#
# Use 5 ETFs (SPY - US stocks, EFA - foreign stocks, IEF - bonds, VNQ - REITs, 
# GSG - commodities), equal weight the portfolio. Hold asset class ETF only when 
# it is over its 10 month Simple Moving Average, otherwise stay in cash.

class AssetClassTrendFollowing(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2000, 1, 1)  
        self.SetCash(100000)  
        
        self.data = {}
        period = 10 * 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.SMA(symbol, period, Resolution.Daily)

    def OnData(self, data):
        if self.IsWarmingUp: return

        long = [x[0] for x in self.data.items() if self.Securities.ContainsKey(x[0]) and self.Securities[x[0]].Price > x[1].Current.Value]
        
        # Trade execution.
        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))