diff --git a/backtest_iron_condor_example.py b/backtest_iron_condor_example.py index 5898973..4a33706 100644 --- a/backtest_iron_condor_example.py +++ b/backtest_iron_condor_example.py @@ -1,30 +1,15 @@ -from backtesting import backtest_iron_condor, DeltaTargetStrategy, OptionType +from backtesting import backtest_iron_condor +from backtesting.delta_targeting import create_strategies from datetime import datetime from plotting import BacktestChart, plot -def create_strategies(entry_time: str, number_of_contracts: int = 1): - call_spread_strategy = DeltaTargetStrategy( - delta_target = 0.10, - option_type = OptionType.CALL, - number_of_contracts = number_of_contracts, - spread_width = 50, - stop_loss_multiple = 1.00, - trade_entry_time = entry_time - ) - put_spread_strategy = DeltaTargetStrategy( - delta_target = -0.10, - option_type = OptionType.PUT, - number_of_contracts = number_of_contracts, - spread_width = 50, - stop_loss_multiple = 1.00, - trade_entry_time = entry_time - ) - return call_spread_strategy, put_spread_strategy - if __name__ == '__main__': start_date = datetime(2024, 1, 1) end_date = datetime.now() - call_spread_strategy, put_spread_strategy = create_strategies(entry_time = '10:05:00') + call_spread_strategy, put_spread_strategy = create_strategies( + delta_target = 0.10, + entry_time = '10:05:00' + ) backtest_result = backtest_iron_condor( f'Iron Condor @ {call_spread_strategy.trade_entry_time}', call_spread_strategy, diff --git a/backtesting/credit_targeting.py b/backtesting/credit_targeting.py index e486d67..72d5c9a 100644 --- a/backtesting/credit_targeting.py +++ b/backtesting/credit_targeting.py @@ -1,7 +1,27 @@ from dataclasses import dataclass from .option_spread_strategy import OptionSpreadStrategy +from .option_type import OptionType @dataclass class CreditTargetStrategy(OptionSpreadStrategy): - credit_target: float \ No newline at end of file + credit_target: float + +def create_strategies(credit_target: float, entry_time: str, number_of_contracts: int = 1): + call_spread_strategy = CreditTargetStrategy( + credit_target = credit_target, + option_type = OptionType.CALL, + number_of_contracts = number_of_contracts, + spread_width = 50, + stop_loss_multiple = 1.00, + trade_entry_time = entry_time + ) + put_spread_strategy = CreditTargetStrategy( + credit_target = credit_target, + option_type = OptionType.PUT, + number_of_contracts = number_of_contracts, + spread_width = 50, + stop_loss_multiple = 1.00, + trade_entry_time = entry_time + ) + return call_spread_strategy, put_spread_strategy \ No newline at end of file diff --git a/backtesting/delta_targeting.py b/backtesting/delta_targeting.py index ff91525..5283bbf 100644 --- a/backtesting/delta_targeting.py +++ b/backtesting/delta_targeting.py @@ -1,7 +1,27 @@ from dataclasses import dataclass from .option_spread_strategy import OptionSpreadStrategy +from .option_type import OptionType @dataclass class DeltaTargetStrategy(OptionSpreadStrategy): - delta_target: float \ No newline at end of file + delta_target: float + +def create_strategies(delta_target: float, entry_time: str, number_of_contracts: int = 1): + call_spread_strategy = DeltaTargetStrategy( + delta_target = delta_target, + option_type = OptionType.CALL, + number_of_contracts = number_of_contracts, + spread_width = 50, + stop_loss_multiple = 1.00, + trade_entry_time = entry_time + ) + put_spread_strategy = DeltaTargetStrategy( + delta_target = -delta_target, + option_type = OptionType.PUT, + number_of_contracts = number_of_contracts, + spread_width = 50, + stop_loss_multiple = 1.00, + trade_entry_time = entry_time + ) + return call_spread_strategy, put_spread_strategy \ No newline at end of file