Incorporate more realistic slippage into entries and exits

This commit is contained in:
moshferatu 2024-03-07 12:58:59 -08:00
parent 2ea84e8dcd
commit 37c3ebe1fa

View File

@ -111,11 +111,13 @@ def _backtest_iron_condor(
# Calculate entry slippage.
if original_call_spread_price > 0.05:
original_call_spread_price = original_call_spread_price - (original_call_spread_price % 0.05)
original_call_spread_price = original_call_spread_price - 0.10
original_call_spread_price -= (original_call_spread_price % 0.05)
logging.info('Original Call Spread Price: %s', original_call_spread_price)
if original_put_spread_price > 0.05:
original_put_spread_price = original_put_spread_price - (original_put_spread_price % 0.05)
original_put_spread_price = original_put_spread_price - 0.10
original_put_spread_price -= (original_put_spread_price % 0.05)
logging.info('Original Put Spread Price: %s', original_put_spread_price)
premium_received = original_call_spread_price + original_put_spread_price
@ -183,7 +185,7 @@ def _backtest_iron_condor(
premium_received -= original_call_spread_price * (call_spread_strategy.stop_loss_multiple + 1)
call_spread_details['Close'] = original_call_spread_price * (call_spread_strategy.stop_loss_multiple + 1) + 0.10
# Calculate exit slippage.
premium_received -= 0.10 # TODO: Make this configurable.
premium_received -= 0.20 # TODO: Make this configurable.
call_spread_stopped_out = True
exit_time = call_spread.name[-8:]
logging.info('Call Spread Stopped Out')
@ -191,7 +193,7 @@ def _backtest_iron_condor(
if not put_spread_stopped_out:
if current_put_spread_price >= ((put_spread_strategy.stop_loss_multiple + 1) * original_put_spread_price):
premium_received -= original_put_spread_price * (put_spread_strategy.stop_loss_multiple + 1)
premium_received -= 0.10 # TODO: Make this configurable.
premium_received -= 0.20 # TODO: Make this configurable.
put_spread_details['Close'] = original_put_spread_price * (put_spread_strategy.stop_loss_multiple + 1) + 0.10
put_spread_stopped_out = True
exit_time = call_spread.name[-8:]