Overall Statistics
Total Trades
7
Average Win
0%
Average Loss
-0.31%
Compounding Annual Return
-0.133%
Drawdown
23.700%
Expectancy
-1
Net Profit
-1.226%
Sharpe Ratio
0.026
Probabilistic Sharpe Ratio
0.053%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.002
Beta
-0.001
Annual Standard Deviation
0.081
Annual Variance
0.007
Information Ratio
-0.72
Tracking Error
0.158
Treynor Ratio
-1.546
Total Fees
$505.15
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("AGGG", Resolution.Daily).Symbol
        self.lookBackPeriod = 100
        self.US = self.AddEquity("SPY", Resolution.Daily).Symbol
        #create symbol data for US (IUSA), EU (IQQY) and emerging market (EUNM) ETFs
        self.symbolObjects = [SymbolData(self,symbolString, self.lookBackPeriod) for symbolString in ["IQQY","EUNM","IUSA"]]
        self.tBill = SymbolData(self,"IBCC", 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)