Overall Statistics
Total Trades
139
Average Win
10.38%
Average Loss
-3.97%
Compounding Annual Return
24.150%
Drawdown
43.600%
Expectancy
1.295
Net Profit
640.363%
Sharpe Ratio
0.842
Probabilistic Sharpe Ratio
20.607%
Loss Rate
37%
Win Rate
63%
Profit-Loss Ratio
2.62
Alpha
0.262
Beta
-0.113
Annual Standard Deviation
0.295
Annual Variance
0.087
Information Ratio
0.401
Tracking Error
0.331
Treynor Ratio
-2.201
Total Fees
$2289.87
from datetime import datetime
from collections import *


class DualMomentumGem(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2010, 1, 1)  # Set Start Date
        self.SetEndDate(2019, 4, 1)    # Set Start Date       
        self.SetCash(100000)           # Set Strategy Cash
        self.bonds = self.AddEquity("AGG", Resolution.Daily).Symbol
        self.lookBackPeriod = 100
        self.US = self.AddEquity("SPY", Resolution.Daily).Symbol
        #create symbol data for US (QQQ), EU (EFA) and emerging market (EEM) ETFs
        self.symbolObjects = [SymbolData(self,symbolString, self.lookBackPeriod) for symbolString in ["QQQ","EFA","EEM"]]
        self.tBill = SymbolData(self,"SHV", self.lookBackPeriod)
        self.Schedule.On(self.DateRules.MonthStart(self.US),self.TimeRules.AfterMarketOpen(self.US), self.Rebalance)
        self.Portfolio.MarginCallModel = MarginCallModel.Null
        self.leverage = 2
        self.SetWarmUp(self.lookBackPeriod)
            
    def Rebalance(self):
        self.symbolObjects.sort(key=lambda symbolObject: symbolObject.Momentum.Current.Value, reverse=True)
        currentLong = self.symbolObjects[0].Symbol
        if self.symbolObjects[0].Momentum.Current.Value < self.tBill.Momentum.Current.Value:
            currentLong  = self.bonds
        self.SetHoldings(currentLong, self.leverage, True)
        
        
class SymbolData:
    '''Contains data specific to a symbol required by this model'''
    def __init__(self,algorithm, symbolString,lookBackPeriod):
        self.Symbol = algorithm.AddEquity(symbolString, Resolution.Daily).Symbol
        self.Momentum = algorithm.MOM(self.Symbol, lookBackPeriod, Resolution.Daily)