Overall Statistics Total Trades 11152 Average Win 0.07% Average Loss -0.13% Compounding Annual Return 5.729% Drawdown 29.200% Expectancy 0.127 Net Profit 161.817% Sharpe Ratio 0.529 Probabilistic Sharpe Ratio 1.413% Loss Rate 25% Win Rate 75% Profit-Loss Ratio 0.50 Alpha 0.053 Beta -0.007 Annual Standard Deviation 0.098 Annual Variance 0.01 Information Ratio -0.176 Tracking Error 0.199 Treynor Ratio -7.869 Total Fees \$16612.40
# https://quantpedia.com/Screener/Details/1
# 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.

import numpy as np
from datetime import datetime

class BasicTemplateAlgorithm(QCAlgorithm):

def Initialize(self):

self.SetStartDate(2003, 1, 1)
self.SetEndDate(datetime.now())
self.SetCash(100000)
self.data = {}
period = 10*21
self.SetWarmUp(period)
self.symbols = ["SPY", "EFA", "IEF", "VNQ", "GSG"]
for symbol in self.symbols:
self.data[symbol] = self.SMA(symbol, period, Resolution.Daily)

def OnData(self, data):
if self.IsWarmingUp: return
isUptrend = []
for symbol, sma in self.data.items():
if self.Securities[symbol].Price > sma.Current.Value:
isUptrend.append(symbol)
else:
self.Liquidate(symbol)

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