Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -0.975 Tracking Error 0.161 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
class MinimalExample(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 5, 5) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.spy = self.AddEquity("SPY", Resolution.Minute) self.window = RollingWindow[TradeBar](5) resolutionInTimeSpan = Extensions.ToTimeSpan(Resolution.Daily) self.consolidator = TradeBarConsolidator(timedelta(1)) self.consolidator.DataConsolidated += self.OnDataConsolidated self.SubscriptionManager.AddConsolidator(self.spy.Symbol, self.consolidator) self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose("SPY", 1), self.ClosingBar) self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SPY", 2), self.OpeningBar) def OnDataConsolidated(self, sender, bar): self.window.Add(bar) def ClosingBar(self): self.Log(f"##### Close {self.Time}") if self.Portfolio.Invested: self.Liquidate() def LogBar(self, bar): return f"O: {bar.Open}, H: {bar.High}, L: {bar.Low}, C: {bar.Close}, V: {bar.Volume}" def OpeningBar(self): self.Log(f"##### Open {self.Time}") if self.window.IsReady: current_price = self.Securities[self.spy.Symbol].Price self.Log(f"{self.Time}: Open@{current_price}") self.Log(f"D-1 {self.window[0].Time} - {self.window[0].EndTime}: {self.LogBar(self.window[0])}") self.Log(f"D-2 {self.window[1].Time} - {self.window[1].EndTime}: {self.LogBar(self.window[1])}")