Correctly update the closing price of each spread
This commit is contained in:
parent
16db358eaf
commit
2ea84e8dcd
@ -124,18 +124,18 @@ def _backtest_iron_condor(
|
||||
"Legs": [{"Action": "SELL", "Strike": call_spread_entry['strike_short_strike'], "Type": "CALL"},
|
||||
{"Action": "BUY", "Strike": call_spread_entry['strike_long_strike'], "Type": "CALL"}],
|
||||
"Open": original_call_spread_price,
|
||||
"High": None,
|
||||
"Low": None,
|
||||
"Close": None
|
||||
"High": float('-inf'),
|
||||
"Low": float('inf'),
|
||||
"Close": 0.0
|
||||
}
|
||||
|
||||
put_spread_details = {
|
||||
"Legs": [{"Action": "SELL", "Strike": put_spread_entry['strike_short_strike'], "Type": "PUT"},
|
||||
{"Action": "BUY", "Strike": put_spread_entry['strike_long_strike'], "Type": "PUT"}],
|
||||
"Open": original_put_spread_price,
|
||||
"High": None,
|
||||
"Low": None,
|
||||
"Close": None
|
||||
"High": float('-inf'),
|
||||
"Low": float('inf'),
|
||||
"Close": 0.0
|
||||
}
|
||||
|
||||
trades_entered = False
|
||||
@ -172,13 +172,11 @@ def _backtest_iron_condor(
|
||||
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)
|
||||
|
||||
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['Close'] = current_call_spread_price
|
||||
call_spread_details['High'] = max(call_spread_details['High'], current_call_spread_price)
|
||||
call_spread_details['Low'] = min(call_spread_details['Low'], current_call_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['Close'] = current_put_spread_price
|
||||
put_spread_details['High'] = max(put_spread_details['High'], current_put_spread_price)
|
||||
put_spread_details['Low'] = min(put_spread_details['Low'], current_put_spread_price)
|
||||
|
||||
if not call_spread_stopped_out:
|
||||
if current_call_spread_price >= ((call_spread_strategy.stop_loss_multiple + 1) * original_call_spread_price):
|
||||
@ -231,9 +229,11 @@ def _backtest_iron_condor(
|
||||
|
||||
if not call_spread_stopped_out and current_call_spread_price > 0.05:
|
||||
premium_received -= current_call_spread_price
|
||||
call_spread_details['Close'] = current_call_spread_price
|
||||
|
||||
if not put_spread_stopped_out and current_put_spread_price > 0.05:
|
||||
premium_received -= current_put_spread_price
|
||||
put_spread_details['Close'] = current_put_spread_price
|
||||
|
||||
number_of_contracts = call_spread_strategy.number_of_contracts
|
||||
stop_out_fees = 0.0 # It costs money to get stopped out.
|
||||
|
Loading…
Reference in New Issue
Block a user