Computing Power to the People

The Official Qarnot Blog

< Back

Stock options pricing using Python: an introduction


by Paul - April 8, 2017 - Finance
CC-BY-SA / cadunico
 

In finance, the Monte Carlo method is used to simulate the various sources of uncertainty that affect the value of the instrument, portfolio or investment in question, and to then calculate a representative value given these possible values of the underlying inputs.

Problem description

A call option, often simply labeled a call, is a financial contract between two parties, the buyer and the seller. The buyer of the call option has the right, but not the obligation, to buy a particular financial instrument, the underlying ($S$), from the seller of the option at a certain time, the maturity date ($T$), for a certain price, the strike ($K$). The seller is obligated to sell the underlying S to the buyer if the buyer so decides. The buyer pays a fee, the premium ($p$), for this right. By convention, we set the time origin $t=0$ at option contract initiation and $S_t$ is the observable price of the underlying. Typically, if $S$ is a stock, $S_t$ represents its exchange price on the market at time $t$. The value of the call option at maturity $t=T$ is $V_T = Max(S_T-K,0)$. The payoff for the buyer, $V_T$, is represented on the next figure.

The problem is to estimate, $p = V_0$, the right value of the contract at $t=0$.

What happens in (simplified) nature

To estimate the value of an option, we must modelize the behaviour of the underlying stock market. Basic financial theory modelize the underlying asset St as a geometric brownian motion satisfying the following stochastic differential equation:

$$dS_t = \mu S_t dt + \sigma S_t dW_t$$

where $\mu$ is the drift of $S$, $\sigma$ the volatility of $S$ and $W_t$ a Wiener process. The solution of this stochastic differential equation is the following

$$S_t = S_0 exp \left(\left(\mu – \dfrac{\sigma^2}{2}\right) t + \sigma W_t \right)$$

If we simulate many times the previous stochastic process, we get paths and $S_T$ distribution is lognormal, i.e. $ln(S_T)$ has normal gaussian distribution, as shown in the following figure. Since we just need the terminal value $S_T$ of the underlying at maturity $T$, we don’t need to simulate full $S_t$ paths since $S_T$ can be directly simulated as:

$$S_T = S_0 exp \left(\left(\mu – \dfrac{\sigma^2}{2}\right) T + \sigma \sqrt{T} \mathcal{N}(0,1) \right)$$

where $\mathcal{N}(0,1)$ is the standard Gaussian distribution (with zero mean and unit variance).

In terms of theory, the price of the option is its discounted expected value. With Monte Carlo valuation, the technique applied then, is:

  1. to generate a large number of simulated possible price paths for the underlying;
  2. to then calculate the associated exercise value (i.e. “payoff”) of the option for each path.
  3. These payoffs are then averaged and
  4. discounted to today. This result is the value of the option.

Some code

The following code implement the previous method applied to a simple call option.

You can estimate the call price with several amount of samples.

Of course you can play with the parameters to estimate the price of an option “in the money”, i.e. with a underlying asset price $S_0$ over the strike $K$, or “out of the money, i.e. with a underlying asset price $S_0$ below the strike $K$.

Real life is more complex

The previous example, with a vanilla, i.e. basic, theoretical and standard, call option in a very simple compared to what happen in real markets. Furthermore, we didn’t explain how to determine the drift ($\mu$) and the volatility ($\sigma$) of $S$. Among many other things, a more realistic valuation case would have to take into account:

  1. a multi-underlying asset portfolio, thus correlation factors between theses assets;
  2. volatility used in the model depends on the strike $K$ and the maturity $T$;
  3. in practice, interest rates are not constant;
  4. the model underestimate extreme moves, yielding tail risks;
  5. in practice, hedging the option is not cost-less;
  6. real stocks pay dividends, or other corporate actions, generating discontinuities in market value;
  7. …;

These are only some of the difficulties that you will encounter if you want to perfectly price an option. Otherwise, it would be too simple…

[1] Monte Carlo method: wikipedia

[2] Monte Carlo methods for option pricing: wikipedia