Overall Statistics
Total Trades
88
Average Win
2.78%
Average Loss
-1.43%
Compounding Annual Return
3.644%
Drawdown
20.100%
Expectancy
0.192
Net Profit
11.336%
Sharpe Ratio
0.323
Loss Rate
60%
Win Rate
40%
Profit-Loss Ratio
1.94
Alpha
0.048
Beta
0.166
Annual Standard Deviation
0.137
Annual Variance
0.019
Information Ratio
0.249
Tracking Error
0.277
Treynor Ratio
0.266
Total Fees
$88.00
class MomentumBasedTacticalAllocation(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2007, 8, 1) 
        self.SetEndDate(2010, 8, 1) 
        self.SetCash(3000)   
        
        self.spy = self.AddEquity("SPY", Resolution.Daily)  
        self.bnd = self.AddEquity("BND", Resolution.Daily)  
        
        self.spyMomentum = self.MOMP("SPY", 50, Resolution.Daily)
        self.bondMomentum = self.MOMP("BND", 50, Resolution.Daily) 
        
        self.SetBenchmark("SPY")  
        self.SetWarmUp(50) 
        
    def OnData(self, data):
        
        # Don't place trades until our indicators are warmed up:
        if self.IsWarmingUp:
            return
        
        #1. If SPY has more upward momentum than BND, then we liquidate our holdings in BND and allocate 100% of our equity to SPY
        if self.spyMomentum.Current.Value > self.bondMomentum.Current.Value:
            self.Liquidate("BND")
            self.SetHoldings("SPY", 1)

        #2. Otherwise we liquidate our holdings in SPY and allocate 100% to BND
        else:
            self.Liquidate("SPY")
            self.SetHoldings("BND", 1)