Overall Statistics |
Total Trades 66 Average Win 0.04% Average Loss -0.04% Compounding Annual Return 1.039% Drawdown 0.200% Expectancy 0.357 Net Profit 0.428% Sharpe Ratio 2.263 Loss Rate 39% Win Rate 61% Profit-Loss Ratio 1.24 Alpha 0.024 Beta -0.692 Annual Standard Deviation 0.005 Annual Variance 0 Information Ratio -2.017 Tracking Error 0.005 Treynor Ratio -0.015 Total Fees $66.00 |
from datetime import timedelta class Algorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2019, 1, 1) self.SetEndDate(2019, 5, 31) self.SetCash(100000) self.syl = 'SPY' self.equity = self.AddEquity(self.syl, Resolution.Minute) #equity.SetDataNormalizationMode(DataNormalizationMode.Raw) #self.SetBenchmark(self.equity.Symbol) self.PrevClose = None self.Schedule.On(self.DateRules.EveryDay("SPY"), \ self.TimeRules.BeforeMarketClose("SPY", 45), \ Action(self.Open)) self.Schedule.On(self.DateRules.EveryDay("SPY"), \ self.TimeRules.BeforeMarketClose("SPY", 5), \ Action(self.Close)) self.Schedule.On(self.DateRules.EveryDay("SPY"), \ self.TimeRules.BeforeMarketClose("SPY", 0), \ Action(self.Update)) def Open(self): if self.UtcTime.weekday()==4: self.Log(self.UtcTime) return if self.PrevClose != None: if (self.equity.Price - self.PrevClose)/self.PrevClose > 0.005: self.MarketOrder(self.equity.Symbol, -100) self.StopMarketOrder(self.equity.Symbol, 100, self.equity.Price*1.002) return elif (self.equity.Price - self.PrevClose)/self.PrevClose < -0.005: self.MarketOrder(self.equity.Symbol, 100) self.StopMarketOrder(self.equity.Symbol, -100, self.equity.Price*0.998) return def Close(self): self.Liquidate() openOrders = self.Transactions.GetOpenOrders() if len(openOrders) > 0: for x in openOrders: self.Transactions.CancelOrder(x.Id) self.Log(str(x.Id) + " cancelled") def Update(self): self.PrevClose = self.equity.Price def OnData(self,data): self.data = data pass