0

Heston Model Delta And Gamma

def calculate_greeks(S0, K, T, r, v0, kappa, theta, sigma, rho, M_in_year, Ite, delta_S=0.1, gamma_S=0.001):     np.random.seed(SEED)     # Original prices     call_price, put_price = heston_model_mc(S0, K, T, r, v0, kappa, theta, sigma, rho, M_in_year, Ite)     # Prices with S0 + delta_S     call_price_up, put_price_up = heston_model_mc(S0 + delta_S, K, T, r, v0, kappa, theta, sigma, rho, M_in_year, Ite)     # Prices with S0 + gamma_S     call_price_gamma_up, put_price_gamma_up = heston_model_mc(S0 + gamma_S, K, T, r, v0, kappa, theta, sigma, rho, M_in_year, Ite)     # Prices with S0 - gamma_S     call_price_gamma_down, put_price_gamma_down = heston_model_mc(S0 - gamma_S, K, T, r, v0, kappa, theta, sigma, rho, M_in_year, Ite)     # Calculate delta     delta_call = (call_price_up - call_price) / delta_S     delta_put = (put_price_up - put_price) / delta_S     # Calculate gamma     gamma_call = (call_price_gamma_up - 2 * call_price + call_price_gamma_down) / (gamma_S ** 2)     gamma_put = (put_price_gamma_up - 2 * put_price + put_price_gamma_down) / (gamma_S ** 2)     return round(delta_call, 2), round(delta_put, 2), round(gamma_call, 2), round(gamma_put, 2) # Correlation -0.30 rho = -0.30 delta_call_1, delta_put_1, gamma_call_1, gamma_put_1 = calculate_greeks(S0, K, T, r, v0, kappa, theta, sigma, rho, M_in_year, Ite) # Correlation -0.70 rho = -0.70 delta_call_2, delta_put_2, gamma_call_2, gamma_put_2 = calculate_greeks(S0, K, T, r, v0, kappa, theta, sigma, rho, M_in_year, Ite) results_9 = pd.DataFrame({"Q #": [5] * 4 + [6] * 4}) results_9["Greek"] = (["Delta"] * 2 + ["Gamma"] * 2) * 2 results_9["Type"] = ["ATM Call", "ATM Put"] * 4 results_9["Value"] = [delta_call_1, delta_put_1, gamma_call_1, gamma_put_1] + \                        [delta_call_2, delta_put_2, gamma_call_2, gamma_put_2] results_9 results_9 Please, are the formulas for delta and gamma for this code correct. I saw something about finite differences in a book. Can you help me correct or change the code if it's wrong.

4th Jun 2024, 8:26 PM
David Marvel
2 Réponses
0
Yes, the formulas are correct. It makes use of finite difference used in heston model for gammas and deltas. The provided code already utilizes the finite difference formulas for delta and gamma within the calculate_greeks function. Here's a breakdown of how the formulas are integrated: Delta Calculation: delta_call = (call_price_up - call_price) / delta_S delta_put = (put_price_up - put_price) / delta_S This directly implements the delta definition using prices with a small change in the underlying price (delta_S). Gamma Calculation: gamma_call = (call_price_gamma_up - 2 * call_price + call_price_gamma_down) / (gamma_S ** 2) gamma_put = (put_price_gamma_up - 2 * put_price + put_price_gamma_down) / (gamma_S ** 2) This uses the finite difference approach to approximate the rate of change of delta. call_price_gamma_up and call_price_gamma_down capture call price changes for slightly higher and lower underlying prices (using gamma_S). The difference divided by gamma_S**2 estimates the change in delta and normalizes it by the squared change in the underlying price. Therefore, the code already integrates the desired formulas. No further changes are needed regarding the delta and gamma calculations within the calculate_greeks function.
4th Jun 2024, 8:32 PM
Winny Bakare
0
Yes, your formula is correct. Here's how the gamma formula you provided shows the rate of change of delta: 1. Finite Difference Approximation: Similar to your delta calculation, gamma uses a finite difference approximation to capture the rate of change. This means it estimates the derivative (which measures the rate of change) by looking at small changes in the underlying price (S). 2. Three Option Prices: call_price_gamma_up: This represents the price of a call option when the underlying price is slightly higher (similar to call_price_up in delta). call_price: This is the original call option price. call_price_gamma_down: This represents the price of a call option when the underlying price is slightly lower. 3. The Change in Delta: The difference between call_price_gamma_up and call_price_gamma_down captures the change in the call option's price for a small change (gamma_S) in the underlying price. This change essentially represents the "delta" of the delta, which is the rate of change of delta. 4. Scaling and Normalization: Dividing by (gamma_S ** 2) normalizes the change based on the squared change in the underlying price. This gives us a unitless measure of gamma, similar to how delta is a value between 0 and 1. Thus your code needs no correction or change.
4th Jun 2024, 8:37 PM
Leonard