Overall Statistics |
Total Trades 382 Average Win 0.67% Average Loss -0.47% Compounding Annual Return 13.295% Drawdown 11.600% Expectancy 0.485 Net Profit 61.665% Sharpe Ratio 1.064 Probabilistic Sharpe Ratio 51.556% Loss Rate 39% Win Rate 61% Profit-Loss Ratio 1.43 Alpha 0.041 Beta 0.392 Annual Standard Deviation 0.089 Annual Variance 0.008 Information Ratio -0.353 Tracking Error 0.12 Treynor Ratio 0.241 Total Fees $1109.31 Estimated Strategy Capacity $23000000.00 Lowest Capacity Asset BND TRO5ZARLX6JP |
# Price - Moving Average(4 Hour bar) Cross # ----------------------------------- STOCK = "SPY"; BOND = "BND"; MA = 20; # ----------------------------------- class PMAC_FourHourBar(QCAlgorithm): def Initialize(self): self.SetStartDate(2018, 1, 1) self.SetEndDate(2021, 11, 5) self.SetCash(100000) self.stock = self.AddEquity(STOCK, Resolution.Hour).Symbol self.bond = self.AddEquity(BOND, Resolution.Hour).Symbol consolidator = TradeBarConsolidator(timedelta(hours = 4)) self.SubscriptionManager.AddConsolidator(self.stock, consolidator) self.sma = SimpleMovingAverage(MA) self.RegisterIndicator(self.stock, self.sma, consolidator) self.SetWarmUp(MA, Resolution.Hour) self.uptrend = 0 def OnData(self, data): if not(self.Time.time() == time(10) or self.Time.time() == time(14)): return if self.IsWarmingUp:return if not self.sma.IsReady or self.stock not in data or self.bond not in data: return if data[self.stock].Price >= self.sma.Current.Value and not self.uptrend: self.SetHoldings(self.stock, 0.8) self.SetHoldings(self.bond, 0.2) self.uptrend = 1 elif data[self.stock].Price < self.sma.Current.Value and self.uptrend: self.SetHoldings(self.stock, 0.2) self.SetHoldings(self.bond, 0.8) self.uptrend = 0 self.Plot("Benchmark", "SMA", self.sma.Current.Value)