Overall Statistics |
Total Trades 83 Average Win 8.38% Average Loss -3.75% Compounding Annual Return 9.871% Drawdown 19.200% Expectancy 0.859 Net Profit 271.257% Sharpe Ratio 0.662 Probabilistic Sharpe Ratio 6.598% Loss Rate 42% Win Rate 58% Profit-Loss Ratio 2.23 Alpha 0.087 Beta 0.039 Annual Standard Deviation 0.137 Annual Variance 0.019 Information Ratio -0.014 Tracking Error 0.224 Treynor Ratio 2.302 Total Fees $83.00 |
class MomentumBasedTacticalAllocation(QCAlgorithm): def Initialize(self): self.SetStartDate(2007, 1,1) self.SetEndDate(2020,12,1) self.SetCash(3000) self.spy = self.AddEquity("SPY", Resolution.Daily) self.bnd = self.AddEquity("TLT", Resolution.Daily) self.eem = self.AddEquity("EEM",Resolution.Daily) self.spyMomentum30 = self.MOMP("SPY", 30, Resolution.Daily) self.spyMomentum60 = self.MOMP("SPY", 60, Resolution.Daily) self.spyMomentum90 = self.MOMP("SPY", 90, Resolution.Daily) self.bondMomentum30 = self.MOMP("TLT", 30, Resolution.Daily) self.bondMomentum60 = self.MOMP("TLT", 60, Resolution.Daily) self.bondMomentum90 = self.MOMP("TLT", 90, Resolution.Daily) self.eemMomentum30 = self.MOMP("EEM", 30, Resolution.Daily) self.eemMomentum60 = self.MOMP("EEM", 60, Resolution.Daily) self.eemMomentum90 = self.MOMP("EEM", 90, Resolution.Daily) self.SetBenchmark(self.spy.Symbol) self.SetWarmUp(90) self.last_month = -1 def OnData(self, data): spyavg = (self.spyMomentum30.Current.Value+self.spyMomentum60.Current.Value+self.spyMomentum90.Current.Value)/3 bndavg = (self.bondMomentum30.Current.Value+self.bondMomentum60.Current.Value+self.bondMomentum90.Current.Value)/3 eemavg = (self.eemMomentum30.Current.Value+self.eemMomentum60.Current.Value+self.eemMomentum90.Current.Value)/3 if self.IsWarmingUp: return #1. Limit trading to happen once per month if self.Time.month == self.last_month: return if spyavg > eemavg > bndavg: self.Liquidate("TLT") self.Liquidate("EEM") self.SetHoldings("SPY", 1) else: if eemavg > spyavg > bndavg: self.Liquidate("TLT") self.Liquidate("EEM") self.SetHoldings("SPY", 1) else: self.Liquidate("SPY") self.Liquidate("EEM") self.SetHoldings("TLT", 1) self.last_month = self.Time.month return