Overall Statistics
Total Trades
83
Average Win
8.10%
Average Loss
-3.95%
Compounding Annual Return
11.795%
Drawdown
24.900%
Expectancy
0.862
Net Profit
241.235%
Sharpe Ratio
0.737
Loss Rate
39%
Win Rate
61%
Profit-Loss Ratio
2.05
Alpha
0.1
Beta
1.185
Annual Standard Deviation
0.167
Annual Variance
0.028
Information Ratio
0.62
Tracking Error
0.167
Treynor Ratio
0.104
Total Fees
$1690.68
# https://quantpedia.com/Screener/Details/14
class DualMomentum(QCAlgorithm):

    def Initialize(self):

        self.SetStartDate(2008, 1, 1)  # Set Start Date
        self.SetEndDate(2019, 1, 1)    # Set Start Date       
        self.SetCash(100000)           # Set Strategy Cash
        self.UniverseSettings.Resolution = Resolution.Daily
        self.num_coarse = 100
        self.num_fine = 50
        self.us = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.worldExUS =  self.AddEquity("VEU", Resolution.Daily).Symbol
        self.tbill = self.AddEquity("SHV", Resolution.Daily).Symbol #SHY 
        self.agg = self.AddEquity("BND", Resolution.Daily).Symbol # AGG 
        self.leverage = 1.3
        self.Schedule.On(self.DateRules.MonthStart("SPY"),self.TimeRules.AfterMarketOpen("SPY"), self.rebalance)
        self.currentLong = self.us
        self.returnWindowLength = 100
   
    def Returns(self, symbol, period):
        closingBars = self.History(symbol, TimeSpan.FromDays(period),Resolution.Daily).close
        return (closingBars[-1] - closingBars[0])/closingBars[-1]
       
    def rebalance(self):
        if self.Returns(self.us,self.returnWindowLength) < self.Returns(self.tbill,self.returnWindowLength):
            self.currentLong =  self.agg
        elif self.Returns(self.us,self.returnWindowLength) > self.Returns(self.worldExUS,self.returnWindowLength):
            self.currentLong=self.us
        else:
            self.currentLong = self.worldExUS
        stocksInvested = [x.Key for x in self.Portfolio if x.Value.Invested]
        if not stocksInvested: 
            self.SetHoldings(self.currentLong, self.leverage)
        elif self.currentLong != stocksInvested[0]:
            self.SetHoldings(self.currentLong, self.leverage, True)


    def OnData(self, data):
        pass