Overall Statistics |
Total Trades 389 Average Win 3.07% Average Loss -0.84% Compounding Annual Return 17.037% Drawdown 9.000% Expectancy 0.506 Net Profit 119.753% Sharpe Ratio 1.355 Probabilistic Sharpe Ratio 77.712% Loss Rate 68% Win Rate 32% Profit-Loss Ratio 3.64 Alpha 0.088 Beta 0.291 Annual Standard Deviation 0.087 Annual Variance 0.008 Information Ratio 0.111 Tracking Error 0.138 Treynor Ratio 0.405 Total Fees $977.66 Estimated Strategy Capacity $28000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
# SPY Bollinger Band LE with Stop Loss and Take Profit # ------------------------------------------------------------------- STOCK = "SPY"; BAR = 60; BB = 40; MULT = 0.5; SL = -0.005; TP = 0.03; # ------------------------------------------------------------------- class MeasuredRedOrangeChicken(QCAlgorithm): def Initialize(self): self.SetStartDate(2017, 6, 1) self.SetEndDate(2022, 6, 1) self.SetCash(100000) res = Resolution.Minute self.stock = self.AddEquity(STOCK, res).Symbol consolidator = TradeBarConsolidator(timedelta(minutes = BAR)) self.Consolidate(self.stock, timedelta(minutes = BAR), self.BarHandler) self.bb = BollingerBands(BB, MULT, MovingAverageType.Exponential) self.RegisterIndicator(self.stock, self.bb, consolidator) self.SetWarmUp(5*BAR*BB, res) def BarHandler(self, consolidated): if self.IsWarmingUp: return if not self.bb.IsReady: return price = self.Securities[self.stock].Price pnl = self.Securities[self.stock].Holdings.UnrealizedProfitPercent if not self.Portfolio[self.stock].Invested: if price > self.bb.UpperBand.Current.Value: self.SetHoldings(self.stock, 1, False, "Over UB") elif self.Portfolio[self.stock].Invested: if pnl < SL: self.Liquidate(self.stock, "Stop Loss") elif pnl > TP: self.Liquidate(self.stock, "Take Profit")