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
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