Hello,
I have a question regarding the Risk Management Solution Capstone in the Advanced Options Volatility Trading course.
In the provided solution, I noticed that the stop-loss is triggered only if the closing price at the end of the day is below the stop-loss level. However, the possibility of an intraday price dropping below the stop-loss level (and triggering it during the day) doesn’t seem to be considered in the mechanism.
I was wondering how this intraday consideration could be incorporated into the strategy. Specifically:
- What kind of data should be consulted to determine whether the stop-loss would have been hit during the day?
- How could this be implemented within the provided framework or in a similar solution?
I’d appreciate any insights or suggestions. Thanks in advance!
Hello Luis Hernan Gomez,
Thank you for your thoughtful question!
Let’s dive into the details to address your concerns about incorporating intraday stop-loss considerations into the strategy.
The project is designed for daily data. However, if you want to modify it for intraday extremes, here is how you can do it.
Using intraday data for the solution code given can indeed breach stop-loss levels. So, here is how you can modify the problem statement. [ in this iteration of the reply, I'm assuming you don't have the granular minute-minute data and proposing an optimal solution to incorporate intraday level by still using the daily data]
The best way to handle it is using intraday data for a more realistic event-based backtest.
However, if you don't have access to minute-minute data or hourly data, you can use high and low prices of daily data, which can suffice for simulating intraday stop-loss conditions without requiring full intraday data.
To incorporate intraday stop-loss considerations, use the high and low prices of the options (or the underlying asset, if hedging) to assess whether the stop-loss level was breached during the trading day. Replace the current stop-loss logic, which relies on the closing price, with a comparison against the intraday low price for long positions or the intraday high price for short positions, ensuring that stop-loss triggers account for more realistic price movements throughout the day.
Let's see how you can modify the current functions.
- # Function for fetching premium
def get_premium(options_strategy, options_data):
# Get the premium for call option
if options_strategy['Asset Type'] == "CE":
return options_data[' [C_LAST]']
# Get the premium for put option
elif options_strategy['Asset Type'] == "PE":
return options_data[' [P_LAST]']
This function needs to be changed to consider the high or low of the day depending on the short or long position you are considering. However, irrespective of long/short you need both data i.e. net premium at high and low since your risk management involves stoploss and take profit.
So, assumes you have access to the [C_HIGH], [C_LOW], [P_HIGH], [P_LOW] columns in your options_data
Calculate intraday high and low net premium for the straddle
intraday_high_premium = (straddle.Position * straddle.apply(
lambda r: get_premium(r, setup_strike_data, price_type='HIGH'), axis=1)).sum()
intraday_low_premium = (straddle.Position * straddle.apply(
lambda r: get_premium(r, setup_strike_data, price_type='LOW'), axis=1)).sum()
Check for intraday stop-loss
if intraday_low_premium < sl: # Intraday low triggers stop-loss
exit_type = 'Intraday SL'
exit_flag = True
elif intraday_high_premium > tp: # Intraday high triggers take-profit
exit_type = 'Intraday TP'
exit_flag = True
The existing stop-loss logic with the new intraday logic inside the open position evaluation loop (where current_position == 1). Ensure the setup_strike_data used for the calculation has the necessary columns ([C_HIGH], [C_LOW], etc.).
Please give it a try and lemme know if you need any assistance. However, if you have granular data like tick data or minute -minute data or hourly data, you can follow the same approach and incase if you need any assistance, please let us know.
Happy learning !
Thank you for your response! It was very helpful.
I have an additional question. If I wanted to perform a more precise analysis using bid and ask prices, what type of data would be suitable to calculate the intraday low bid and ask high?
I’ve been searching for data that could work for this analysis, but so far, the only thing I’ve found is intraday tick data. However, it tends to be quite heavy and potentially impractical for large-scale analysis.
Do you have any suggestions or alternatives that could be more manageable? I’d really appreciate your insights.
Thank you again!