Overall Statistics |
Total Trades 3291 Average Win 0.17% Average Loss 0.00% Compounding Annual Return 1.139% Drawdown 33.800% Expectancy 0.650 Net Profit 1.707% Sharpe Ratio 0.184 Probabilistic Sharpe Ratio 15.864% Loss Rate 98% Win Rate 2% Profit-Loss Ratio 92.62 Alpha -0.166 Beta 0.976 Annual Standard Deviation 0.276 Annual Variance 0.076 Information Ratio -4.417 Tracking Error 0.039 Treynor Ratio 0.052 Total Fees $5522.48 |
from enum import Enum class UncoupledQuantumCoil(QCAlgorithm): def Initialize(self): self.SetStartDate(2019, 2, 9) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.symbol = self.AddEquity('SPY', Resolution.Minute).Symbol self.sma = self.SMA(self.symbol, 20, Resolution.Minute) self.sma.Updated += self.UpdateSmaWin self.sma_win = RollingWindow[float](2) self.close_win = RollingWindow[float](2) self.state = State.TO_BUY def UpdateSmaWin(self, sender, updated): if self.sma.IsReady: self.sma_win.Add(self.sma.Current.Value) def OnData(self, data): if data.ContainsKey(self.symbol) and data[self.symbol] is not None: self.close_win.Add(data[self.symbol].Close) if self.state == State.TO_BUY: if self.CheckSignal(): self.state = State.BUY_SUBMITTED self.SetHoldings(self.symbol, 1) def CheckSignal(self): if not self.sma_win.IsReady or not self.close_win.IsReady: return False if self.close_win[1] < self.sma_win[1] and self.close_win[0] > self.sma_win[0]: return True else: return False def OnOrderEvent(self, orderEvent): self.Debug('OnOrderEvent') if orderEvent.Status == OrderStatus.Filled: if self.state == State.BUY_SUBMITTED: sell_num = self.Portfolio[self.symbol].Quantity sell_price = self.Portfolio[self.symbol].Price self.LimitOrder(self.symbol, -sell_num, sell_price + .01) self.state = State.SELL_SUBMITTED elif self.state == State.SELL_SUBMITTED: self.state = State.TO_BUY class State(Enum): TO_BUY = 0 BUY_SUBMITTED = 1 SELL_SUBMITTED = 2