Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return -24.579% Drawdown 5.600% Expectancy 0 Net Profit -0.360% Sharpe Ratio -0.872 Probabilistic Sharpe Ratio 41.818% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.462 Beta 1.71 Annual Standard Deviation 0.217 Annual Variance 0.047 Information Ratio 2.058 Tracking Error 0.093 Treynor Ratio -0.111 Total Fees $1.00 Estimated Strategy Capacity $3400000.00 Lowest Capacity Asset AAPL Y3LLKB7Q6QKM|AAPL R735QTJ8XC9X |
from AlgorithmImports import * # endregion class EnergeticYellowGreenFalcon(QCAlgorithm): def Initialize(self): # INITIALIZE self.SetStartDate(2022, 11, 12) # Set Start Date self.SetEndDate(2022, 11, 16) self.SetCash(10000) # Set Strategy Cash self.symbol = self.AddEquity('AAPL', Resolution.Minute) self.symbol.SetDataNormalizationMode(DataNormalizationMode.SplitAdjusted) option = self.AddOption("AAPL") self.option_symbol = option.Symbol self.SetSecurityInitializer(self.SecurityInitializer) # # SCHEDULED EVENTS self.Schedule.On(self.DateRules.EveryDay(self.symbol.Symbol), self.TimeRules.AfterMarketOpen(self.symbol.Symbol, 1), self.DayStart) self.Schedule.On(self.DateRules.EveryDay(self.symbol.Symbol), self.TimeRules.BeforeMarketClose(self.symbol.Symbol, 2), self.ParabolicCheck) self.Schedule.On(self.DateRules.EveryDay(self.symbol.Symbol), self.TimeRules.BeforeMarketClose(self.symbol.Symbol, 1), self.LiquidateCheck) self.Schedule.On(self.DateRules.EveryDay(self.symbol.Symbol), self.TimeRules.BeforeMarketClose(self.symbol.Symbol), self.DayEnd) # TOGGLES self.trading = False self.gap_up = False self.gap_down = False self.long = False self.short = False self.liquidate_toggle = False self.invest_daily = False self.daily_trigger = False self.invest_daily_s = False self.daily_trigger_s = False self.second_trade = False self.trail_stop = False self.trail_stop_s = False self.initial_day_stop_sell = False self.initial_day_stop_sell_s = False self.initial_stop_sell = False self.initial_stop_sell_s = False self.target_sell = False self.target_sell_s = False self.parabolic_sell = False self.parabolic_sell_s = False self.gap_up_sell = False self.gap_down_sell = False self.break_even = False self.chop = False # VARIABLES self.symbol_price = 0 self.entry_price = 0 self.trade_count = 0 self.sell_count = 0 self.open_price = 0 self.day_counter = 0 self.day_counter_s = 0 self.initial_day_stop_price = 0 self.initial_day_stop_price_s = 0 self.initial_stop_price = 0 self.initial_stop_price_s = 0 self.initial_target_price = 0 self.initial_target_price_s = 0 self.trigger_day_timer = 0 self.trigger_day_timer_s = 0 self.trigger_day_high = 0 self.trigger_day_low = 0 self.previous_day_high = 0 self.previous_day_low = 0 self.trigger_day_open = 0 self.trigger_day_close = 0 self.trigger_free_high = 0 self.trigger_free_low = 0 self.trigger_free_open = 0 self.trigger_free_close = 0 self.trigger_day_high = 0 self.trigger_day_low = 0 self.trigger_day_open = 0 self.trigger_day_close = 0 self.current_day_high = 0 self.current_day_low = 999999 self.trigger_array_high = 0 self.trigger_array_low = 0 self.previous_array_high = 0 self.previous_array_low = 0 self.day_three_high = 0 self.day_four_high = 0 self.day_five_high = 0 self.day_six_high = 0 self.day_three_low = 0 self.day_four_low = 0 self.day_five_low = 0 self.day_six_low = 0 self.vix_price = 0 self.order = True self.SetWarmUp(timedelta(days = 25)) # self.ema = self.EMA(self.symbol.Symbol, 20, Resolution.Daily) # self.vix = self.AddData(CBOE, 'VIX', Resolution.Daily).Symbol # self.vix_ema = self.EMA(self.vix, 20, Resolution.Daily) # CONSOLIDATED DATA # Daily Bars dailyConsolidator = TradeBarConsolidator(timedelta(days=1)) self.SubscriptionManager.AddConsolidator(self.symbol.Symbol, dailyConsolidator) dailyConsolidator.DataConsolidated += self.OnDayBar self.dayBarWindow = RollingWindow[TradeBar](20) # TEST CONSOLIDATED free_consolidator = TradeBarConsolidator(timedelta(minutes=10)) self.SubscriptionManager.AddConsolidator(self.symbol.Symbol, free_consolidator) free_consolidator.DataConsolidated += self.OnFreeBar self.freeBarWindow = RollingWindow[TradeBar](1) # 5-Minute Bars five_min_consolidator = TradeBarConsolidator(timedelta(minutes=5)) self.SubscriptionManager.AddConsolidator(self.symbol.Symbol, five_min_consolidator) five_min_consolidator.DataConsolidated += self.OnFiveMinBar self.fiveMinBarWindow = RollingWindow[TradeBar](2) def SecurityInitializer(self, security): security.SetMarketPrice(self.GetLastKnownPrice(security)) security.SetDataNormalizationMode(DataNormalizationMode.Raw) def OnData(self, data): if self.IsWarmingUp: return if not self.Portfolio.Invested and self.order: contract_symbols = self.OptionChainProvider.GetOptionContractList(self.option_symbol, self.Time) expiry = min([symbol.ID.Date for symbol in contract_symbols], default="EMPTY") filtered_symbols = [symbol for symbol in contract_symbols if symbol.ID.Date == expiry and self.option_symbol.ID.OptionRight == OptionRight.Call] self.contract_symbol = sorted(filtered_symbols, key=lambda symbol: symbol.ID.StrikePrice)[0] value = self.AddOptionContract(self.contract_symbol) shares_to_buy = int(self.Portfolio.Cash / (100*value.AskPrice)) self.MarketOrder(self.contract_symbol, shares_to_buy) self.order = False # CONSOLILDATED FUNCTIONS def OnFiveMinBar(self, sender, bar): self.fiveMinBarWindow.Add(bar) if not self.fiveMinBarWindow.IsReady: return trigger_five_min = self.fiveMinBarWindow[0] previous_five_min = self.fiveMinBarWindow[1] self.trigger_five_min_high = trigger_five_min.High self.trigger_five_min_low = trigger_five_min.Low self.trigger_five_min_open = trigger_five_min.Open self.trigger_five_min_close = trigger_five_min.Close self.previous_five_min_high = previous_five_min.High self.previous_five_min_low = previous_five_min.Low # Inside Bar if (self.trigger_five_min_high < self.previous_five_min_high) and (self.trigger_five_min_low > self.previous_five_min_low): self.trigger_five_min_timer = self.Time.minute self.invest_five_min = True self.five_min_trigger = True self.trigger_five_min_timer_s = self.Time.minute self.invest_five_min_s = True self.five_min_trigger_s = True # 2Down if (self.trigger_five_min_high < self.previous_five_min_high) and (self.trigger_five_min_low < self.previous_five_min_low): self.trigger_five_min_timer = self.Time.minute self.invest_five_min = True self.five_min_trigger = True # 2Up if (self.trigger_five_min_high > self.previous_five_min_high) and (self.trigger_five_min_low > self.previous_five_min_low): self.trigger_five_min_timer_s = self.Time.minute self.invest_five_min_s = True self.five_min_trigger_s = True def OnFreeBar(self, sender, bar): self.freeBarWindow.Add(bar) if not self.freeBarWindow.IsReady: return trigger_free = self.freeBarWindow[0] self.trigger_free_open = trigger_free.Open self.trigger_free_close = trigger_free.Close self.trigger_free_high = trigger_free.High self.trigger_free_low = trigger_free.Low def OnDayBar(self, sender, bar): self.dayBarWindow.Add(bar) if not self.dayBarWindow.IsReady: return # VARIABLES - HIGHS - LOWS trigger_day = self.dayBarWindow[0] previous_day = self.dayBarWindow[1] day_three = self.dayBarWindow[2] day_four = self.dayBarWindow[3] day_five = self.dayBarWindow[4] day_six = self.dayBarWindow[5] day_seven = self.dayBarWindow[6] day_eight = self.dayBarWindow[7] day_nine = self.dayBarWindow[8] day_ten = self.dayBarWindow[9] day_eleven = self.dayBarWindow[10] day_twelve = self.dayBarWindow[11] day_thirteen = self.dayBarWindow[12] day_fourteen = self.dayBarWindow[13] day_fifteen = self.dayBarWindow[14] day_sixteen = self.dayBarWindow[15] day_seventeen = self.dayBarWindow[16] day_eighteen = self.dayBarWindow[17] day_nineteen = self.dayBarWindow[18] day_twenty = self.dayBarWindow[19] self.trigger_day_high = trigger_day.High self.previous_day_high = previous_day.High self.day_three_high = day_three.High self.day_four_high = day_four.High self.day_five_high = day_five.High self.day_six_high = day_six.High self.day_seven_high = day_seven.High self.day_eight_high = day_eight.High self.day_nine_high = day_nine.High self.day_ten_high = day_ten.High self.day_eleven_high = day_eleven.High self.day_twelve_high = day_twelve.High self.day_thirteen_high = day_thirteen.High self.day_fourteen_high = day_fourteen.High self.day_fifteen_high = day_fifteen.High self.day_sixteen_high = day_sixteen.High self.day_seventeen_high = day_seventeen.High self.day_eighteen_high = day_eighteen.High self.day_nineteen_high = day_nineteen.High self.day_twenty_high = day_twenty.High self.trigger_day_low = trigger_day.Low self.previous_day_low = previous_day.Low self.day_three_low = day_three.Low self.day_four_low = day_four.Low self.day_five_low = day_five.Low self.day_six_low = day_six.Low self.day_seven_low = day_seven.Low self.day_eight_low = day_eight.Low self.day_nine_low = day_nine.Low self.day_ten_low = day_ten.Low self.day_eleven_low = day_eleven.Low self.day_twelve_low = day_twelve.Low self.day_thirteen_low = day_thirteen.Low self.day_fourteen_low = day_fourteen.Low self.day_fifteen_low = day_fifteen.Low self.day_sixteen_low = day_sixteen.Low self.day_seventeen_low = day_seventeen.Low self.day_eighteen_low = day_eighteen.Low self.day_nineteen_low = day_nineteen.Low self.day_twenty_low = day_twenty.Low # DAILY TRIGGERING DAILY LOGIC # Inside Bar if (self.trigger_day_high < self.previous_day_high) and (self.trigger_day_low > self.previous_day_low): self.trigger_day_timer = self.Time.day self.invest_daily = True self.daily_trigger = True self.trigger_day_timer_s = self.Time.day self.invest_daily_s = True self.daily_trigger_s = True # 2Down if (self.trigger_day_high < self.previous_day_high) and (self.trigger_day_low < self.previous_day_low): self.trigger_day_timer = self.Time.day self.invest_daily = True self.daily_trigger = True # 2Up if (self.trigger_day_high > self.previous_day_high) and (self.trigger_day_low > self.previous_day_low): self.trigger_day_timer_s = self.Time.day self.invest_daily_s = True self.daily_trigger_s = True # DEFINING CHOP LOGIC self.trigger_array_highs = [] self.trigger_array_lows = [] self.previous_array_highs = [] self.previous_array_lows = [] self.trigger_array_highs.append(self.trigger_day_high) self.trigger_array_highs.append(self.previous_day_high) # self.trigger_array_highs.append(self.day_three_high) # self.trigger_array_highs.append(self.day_four_high) # self.trigger_array_highs.append(self.day_five_high) # self.trigger_array_highs.append(self.day_six_high) # self.trigger_array_highs.append(self.day_seven_high) # self.trigger_array_highs.append(self.day_eight_high) # self.trigger_array_highs.append(self.day_nine_high) # self.trigger_array_highs.append(self.day_ten_high) # self.trigger_array_highs.append(self.day_eleven_high) # self.trigger_array_highs.append(self.day_twelve_high) # self.trigger_array_highs.append(self.day_thirteen_high) # self.trigger_array_highs.append(self.day_fourteen_high) # self.trigger_array_highs.append(self.day_fifteen_high) # self.trigger_array_highs.append(self.day_sixteen_high) # self.trigger_array_highs.append(self.day_seventeen_high) # self.trigger_array_highs.append(self.day_eighteen_high) # self.trigger_array_highs.append(self.day_nineteen_high) # self.trigger_array_highs.append(self.day_twenty_high) self.trigger_array_lows.append(self.trigger_day_low) self.trigger_array_lows.append(self.previous_day_low) # self.trigger_array_lows.append(self.day_three_low) # self.trigger_array_lows.append(self.day_four_low) # self.trigger_array_lows.append(self.day_five_low) # self.trigger_array_lows.append(self.day_six_low) # self.trigger_array_lows.append(self.day_seven_low) # self.trigger_array_lows.append(self.day_eight_low) # self.trigger_array_lows.append(self.day_nine_low) # self.trigger_array_lows.append(self.day_ten_low) # self.trigger_array_lows.append(self.day_eleven_low) # self.trigger_array_lows.append(self.day_twelve_low) # self.trigger_array_lows.append(self.day_thirteen_low) # self.trigger_array_lows.append(self.day_fourteen_low) # self.trigger_array_lows.append(self.day_fifteen_low) # self.trigger_array_lows.append(self.day_sixteen_low) # self.trigger_array_lows.append(self.day_seventeen_low) # self.trigger_array_lows.append(self.day_eighteen_low) # self.trigger_array_lows.append(self.day_nineteen_low) # self.trigger_array_lows.append(self.day_twenty_low) # self.previous_array_highs.append(self.trigger_day_high) # self.previous_array_highs.append(self.previous_day_high) self.previous_array_highs.append(self.day_three_high) self.previous_array_highs.append(self.day_four_high) self.previous_array_highs.append(self.day_five_high) self.previous_array_highs.append(self.day_six_high) self.previous_array_highs.append(self.day_seven_high) self.previous_array_highs.append(self.day_eight_high) self.previous_array_highs.append(self.day_nine_high) self.previous_array_highs.append(self.day_ten_high) # self.previous_array_highs.append(self.day_eleven_high) # self.previous_array_highs.append(self.day_twelve_high) # self.previous_array_highs.append(self.day_thirteen_high) # self.previous_array_highs.append(self.day_fourteen_high) # self.previous_array_highs.append(self.day_fifteen_high) # self.previous_array_highs.append(self.day_sixteen_high) # self.previous_array_highs.append(self.day_seventeen_high) # self.previous_array_highs.append(self.day_eighteen_high) # self.previous_array_highs.append(self.day_nineteen_high) # self.previous_array_highs.append(self.day_twenty_high) # self.previous_array_lows.append(self.trigger_day_low) # self.previous_array_lows.append(self.previous_day_low) self.previous_array_lows.append(self.day_three_low) self.previous_array_lows.append(self.day_four_low) self.previous_array_lows.append(self.day_five_low) self.previous_array_lows.append(self.day_six_low) self.previous_array_lows.append(self.day_seven_low) self.previous_array_lows.append(self.day_eight_low) self.previous_array_lows.append(self.day_nine_low) self.previous_array_lows.append(self.day_ten_low) # self.previous_array_lows.append(self.day_eleven_low) # self.previous_array_lows.append(self.day_twelve_low) # self.previous_array_lows.append(self.day_thirteen_low) # self.previous_array_lows.append(self.day_fourteen_low) # self.previous_array_lows.append(self.day_fifteen_low) # self.previous_array_lows.append(self.day_sixteen_low) # self.previous_array_lows.append(self.day_seventeen_low) # self.previous_array_lows.append(self.day_eighteen_low) # self.previous_array_lows.append(self.day_nineteen_low) # self.previous_array_lows.append(self.day_twenty_low) def max(i): max_value = i[0] for number in i: if number > max_value: max_value = number return max_value def min(i): min_value = i[0] for number in i: if number < min_value: min_value = number return min_value self.trigger_array_high = max(self.trigger_array_highs) self.trigger_array_low = min(self.trigger_array_lows) self.previous_array_high = max(self.previous_array_highs) self.previous_array_low = min(self.previous_array_lows) # Inside Bar if (self.trigger_array_high < self.previous_array_high) and (self.trigger_array_low > self.previous_array_low): self.trading = True else: self.trading = False # SCHEDULED EVENTS def DayStart(self): self.invest_five_min = False self.five_min_trigger = False self.invest_five_min_s = False self.five_min_trigger_s = False def ParabolicCheck(self): self.parabolic_sell = True self.parabolic_sell_s = True def LiquidateCheck(self): if self.long: self.day_counter += 1 else: self.day_counter = 0 if self.short: self.day_counter_s += 1 else: self.day_counter_s = 0 def DayEnd(self): self.gap_up_sell = False self.gap_down_sell = False self.invest_daily = False self.daily_trigger = False self.invest_daily_s = False self.daily_trigger_s = False self.parabolic_sell = False self.parabolic_sell_s = False self.chop = False self.trading = True self.current_day_high = 0 self.current_day_low = 999999 # self.long = False # self.short = False # self.trail_stop = False # self.trail_stop_s = False # self.initial_day_stop_sell = False # self.initial_day_stop_sell_s = False # self.initial_stop_sell = False # self.initial_stop_sell_s = False # self.target_sell = False # self.target_sell_s = False # self.parabolic_sell = False # self.parabolic_sell_s = False # self.break_even = False # self.second_trade = False # self.trade_count = 0