Time：2021-4-29

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

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
#Volatility
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)

print(results)

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

Most popular insights

## Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]