Heston model for option pricing in R language


Link to the original text:http://tecdat.cn/?p=12111

In this article, I will show you how to simulate the Heston stochastic volatility model of stock price.

Heston model is an option valuation method, which takes into account the volatility of different options traded in the same asset at a given time. It attempts to recreate market pricing by using stochastic processes to simulate volatility and interest rates. The characteristic of Heston model is to include the square root of volatility function in the whole pricing function.

For a fixed risk-free interest rate, it is described as follows:

Heston model for option pricing in R language

By using this model, we can get the price of European call options.

This is the description of the function.

callHestoncf(S, X, tau, r, v0, vT, rho, k, sigma){
#S = the price of the share price on the maturity date, x = exercise price, tau = maturity date
#R = risk free interest rate, q = dividend yield
#V0 = initial variance, VT = long-term variance
#Rho = correlation coefficient, k = is VT regression to θ The speed of the car;
#Sigma = volatility

Now, Monte Carlo pricing. We will price three European call options with three different exercise prices. We used 100000 simulations for 15 years, once a month. The following are the simulation parameters:

#Initial price
S0 <- 100
#Simulation times (can be reduced at will)
n <- 100000
#Sampling frequency
freq <- "monthly"
#Recovery speed of volatility mean
kappa <- 0.003
volvol <- 0.009
#Correlation. Volume and spot price
rho <- -0.5
#Initial variance
V0 <- 0.04
#Long term variance
theta <- 0.04
#Initial short term interest rate
r0 <- 0.015
#Maturity date of options
horizon <- 15
#Option exercise price
strikes <- c(140, 100, 60)

In order to use the simulation Heston model, we first need to define how to simulate.

This function provides a list of 2 components, each containing a simulated random Gaussian increment.

#    Stochastic wave simulation
sim.vol <- simdiff(n =  n, horizon =  horizon,
frequency =  freq, model = "CIR", x0 =  V0,
theta1 =  kappa*theta, theta2 =  kappa,
theta3 =  volvol, eps =  shocks[[1]])
#Stock price simulation
sim.price <- simdiff(n = n, horizon = horizon,
frequency = freq, model = "GBM", x0 = S0,
theta1 = r0, theta2 = sqrt(sim.vol),
eps = shocks[[2]])

Now, we can calculate three different options prices.

#Maturity stock price (15 years)

strikes mcprices  lower95  upper95 pricesAnalytic
1     140 25.59181 25.18569 25.99793         25.96174
2     100 37.78455 37.32418 38.24493         38.17851
3      60 56.53187 56.02380 57.03995         56.91809

From these results, we can see that the Monte Carlo prices of the three options are quite close to the prices calculated by using the function (directly using the formula to calculate the prices). The 95% confidence interval contains the theoretical price.

Here’s the option price as a function of the number of simulations. The calculated theoretical price is plotted in blue, the Monte Carlo average price is plotted in red, and the shaded area represents the 95% confidence interval around the mean (Monte Carlo price).

Heston model for option pricing in R language

Heston model for option pricing in R language

Most popular insights

1.Recognition of changing stock market by machine learning — Application of hidden Markov model (HMM)

2.R language garch-dcc model and DCC (MVT) modeling estimation

3.R language implementation copula algorithm modeling dependency case analysis report

4.R language copulas and VaR analysis of financial time series data

5.Time series prediction of R-language multivariate copula GARCH model

6.An example of stock forecasting based on neural network with R language

7.Realization of Volatility Prediction with R language: arch model and har-rv model

8.How to make Markov switching model with R language

9.Matlab uses copula simulation to optimize market risk