Overall Statistics |
Total Trades 7 Average Win 1.01% Average Loss 0% Compounding Annual Return 18.198% Drawdown 6.600% Expectancy 0 Net Profit 3.717% Sharpe Ratio 1.407 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha -0.106 Beta 0.84 Annual Standard Deviation 0.122 Annual Variance 0.015 Information Ratio -2.64 Tracking Error 0.06 Treynor Ratio 0.204 Total Fees $23.30 |
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): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.SetStartDate(2013,05,1) #Set Start Date self.SetEndDate(2013,07,19) self.SetCash(100000) #Set Strategy Cash # Find more symbols here: http://quantconnect.com/data 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), 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 openOrders = self.Transactions.GetOpenOrders() currBar = self.window[0].Close yesterdayc = self.daily[1].Close minuteBarC = self.minute[1].Close minuteBar0 = self.minute[1].Open self.Debug(str(self.Securities["SPY"].Price) + "," + str(currBar)+str(minuteBar0)+str(minuteBarC)) if not self.Portfolio.Invested and currBar<yesterdayc and minuteBar0<minuteBarC and "SPY" not in openOrders: self.SetHoldings("SPY", 1) # Add second bar to window rolling window def OnData(self, data): if data["SPY"] is None: return self.window.Add(data["SPY"]) if not (self.window.IsReady): return self.Debug("haha") factor = d.Decimal(1.01) currBar = self.window[0].Close if self.Portfolio["SPY"].AveragePrice *factor< currBar: self.SetHoldings("SPY", 0)