Back

Evaluating option price at different underlying stock prices

Trying to figure out how to calculate Greeks at different underlying prices. The idea is to do it in advance of needing the actual trades executed. The method used here is pretty hacky. Would be open to trying a different way. Also not sure if the changes made to the self.option object have lasting effects. 

The problem is that in the backtest it appears the delta calculation is being done wrong because once the price dips low enough to kick in the trade the delta doesn't become neutral, it's 99 off, which instigates another trade very soon after at almost the same price.

In the code below we need to get "this_trade_bar" because "SetMarketPrice" doesn't work without a BaseData object and I couldn't figure out how to initialize a BaseData object.

this_trade_bar = self.equity.GetLastData()
# update needs a bunch of dummy variables which I hope don't affect the calculation
this_trade_bar.Update(new_price, 1.0, 1.0, 1.0, 1.0, 1.0)
# We're not sure yet what lasting effects setting market price has on the option object
self.option.Underlying.SetMarketPrice(this_trade_bar)
this_option_model_result = self.option.PriceModel.Evaluate(self.option, slice, this_option)
this_delta = this_option_model_result.Greeks.Delta
# delta * num options * num stocks per contract - num stocks already - thresholds covered
num_shares_to_hedge = this_delta * self.Portfolio[this_option.Symbol].Quantity * 100 \
- self.Portfolio[self.stock].Quantity \
- thresholds_so_far * self.delta_threshold * sign

 

Update Backtest








0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


So what appears to be the issue is the original option contract hasn't been updated to reflect the new price and so the greek calculations are off.

0

Hello,

Thanks for sharing the algorithm. This is pretty tricky to achieve. Here are a few thoughts after looking at your code:

  1. We don't recommend using SetMarketPrice() as this is against QC's framework and can cause all sorts of problems.
  2. Here are a few examples of how QC defines the different option pricing models. You might have to implement a custom IOptionPriceModel to achieve the goal of calculating Greeks at different underlying prices. This will pretty tricky so I will leave it to you to decide if you want to proceed with this method, but if you do, you would set it as an independent price model (not on a security)

Sorry we could not be more helpful.

 

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hey!

So this idea comes directly from the code for the Evaluate function. In particular line 93 here;

public OptionPriceModelResult Evaluate(Security security, Slice slice, OptionContract contract)
{
try
{
// setting up option pricing parameters
var calendar = new UnitedStates();
var dayCounter = new Actual365Fixed();
var optionSecurity = (Option)security;

var settlementDate = contract.Time.Date.AddDays(Option.DefaultSettlementDays);
var maturityDate = contract.Expiry.Date.AddDays(Option.DefaultSettlementDays);
var underlyingQuoteValue = new SimpleQuote((double)optionSecurity.Underlying.Price);

A couple of questions about possible solutions if calling SetMarketPrice() is not a good idea

  1. Is SetRealTimePrice() any better?
  2. Is it possible to simply Clone or copy the QuantConnect.Securities.Option.Optionclass, update it and then discard it? I've tried to DeepCopy some objects before and it gave some crazy errors. But surely something along these lines must be feasible?

Let's say I did go down the route of adding an additional input to the Evaluate function which took the current price directly from an input variable instead of getting it from the OptionSecurity.Underlying.Price attribute. Would it even be possible to run this in the online IDE or on a live server?

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed