| Overall Statistics |
|
Total Trades 123 Average Win 5.06% Average Loss -2.89% Compounding Annual Return 17.314% Drawdown 23.200% Expectancy 0.851 Net Profit 484.594% Sharpe Ratio 1.02 Probabilistic Sharpe Ratio 42.735% Loss Rate 33% Win Rate 67% Profit-Loss Ratio 1.75 Alpha 0.147 Beta 0.053 Annual Standard Deviation 0.15 Annual Variance 0.023 Information Ratio 0.104 Tracking Error 0.211 Treynor Ratio 2.881 Total Fees $1272.86 |
# https://quantpedia.com/Screener/Details/3
# Use 10 sector ETFs. Pick 3 ETFs with strongest 12 month momentum into your portfolio
# and weigh them equally. Hold for 1 month and then rebalance.
import pandas as pd
from datetime import datetime
class SectorMomentumAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010, 2, 1)
self.SetEndDate(datetime.now())
self.SetCash(100000)
self.SetBenchmark('SPY')
# create a dictionary to store momentum indicators for all symbols
self.data = {}
period = 3*21
# choose ten sector ETFs
self.symbols = ['SPY','TLT','QQQ','VO','IWM','EEM']
# warm up the MOM indicator
self.SetWarmUp(period)
for symbol in self.symbols:
self.AddEquity(symbol, Resolution.Daily)
self.data[symbol] = self.MOM(symbol, period, Resolution.Daily)
# schedule the function to fire at the month start
self.Schedule.On(self.DateRules.MonthStart("SPY"), self.TimeRules.AfterMarketOpen("SPY"), self.Rebalance)
def OnData(self, data):
pass
def Rebalance(self):
if self.IsWarmingUp: return
top1 = pd.Series(self.data).sort_values(ascending = False)[:1]
for kvp in self.Portfolio:
security_hold = kvp.Value
# liquidate the security which is no longer in the top3 momentum list
if security_hold.Invested and (security_hold.Symbol.Value not in top1.index):
self.Liquidate(security_hold.Symbol)
for symbol in top1.index:
# self.SetHoldings(symbol, 1/len(top3))
self.SetHoldings(symbol, 1)