SHASHANK KHANNA
  • Blog
  • Gallery
  • About
  • Contact

Monte-Carlo Simulations

 

Purpose

To perform Monte-Carlo simulations and use it to calculate expected price at a given future date.

What are Monte-Carlo Simulations?

Monte-Carlo simulations are basically simulations of probability. As per investopedia:

"Monte Carlo simulations are used to model the probability of different outcomes in a process that cannot easily be predicted due to the intervention of random variables. "

Basically, given a set of parameters and some random variables, we perform thousands of simulations and then seek expected outcome.

Gaussian Process and Brownian Motion

In our case, we will make use of Gaussian Process that provides us with the random variable and then use it along with Asset Volatility, Risk-free rate, and time duration to calculate the expected price at a given future date.

This continuous-time stochastic process represents the Brownian motion (aka the Wiener Process). 
​
Primary use of this Gaussian based Monte-Carlo simulations is to generate asset prices is used to calculate American Option prices, which we will go over in another blog. 
​

Below is the Python library to generate value from Gaussian distribution.
Gaussian random variable in Python

    

Fetch underlying data

In order to successfully apply Monte-Carlo simulations on this Gaussian process, we need to get below data:
  • Asset Volatility ( sigma )
  • Spot Price ( S )
  • Risk Free Rate ( Rf )
  • Time to maturity (in years) ( T-t )
Asset volatility can be calculated from historical asset prices; hence, we need to download historical prices from one of the web-sources. Risk-free rate in our case will be a 3-month Treasury Rate that can be fetched from FRED database using Quandl API.  

Panda library has a useful function to download these prices from Morningstar, Quandl, Yahoo, etc. Downloads from Yahoo are having some issue recently; hence, in our case we will use combination of Quandl and Morningstar. 
Download Asset Prices

    
Download Treasury rate 

    

Volatility Calculation

Now that we have historical asset prices, we will go ahead and calculate the asset volatility. 

We do this by first calculating the Log returns for each day. Once, we have log returns for each day, we calculate the standard deviation using the ever helpful Pandas' std function. Note, this will provide us with daily standard deviation; hence, we need to annualize it by multiplying it with 252 (i.e. expected number of trading days in an year). Once we have annualized standard deviation, we take square root of it to calculate annualized volatility. 

Below code reflects how easy it is in Pandas:
Calculate annualized volatility from daily asset prices

    

Apply Gaussian Process and perform Simulations

We now have all the required inputs and are ready to apply Gaussian Process to calculate expected asset price using Monte-Carlo simulations.  For each simulation, we calculate expected price using below equation:

                   ST = St * exp(  (Rf− 0.5*σ^2)(T−t) + σϵ√(T−t) )
where,
          ST = Expected asset price at time 
          St  = Current asset price at time t (aka Spot price)
          Rf = Risk free rate or 3-month treasury rate
          σ  = Annualized Volatility
      (T−t) = Time to maturity in years
          ϵ  = Random variable based on Gaussian Distribution

Once, we get expected stock price using above equation, we repeat this calculation for N number of simulations. The only variable changing in each simulation is the Gaussian process; thereby, we representing a continuous time stochastic process, i.e. Wiener process. 

Below Python code performs these Monte-Carlo simulations:
Monte-Carlo simulations and Wiener Process

    
Running Simulations on Tesla Stock (TSLA) for a future date

    

Source-Code

​Full source-code available at my GitHub repository @ ​https://github.com/shashank-khanna/Option-Pricing/blob/master/option_pricing/american_option_pricing.py.

    Author

    I am a passionate, driven polyglot programmer and architect with a knack of solving complex problems in quick and efficient way.  Along with programming, software development, financial products, and management expertise, I also bring skills in statistical modeling, empowering me to work on challenging projects that require combination of software development and quantitative analysis.

    Categories

    All
    American Option Prices
    Black-Scholes Method
    Blockchain
    Bokeh
    Brownian Motion
    Cryptography
    Derivative Pricing
    European Option Prices
    Gaussian Process
    Linear Regression
    Matplotlib
    Monte Carlo Simulations
    Monte-Carlo Simulations
    Numpy
    Ordinary Least Square (OLS)
    Pandas
    Put-Call Parity
    Python
    Sha-256 Hash
    Statistical Analysis
    Stochastic Process
    Stock Analyzer
    Time Series Models
    Wiener Process

    RSS Feed