From 28e316b03a47db476db4ae8eb66be6b4f310ac25 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Thu, 1 Feb 2024 06:00:57 -0800 Subject: [PATCH] Remove available entry time logic and instead depend on the options backtesting module --- run_backtest.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/run_backtest.py b/run_backtest.py index 0b86d6f..354b980 100644 --- a/run_backtest.py +++ b/run_backtest.py @@ -1,24 +1,9 @@ -from backtesting import backtest_iron_condor +from backtesting import available_entry_times, backtest_iron_condor from backtesting.delta_target_strategy import DeltaTargetStrategy from backtesting.option_type import OptionType from database.backtest import insert from datetime import datetime, timedelta -entry_time_format = '%H:%M:%S' - -def entry_times(): - start = datetime.strptime('09:35:00', entry_time_format) - end = datetime.strptime('15:55:00', entry_time_format) - - current_time = start - entry_times = [] - - while current_time <= end: - entry_times.append(current_time.strftime(entry_time_format)) - current_time += timedelta(minutes = 5) - - return entry_times - def create_strategies(entry_time: str): call_spread_strat = DeltaTargetStrategy( delta_target = 0.10, @@ -39,7 +24,7 @@ def create_strategies(entry_time: str): return call_spread_strat, put_spread_strat def run_backtest(start_date: datetime, end_date: datetime): - for entry_time in entry_times(): + for entry_time in available_entry_times(): call_spread_strategy, put_spread_strategy = create_strategies(entry_time) backtest_results = backtest_iron_condor( f'10 Delta Iron Condor @ {call_spread_strategy.trade_entry_time}',