Overall Statistics
Total Trades
278
Average Win
4.50%
Average Loss
-2.63%
Compounding Annual Return
19.560%
Drawdown
42.900%
Expectancy
0.566
Net Profit
574.196%
Sharpe Ratio
0.668
Probabilistic Sharpe Ratio
11.908%
Loss Rate
42%
Win Rate
58%
Profit-Loss Ratio
1.71
Alpha
0.191
Beta
-0.038
Annual Standard Deviation
0.279
Annual Variance
0.078
Information Ratio
0.213
Tracking Error
0.312
Treynor Ratio
-4.936
Total Fees
$10206.98
class LeverageForTheLongRun(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2009,6, 1)  #Set Start Date
        self.SetEndDate(2020,2,2)    #Set End Date
        self.SetCash(100000)           #Set Strategy Cash
        self.spy = self.AddEquity("SPY", Resolution.Daily)
        self.upro = self.AddEquity("UPRO", Resolution.Daily)
        self.agg = self.AddEquity("AGG", Resolution.Daily)
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
        self.sma = self.SMA("SPY", 40)
        
        # Create weekly consolidator
        consolidator =self.Consolidate("SPY", CalendarType.Weekly, self.OnDataConsolidated)
        
        # Register the SMA to use weekly consolidator.
        self.RegisterIndicator("SPY", self.sma, consolidator)
        
        # warm up the indicators
        self.SetWarmUp(40)
    
    # define the Weekly Trade bar for SPY from Initialize
    def OnDataConsolidated(self, bar):
        self.CurrentBar = bar
        
        if self.CurrentBar.Close > self.sma.Current.Value:
            self.SetHoldings("AGG", 0)
            self.SetHoldings("UPRO", 1)
            
        if self.CurrentBar.Close < self.sma.Current.Value:
            self.SetHoldings("UPRO", 0)
            self.SetHoldings("AGG", 1)