Overall Statistics
Total Trades
131
Average Win
8.39%
Average Loss
-4.37%
Compounding Annual Return
19.231%
Drawdown
39.100%
Expectancy
1.058
Net Profit
387.428%
Sharpe Ratio
0.761
Probabilistic Sharpe Ratio
16.194%
Loss Rate
30%
Win Rate
70%
Profit-Loss Ratio
1.92
Alpha
0.205
Beta
-0.1
Annual Standard Deviation
0.256
Annual Variance
0.065
Information Ratio
0.304
Tracking Error
0.296
Treynor Ratio
-1.94
Total Fees
$1634.55
from datetime import datetime
from collections import *


class DualMomentumGem(QCAlgorithm):
    def Initialize(self):
        self.SetBenchmark("SPY")
        self.SetStartDate(2010, 1, 1)  # Set Start Date
        self.SetEndDate(2019, 1, 1)    # Set Start Date       
        self.SetCash(100000)           # Set Strategy Cash
        self.bonds = self.AddEquity("AGG", Resolution.Daily).Symbol
        self.lookBackPeriod = 100
        #create symbol data for US (SPY), EU (EFA) and emerging market (EEM) ETFs
        self.symbolObjects = [SymbolData(self,symbolString, self.lookBackPeriod) for symbolString in ["SPY","EFA","EEM"]]
        self.tBill = SymbolData(self,"SHV", self.lookBackPeriod)
        self.Schedule.On(self.DateRules.MonthStart(self.symbolObjects[0].Symbol),self.TimeRules.AfterMarketOpen(self.symbolObjects[0].Symbol), 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)