diff --git a/backtest_iron_condor_example.py b/backtest_iron_condor_example.py index 62f5851..5898973 100644 --- a/backtest_iron_condor_example.py +++ b/backtest_iron_condor_example.py @@ -4,8 +4,7 @@ from plotting import BacktestChart, plot def create_strategies(entry_time: str, number_of_contracts: int = 1): call_spread_strategy = DeltaTargetStrategy( - delta_upper_bound = 0.11, - delta_lower_bound = 0.10, + delta_target = 0.10, option_type = OptionType.CALL, number_of_contracts = number_of_contracts, spread_width = 50, @@ -13,8 +12,7 @@ def create_strategies(entry_time: str, number_of_contracts: int = 1): trade_entry_time = entry_time ) put_spread_strategy = DeltaTargetStrategy( - delta_upper_bound = 0.11, - delta_lower_bound = 0.10, + delta_target = -0.10, option_type = OptionType.PUT, number_of_contracts = number_of_contracts, spread_width = 50, @@ -24,7 +22,7 @@ def create_strategies(entry_time: str, number_of_contracts: int = 1): return call_spread_strategy, put_spread_strategy if __name__ == '__main__': - start_date = datetime(2024, 1, 12) + start_date = datetime(2024, 1, 1) end_date = datetime.now() call_spread_strategy, put_spread_strategy = create_strategies(entry_time = '10:05:00') backtest_result = backtest_iron_condor( diff --git a/backtesting/backtest_iron_condor.py b/backtesting/backtest_iron_condor.py index f5f3761..2d6f286 100644 --- a/backtesting/backtest_iron_condor.py +++ b/backtesting/backtest_iron_condor.py @@ -74,13 +74,8 @@ def get_spread_history(historical_option_data: pd.DataFrame, option_strat: Delta if opening_quotes.empty: return None else: - if option_strat.option_type == OptionType.PUT: - opening_quotes['delta_diff'] = (opening_quotes['delta'] + option_strat.delta_upper_bound).abs() - short_contract = opening_quotes.loc[opening_quotes['delta_diff'].idxmin()] - else: - opening_quotes['delta_diff'] = (opening_quotes['delta'] - option_strat.delta_upper_bound).abs() - short_contract = opening_quotes.loc[opening_quotes['delta_diff'].idxmin()] - + opening_quotes['delta_diff'] = (opening_quotes['delta'] - option_strat.delta_target).abs() + short_contract = opening_quotes.loc[opening_quotes['delta_diff'].idxmin()] short_strike = short_contract['strike'] logging.info('Short Strike: %s', short_strike) diff --git a/backtesting/delta_target_strategy.py b/backtesting/delta_target_strategy.py index f93ac92..ff91525 100644 --- a/backtesting/delta_target_strategy.py +++ b/backtesting/delta_target_strategy.py @@ -4,6 +4,4 @@ from .option_spread_strategy import OptionSpreadStrategy @dataclass class DeltaTargetStrategy(OptionSpreadStrategy): - # TODO: Just search closest delta instead. - delta_upper_bound: float - delta_lower_bound: float \ No newline at end of file + delta_target: float \ No newline at end of file