Course Name: Options Volatility Trading: Concepts and Strategies, Section No: 21, Unit No: 4, Unit type: ZipFiles
Hi, executing the downloaded solution notebook from the section I realize it throws an error. When executing the entire notebook in the backtesting module does not perform any trade at all, so when you run analytics it gives
KeyError: 'position'
because round_trips_details is empty! Maybe a bad initialisation of any variable?
Solution notebook of captsone project does not work. I´ve tried changing some things in vol estimation but still the same, it does not provide any signals. So, signal is empty and it´s not quantying any backtesting or stats at all.
The same is happening to me with another notebook from unit Volatility Forecasting "Trading with GARCH". It is not giving me signals.
I think I´ve fixed this issue. The iloc method is not working well, as it is a deprecated method. Instead of iloc, I´ve used loc method to insert the correspondent signal:
index_ = options_data.index.get_loc(i)
if (index_+4 <= len(options_data)-1):
if (forecasted_volatility > options_data.iloc[index_].C_IV) and (forecasted_volatility > options_data.iloc[index_].P_IV):
print("Long Straddle Trade on:"+str(i))
options_data.loc[i,"signal"] = 1
for t in range(1,5):
new_index = options_data.index[index_+t]
options_data.loc[new_index,'signal'] = 1
# Reseteo la cuenta de dias
days_since_last_signal = 0
# Straddle largo: volatilidad
elif (forecasted_volatility < options_data.iloc[index_].C_IV) and (forecasted_volatility < options_data.iloc[index_].P_IV):
# Añado señal valida igual a -1 para los siguientes 5 dias
print("Short Straddle Trade on:"+str(i))
options_data.loc[i,"signal"] = -1
for t in range(1,5):
new_index = options_data.index[index_+t]
options_data.loc[new_index,'signal'] = -1
# Reseteo la cuenta de dias
days_since_last_signal = 0
Hello Jorge,
The choice between iloc and loc depends on how the variable 'index_' is initialised and also on the structure of the dataframe 'options_data'.
I see you have made changes to the code. However, the code presented in the course should work without any issues unless the structure of the input data is changed.
Please let us know if you have any queries on the code.