Python for Finance: Analyze Big Financial Data

(Elle) #1

Valuation of European volatility call options


in Gruenbichler-Longstaff (1996) model


square-root diffusion framework


— semianalytical formula



from scipy.stats import ncx2
import numpy as np


Semianalytical option pricing formula of GL96


def calculate_option_value(V0, kappa, theta, sigma, zeta, T, r, K):
”’ Calculation of European call option price in GL96 model.


            Parameters
==========
V0 : float
current volatility level
kappa : float
mean reversion factor
theta : float
long-run mean of volatility
sigma : float
volatility of volatility
zeta :
volatility risk premium
T : float
time-to-maturity
r : float
risk-free short rate
K : float
strike price of the option

Returns
=======
value : float
net present value of volatility call option
”’

D = np.exp(-r * T) # discount factor


variables


alpha = kappa theta
beta = kappa + zeta
gamma = 4
beta / (sigma * 2 ( 1 - np.exp(-beta T)))
nu = 4
alpha / sigma * 2
lamb = gamma
np.exp(-beta T) V0
cx1 = 1 - ncx2.cdf(gamma K, nu + 4 , lamb)
cx2 = 1 - ncx2.cdf(gamma
K, nu + 2 , lamb)
cx3 = 1 - ncx2.cdf(gamma * K, nu, lamb)


formula for European call price


value = (D np.exp(-beta T) V0 cx1



  • D (alpha / beta) ( 1 - np.exp(-beta * T))


                    *   cx2 -   D   *   K   *   cx3)

return value


To simplify the implementation of the web service we write a convenience function,


get_option_value, which will check for the provision of all needed parameters to


calculate a call option value. The function is stored in a Python module called


vol_pricing_service.py, the code of which is shown in Example 14-9. This script also


contains a dictionary with all the necessary parameters and brief descriptions of these


parameters. The function will return an error message detailing what is missing whenever


one or more parameters are missing. If all necessary parameters are provided during the


web service call, the function calls the pricing function calculate_option_value from


the vol_pricing_formula.py script.


Example 14-9. Python script for volatility option valuation and web service helper


function


Free download pdf