Overall Statistics
Total Trades
10770
Average Win
0.08%
Average Loss
-0.15%
Compounding Annual Return
3.777%
Drawdown
29.200%
Expectancy
0.095
Net Profit
114.822%
Sharpe Ratio
0.363
Probabilistic Sharpe Ratio
0.069%
Loss Rate
28%
Win Rate
72%
Profit-Loss Ratio
0.52
Alpha
0.036
Beta
0
Annual Standard Deviation
0.1
Annual Variance
0.01
Information Ratio
-0.148
Tracking Error
0.204
Treynor Ratio
86.284
Total Fees
$15279.59
# 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))