Overall Statistics |
Total Trades 6 Average Win 1.37% Average Loss -2.01% Compounding Annual Return -0.757% Drawdown 7.400% Expectancy -0.159 Net Profit -0.162% Sharpe Ratio -0.013 Loss Rate 50% Win Rate 50% Profit-Loss Ratio 0.68 Alpha -0.047 Beta 0.669 Annual Standard Deviation 0.111 Annual Variance 0.012 Information Ratio -0.766 Tracking Error 0.09 Treynor Ratio -0.002 Total Fees $17.60 |
from QuantConnect.Data.Market import TradeBar from datetime import timedelta from System import * from QuantConnect import * from QuantConnect.Algorithm import * from QuantConnect.Indicators import * import decimal as d class MyAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2015,05,1) #Set Start Date self.SetEndDate(2015,07,19) self.SetCash(100000) #Set Strategy Cash self.AddEquity("SPY", Resolution.Second) consolidator = TradeBarConsolidator(timedelta(1)) consolidator.DataConsolidated += self.OnDailyData self.SubscriptionManager.AddConsolidator("SPY", consolidator) consolidatorm = TradeBarConsolidator(60) consolidatorm.DataConsolidated += self.OnMinuteData self.SubscriptionManager.AddConsolidator("SPY", consolidatorm) self.daily = RollingWindow[TradeBar](2) self.minute = RollingWindow[TradeBar](2) self.window = RollingWindow[TradeBar](2) self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(9, 31, 01), Action(self.One)) # Add daily bar to daily rolling window def OnDailyData(self, sender, bar): self.daily.Add(bar) def OnMinuteData(self, sender, bar): self.minute.Add(bar) def One(self): if not (self.window.IsReady and self.daily.IsReady and self.minute.IsReady): return currBar = self.window[0].Close yesterdayClose = self.daily[0].Close minuteBarClose = self.minute[0].Close minuteBarOpen = self.minute[0].Open if not self.Portfolio.Invested and currBar < yesterdayClose and minuteBarOpen < minuteBarClose: self.SetHoldings("SPY", 1) if not self.Portfolio.Invested and currBar > yesterdayClose and minuteBarOpen > minuteBarClose: self.SetHoldings("SPY", -1) def OnData(self, data): if data["SPY"] is None: return self.window.Add(data["SPY"]) if not (self.window.IsReady): return factor = d.Decimal(1.01) currBar = self.window[0].Close if self.Portfolio["SPY"].AveragePrice *factor< currBar: self.SetHoldings("SPY", 0)