Prevent backtests over periods where the market closes early
This commit is contained in:
parent
f0f6e02a12
commit
c56e7bf0bf
@ -127,10 +127,15 @@ def _backtest_iron_condor(
|
||||
call_spread_history = get_spread_history(historical_option_data, call_spread_strategy)
|
||||
put_spread_history = get_spread_history(historical_option_data, put_spread_strategy)
|
||||
|
||||
current_date = call_spread_history.iloc[0].name[:10]
|
||||
|
||||
entry_time = call_spread_strategy.trade_entry_time
|
||||
|
||||
if call_spread_history is None or put_spread_history is None:
|
||||
# This can happen when the market closes early for the day.
|
||||
logging.warn('No spread history found in %s for %s', historical_data_file, entry_time)
|
||||
return None
|
||||
|
||||
current_date = call_spread_history.iloc[0].name[:10]
|
||||
|
||||
call_spread_entry = call_spread_history.loc[current_date + ' ' + entry_time]
|
||||
original_call_spread_price = ((call_spread_entry['ask_short_strike'] + call_spread_entry['bid_short_strike']) / 2.0) - ((call_spread_entry['ask_long_strike'] + call_spread_entry['bid_long_strike']) / 2.0)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user