Stochastic Volatility Pricing in Python | by Roman Paolucci | Towards Data Science

There are a variety of methods used to price securities. I would argue that this topic is as much an art as it is a science. This article discusses the advantages of using simulations (mainly in the form of stochastic inputs) for pricing financial instruments. If you are unfamiliar with securities pricing I would suggest this progression of articles...
Martingales and Markov Processes
A gentle introduction to stochastic processes
Geometric Brownian Motion
The primary stochastic process used in the Black-Scholes model
Stochastic Integrals
The evaluation of stochastic integrals for deriving the Black-Scholes model
Deriving the Black-Scholes Model
Deriving the infamous European option pricing model step by step
Those articles will provide a strong foundation in pricing specific securities using a closed-form solution. Afterward, to get a grasp of basic simulation pricing, check out these articles...
Monte Carlo Pricing in Python
Simulating asset price paths to price financial instruments
Python for Pricing Exotics
Advanced simulation pricing specifically for exotic instruments
Having a strong understanding of these different pricing methodologies will reflect the aforementioned art aspect of this science. Each pricing method is different — from the initial assumptions to the actual means (numerical or analytical) of deriving the security’s price. That doesn’t mean that any particular method is more correct or incorrect; which is precisely why understanding how each price is derived is so important. Knowing the assumptions of a Black-Scholes price (lognormally distributed stock prices and no transaction costs just to name two) against a Monte Carlo price (perhaps inclusive of transaction costs) will help guide your pricing needs. There is beauty in both the theoretical analytical solutions and the numerical solutions (which often converge to some theoretical solutions). In fact, some of my previous research has looked at amendments to the Black-Scholes model to better reflect generic market conditions...
papers.ssrn.com
I will now assume that you have a good foundation of securities pricing knowledge. Without further ado, let’s look at why simulation pricing is so powerful by allowing variation in model inputs.
Empirically observed heteroskedasticity in stock prices is not preserved in Geometric Brownian motion as volatility is held constant. Heston (1993) finds a quasi closed-form solution similar to Black-Scholes persisting the notion of stochastic volatility. However, the derivation of his solution is significantly more complicated than the derivation of the Black-Scholes model and is beyond the scope of this article. Nevertheless, the underlying processes he uses to derive his model can be easily implemented into a simulation for pricing capturing, in essence, the same result: stochastic volatility.
There are fundamentally two processes:
I. The stochastic process used to generate a new variance value
II. The stochastic process used to generate a new stock price value
First, let’s first get a good idea of the parameters we are working with...
S — Initial stock price
r — Risk-free rate of interest
v_t — Instantaneous variance
α, β — Mean reverting parameters
σ_v — Variance’s volatility
ε —Generated error
ρ — Error correlation
Δt — Change in time
Now let’s take a look at the processes themselves...
Fundamentally, there is nothing particularly surprising about these processes. Each process can essentially be decomposed as an expectation in the first term, and a shock to that expectation in the second term.
The particularly keen reader will notice that by creating a separate stochastic process for volatility, we are once again fixing volatility. That is, we are fixing variance’s volatility. This can become a circular argument. Should there be a separate stochastic process for the volatility of variance which is now its own stochastic process? There is research on this subject, and it is worth noting, but for the sake of this article, I digress.
Now let’s look to Python to implement these processes to price securities.
First, let’s import numpy and define the parameters of the stochastic variance process, along with some parameters to price a standard European option...
Next, we need to create the outer loop that is responsible for running the simulation n times...
There are a few parameters set within this loop that will become more clear within the next loop. First, at the start of each new simulation in the series of simulations we need to reset base parameters: St, inst_var_now, prev_inst_var, and step. These are synonymous with the input parameters defined in the first section of the article. Notice that the instantaneous variance is broken up into two variables, this is to allow us to use the appropriate error for each step in the stochastic process generating new variances. Let’s create the inner loop to step through a stock price path with a stochastic variance...
After each iteration of this while loop in the set of simulations, we will arrive at the final stock price value. This final stock price value can be used once again in the outer loop to generate a payoff based on the security we are pricing. In this example, I am pricing a European option, so based on the parameters I compute the appropriate payoff...
Notice that when appending the payoff to the payoffs list the payoff is discounted by the risk-free rate over time T. If the time value of money is a foreign concept see Quantitative Finance in Python.
To compute the simulated price of this European option we simply average the values appended to the payoffs list...
14.648492872411381
There we have it! We have arrived at the simulated price by a process with stochastic variance.
This article has shown how to simulate a security’s price using a stochastic variance process. Again, don’t think of this price as more or less correct when compared to other pricing methodologies. Rather, understand the reason for differences in the final price. This notion can be extended to each parameter affecting a financial instrument and make them all stochastic processes.
Stochastic Variance Simulation Pricing Script: