Capitalize spread field names for the sake of consistency

This commit is contained in:
moshferatu 2024-02-02 07:54:06 -08:00
parent 05288fc235
commit 2335f6798c

View File

@ -134,21 +134,21 @@ def _backtest_iron_condor(
premium_received = original_call_spread_price + original_put_spread_price premium_received = original_call_spread_price + original_put_spread_price
call_spread_details = { call_spread_details = {
"legs": [{"action": "SELL", "strike": call_spread_entry['strike_short_strike'], "type": "CALL"}, "Legs": [{"Action": "SELL", "Strike": call_spread_entry['strike_short_strike'], "Type": "CALL"},
{"action": "BUY", "strike": call_spread_entry['strike_long_strike'], "type": "CALL"}], {"Action": "BUY", "Strike": call_spread_entry['strike_long_strike'], "Type": "CALL"}],
"open": original_call_spread_price, "Open": original_call_spread_price,
"high": None, "High": None,
"low": None, "Low": None,
"close": None "Close": None
} }
put_spread_details = { put_spread_details = {
"legs": [{"action": "SELL", "strike": put_spread_entry['strike_short_strike'], "type": "PUT"}, "Legs": [{"Action": "SELL", "Strike": put_spread_entry['strike_short_strike'], "Type": "PUT"},
{"action": "BUY", "strike": put_spread_entry['strike_long_strike'], "type": "PUT"}], {"Action": "BUY", "Strike": put_spread_entry['strike_long_strike'], "Type": "PUT"}],
"open": original_put_spread_price, "Open": original_put_spread_price,
"high": None, "High": None,
"low": None, "Low": None,
"close": None "Close": None
} }
trades_entered = False trades_entered = False
@ -185,18 +185,18 @@ def _backtest_iron_condor(
else: else:
current_put_spread_price = ((put_spread['ask_short_strike'] + put_spread['bid_short_strike']) / 2.0) - ((put_spread['ask_long_strike'] + put_spread['bid_long_strike']) / 2.0) current_put_spread_price = ((put_spread['ask_short_strike'] + put_spread['bid_short_strike']) / 2.0) - ((put_spread['ask_long_strike'] + put_spread['bid_long_strike']) / 2.0)
call_spread_details['high'] = max(call_spread_details['high'] or float('-inf'), current_call_spread_price) call_spread_details['High'] = max(call_spread_details['High'] or float('-inf'), current_call_spread_price)
call_spread_details['low'] = min(call_spread_details['low'] or float('inf'), current_call_spread_price) call_spread_details['Low'] = min(call_spread_details['Low'] or float('inf'), current_call_spread_price)
call_spread_details['close'] = current_call_spread_price call_spread_details['Close'] = current_call_spread_price
put_spread_details['high'] = max(put_spread_details['high'] or float('-inf'), current_put_spread_price) put_spread_details['High'] = max(put_spread_details['High'] or float('-inf'), current_put_spread_price)
put_spread_details['low'] = min(put_spread_details['low'] or float('inf'), current_put_spread_price) put_spread_details['Low'] = min(put_spread_details['Low'] or float('inf'), current_put_spread_price)
put_spread_details['close'] = current_put_spread_price put_spread_details['Close'] = current_put_spread_price
if not call_spread_stopped_out: if not call_spread_stopped_out:
if current_call_spread_price >= ((call_spread_strategy.stop_loss_multiple + 1) * original_call_spread_price): if current_call_spread_price >= ((call_spread_strategy.stop_loss_multiple + 1) * original_call_spread_price):
premium_received -= original_call_spread_price * (call_spread_strategy.stop_loss_multiple + 1) 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 call_spread_details['Close'] = original_call_spread_price * (call_spread_strategy.stop_loss_multiple + 1) + 0.10
# Calculate exit slippage. # Calculate exit slippage.
premium_received -= 0.10 # TODO: Make this configurable. premium_received -= 0.10 # TODO: Make this configurable.
call_spread_stopped_out = True call_spread_stopped_out = True
@ -207,7 +207,7 @@ def _backtest_iron_condor(
if current_put_spread_price >= ((put_spread_strategy.stop_loss_multiple + 1) * original_put_spread_price): 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 -= original_put_spread_price * (put_spread_strategy.stop_loss_multiple + 1)
premium_received -= 0.10 # TODO: Make this configurable. premium_received -= 0.10 # TODO: Make this configurable.
put_spread_details['close'] = original_put_spread_price * (put_spread_strategy.stop_loss_multiple + 1) + 0.10 put_spread_details['Close'] = original_put_spread_price * (put_spread_strategy.stop_loss_multiple + 1) + 0.10
put_spread_stopped_out = True put_spread_stopped_out = True
exit_time = call_spread.name[-8:] exit_time = call_spread.name[-8:]
logging.info('Put Spread Stopped Out') logging.info('Put Spread Stopped Out')