avatarEthan Johnson-Skinner, MSc

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5599

Abstract

conomical data, employment data and inflation reports)</li></ul><h1 id="e1c5">Stochastic Volatility Models</h1><p id="8ddc">“Stochastic” is defined as randomness stemming from an underlying probability distribution. Stochastic volatility models have a component where the variance is randomly distributed. By using the idea that price movements are stochastic we can introduce a function that itself is inherently stochastic. The equation below is based on geometric Brownian motion where v is not constant and varies in time.</p><figure id="d933"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*-toqSJhwEViL80b4zQgVkA.png"><figcaption>Geometric Brownian Motion Replacing Sigma with v</figcaption></figure><p id="1c65">Since this is the starting point for constant volatility models I will break it down. The three main components are as follows, the change in price is equal to general up/down trend plus some random behavior.</p><p id="6b50">The change in price (S) equals drift multiplied by the Asset price at time (t) multiplied by the change in time plus v(t) (function that models the volatility of S(t)) multiplied by asset price at time (t) multiplied by a standard Wiener process (random).</p><p id="78ab">The main focus for stochastic volatility models is to model variable (v) which is <b>not</b> constant throughout time.</p><figure id="1591"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*YTMRZEcov5PaDmChDftsGQ.png"><figcaption>Stochastic Volatility model framework</figcaption></figure><p id="57ff">The change in (v) is given as two new functions in terms of (v). Where alpha capture trends in (v) and beta captures the randomness.</p><blockquote id="14dd"><p>Using this stochastic volatility framework will be key in the creation of the innovative volatility model</p></blockquote><h2 id="0dc0">GARCH Model</h2><p id="b7f6">The GARCH model is one of the most common volatility models. The Generalized Autoregressive Conditional Heteroscedastic (GARCH) model is given as:</p><figure id="382b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*B2CYAJ-XWwjA0iDQ.png"><figcaption>GARCH</figcaption></figure><p id="5ee9">The GARCH model is an expansion on the ARCH model. In the ARCH(q) process the conditional variance is specified as a linear function of past sample variances only, whereas the GARCH(p, q) process accounts for lagged conditional variances as well.</p><p id="0606">The GARCH(1,1) model is given as</p><figure id="532f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*iLaMo1qeRU-uWp43-AxfNw.png"><figcaption>GARCH(1,1)</figcaption></figure><p id="052d">Below is the implementation of the GARCH model in Python using BTC as the sample data.</p><p id="3a07">Looking back at the GARCH formula the (alpha0) term dictates the mean to which the volatility reverts to.</p><figure id="255b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*sp5nWs5DSnqZxmE9hQP9Og.png"><figcaption></figcaption></figure><h1 id="c7e2">GARCH Implementation in Python</h1><p id="16d7">The implementation in Python for the GARCH model is shown below. In line 20 we are able to control the number of terms for the GARCH model, the defaults are p = 1 & q = 1.</p> <figure id="fa42"> <div> <div>

            <iframe class="gist-iframe" src="/gist/ethan-skinner99/bc367b90fe0fb8076eee090132e06da5.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="e4f0">Using the price change of bitcoin over the last year on the daily time scale. The data for this investigation is fetched using yahoo BTC-USD data from the yfinance API. The testing period contains both sections of prolonged low volatility and high volatility which will be good when testing the various models.</p><figure id="eb6e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*4eVbuehtVajzRf_pPk7bBw.png"><figcaption></figcaption></figure><p id="d413">Plotting the bitcoin volatility (price changes) with the modelled GARCH volatility. The modelled volatility displays mean reverting characteristic where large price changes cause upward spikes and then decay back down towards the mean volatility.</p><div id="a78e"><pre><span class="hljs-attribute">Constant</span> Mean - GARCH Model Results                       ====================================================================Dep. Variable:                  Close   R-squared:                       <span class="hljs-number">0</span>.<span class="hljs-number">000</span> Mean Model:             Constant Mean   Adj. R-squared:                  <span class="hljs-number">0</span>.<span class="hljs-number">000</span> Vol Model:                      GARCH   Log-Likelihood:               -<span class="hljs-number">7205</span>.<span class="hljs-number">30</span> Distribution:                  Normal   AIC:                           <span class="hljs-number">14418</span>.<span class="hljs-number">6</span> Method:            Maximum Likelihood   BIC:                           <span class="hljs-number">14437</span>.<span class="hljs-number">7</span>                                         No. Observations:                  <span class="hljs-number">881</span> Date:                Mon, Sep <span class="hljs-number">26</span> <span class="hljs-number">20</span>xx   Df Residuals:                      <span class="hljs-number">880</span> Time:                        xx:xx:xx   Df Model:              

Options

          <span class="hljs-number">1</span>                                  Mean Model                                  ====================================================================     coef    std err          t      P&gt;|t|      <span class="hljs-number">95</span>.<span class="hljs-number">0</span>% Conf. Int. ---------------------------------------------------------------------------- mu           <span class="hljs-number">280</span>.<span class="hljs-number">6952</span>     <span class="hljs-number">33</span>.<span class="hljs-number">780</span>      <span class="hljs-number">8</span>.<span class="hljs-number">310</span>  <span class="hljs-number">9</span>.<span class="hljs-number">609</span>e-<span class="hljs-number">17</span>                               Volatility Model                               ====================================================================         coef    std err          t      P&gt;|t|       <span class="hljs-number">95</span>.<span class="hljs-number">0</span>% Conf. Int. ---------------------------------------------------------------------------omega        <span class="hljs-number">844</span>.<span class="hljs-number">5496</span>    <span class="hljs-number">729</span>.<span class="hljs-number">040</span>      <span class="hljs-number">1</span>.<span class="hljs-number">158</span>      <span class="hljs-number">0</span>.<span class="hljs-number">247</span> 

<span class="hljs-attribute">alpha</span>[<span class="hljs-number">1</span>] <span class="hljs-number">0</span>.<span class="hljs-number">0438</span> <span class="hljs-number">1</span>.<span class="hljs-number">157</span>e-<span class="hljs-number">02</span> <span class="hljs-number">3</span>.<span class="hljs-number">788</span> <span class="hljs-number">1</span>.<span class="hljs-number">520</span>e-<span class="hljs-number">04</span>
<span class="hljs-attribute">beta</span>[<span class="hljs-number">1</span>] <span class="hljs-number">0</span>.<span class="hljs-number">9562</span> <span class="hljs-number">1</span>.<span class="hljs-number">250</span>e-<span class="hljs-number">02</span> <span class="hljs-number">76</span>.<span class="hljs-number">476</span> <span class="hljs-number">0</span>.<span class="hljs-number">000</span> ====================================================================</pre></div><p id="f478">The output for the GARCH modelling process provides a plethora of information. Let’s begin with the coefficients for our GARCH(1,1) model. Beta is representative of the moving average and controls how the previous volatility impacts the current. When beta > 1 the variance grows to infinity and when beta < 1 it decays with time. Omega is the standard deviation for returns; we are on a daily scale which explains why omega is so high. The alpha term tells us how much the previous period’s volatility to carry forward to today.</p><figure id="db39"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*5VHG0xiIh-oZ8HgELp9A-w.png"><figcaption></figcaption></figure><p id="990d">The input into the GARCH model is the absolute value of the daily price change.</p><h1 id="40b1">Conclusion</h1><p id="995a">This was part one of three introducing stochastic volatility modeling. In the next part, I will expand on the Heston model, and then finally move to an innovative volatility model. Hopefully you have a few takeaways about how the GARCH model works and its benefits. In the next section, I will introduce Heston’s model and explore how we can use it to model BTC-USD price volatility.</p><h1 id="d639">About the author:</h1><p id="c7ff">Ethan Skinner holds a Master’s of Applied Mathematics from Ryerson University, in Toronto, Canada, where he also completed his Bachelor’s in Aerospace Engineering. Ethan has published two academic papers at the IEEE COMSAC 2021 conference.</p><p id="05b3">He was part of the financial mathematics group specializing in statistics, and studied volatility modelling and algorithmic trading in-depth. Ethan previously worked as an engineering professional at Bombardier Aerospace, where he was responsible for modelling the life-cycle costs associated with aircraft maintenance.</p><p id="2db2">I am actively training for triathlon and love fitness.</p><p id="d51b">If you have any suggestions on the topics below let me know</p><ul><li>Data science</li><li>Machine Learning</li><li>Mathematics</li><li>Statistical Modelling</li></ul><p id="cfcb">LinkedIn: <a href="https://www.linkedin.com/in/ethanjohnsonskinner/">https://www.linkedin.com/in/ethanjohnsonskinner/</a></p><p id="1726">Twitter : @Ethan_JS94</p><div id="f518" class="link-block"> <a href="https://ethanskinner94.medium.com/membership"> <div> <div> <h2>Join Medium with my referral link - Ethan Johnson-Skinner, MSc</h2> <div><h3>Read every story from Ethan Johnson-Skinner, MSc (and thousands of other writers on Medium). Your membership fee…</h3></div> <div><p>ethanskinner94.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*gR6xH288QYzQUxw2)"></div> </div> </div> </a> </div><p id="e3a8">Subscribe to DDIntel <a href="https://ddintel.datadriveninvestor.com/">Here</a>.</p><p id="9b51">Join our network here: <a href="https://datadriveninvestor.com/collaborate">https://datadriveninvestor.com/collaborate</a></p></article></body>

Creating a New Stochastic Volatility Model from Scratch (Part 1 of 3)

Introduction to stochastic volatility models (GARCH) and the creation of a new stochastic volatility model for volatility clustering using Bitcoin Price data

Photo by Susan Q Yin on Unsplash

Introduction

Why do we model volatility in financial markets? There exists a simple principle that changes in price movements are clustered together. Large changes in the price of an asset are often followed by other large changes and small changes are accordingly often followed by other small changes.

Moreover, these seemingly random price changes are stochastic in nature. A Stochastic process is defined as a random process. In the financial markets this can be observed as the price movements of an asset.

The Wiener process (Brownian Motion) is the process that is used to model financial markets. Mathematically the Wiener process is defined as W(t) where W(0) = 0 and W(t)-W(s) is a gaussian with N(0,σ).

Each change in the random process is independent. When each change is randomly modeled with a gaussian process with zero mean, the expectation is also zero. Because this is not reflective of a financial market, we introduce drift. Here, drift is defined as a general upward or downward movement in price over time.

Example of Drift in Time Series

Extending the Wiener process with the inclusion of drift, we define the standard model for geometric Brownian motion. Here, drift is the term, μt, and the price movement is X(t).

Wiener Process With Drift

The stochastic differential equation with constant volatility is defined as:

Standard Model for Geometric Brownian Motion

W(t) is a Wiener process, S(t) is the asset price and sigma is the constant volatility.

Historically, in financial markets, volatility has never been constant over time; stochastic volatility models overcome this limitation by varying throughout time.

Introduction to the basics of volatility modelling

To understand the volatility of future returns, we must first define the volatility mathematically so we can build our model.

Interpreting future volatility at k steps ahead, let’s first observe how we can build up volatility.

We have the mean and variance of a given time series. In our case, rᵗ represents the log returns for a given asset. E is defined as the expectation or expected value.

The expectation is simply the weighted mean — or in mathematical terms, the first moment. The variance then becomes the second moment. I will rewrite the variance formula to make it clear why we call this the second moment.

The above expression contains within it the expectation of the expectation, and is called the second moment in statistics. Mathematically, the interpretation of the formula above is: expectation of the difference between the daily log returns and the expectation of all the log returns. In simple terms, the formula is a measure between the daily return and average return.

Using the same framework for the standard deviation we can now look at how the volatility of future returns is formulated.

Let t be the current day and k be some number of future time steps. The above formula is the same as the variance formula with one key difference: future volatility is conditional on the current time step, t. The statement [ht+k|t] says that future volatility is conditional (dependent) on the current volatility. This ties into volatility clustering — the idea that volatility shocks today will influence the expectation of volatility many periods in the future.

With the goal clearly defined we can now define some key principles that we want our volatility forecasting model to consider.

  • Volatility is mean reverting (high volatile periods are followed by low volatile periods)
  • Future volatility is dependent on the current volatility (Volatility Clustering)
  • External variables impact volatility (Company Quarterly reports, Economical data, employment data and inflation reports)

Stochastic Volatility Models

“Stochastic” is defined as randomness stemming from an underlying probability distribution. Stochastic volatility models have a component where the variance is randomly distributed. By using the idea that price movements are stochastic we can introduce a function that itself is inherently stochastic. The equation below is based on geometric Brownian motion where v is not constant and varies in time.

Geometric Brownian Motion Replacing Sigma with v

Since this is the starting point for constant volatility models I will break it down. The three main components are as follows, the change in price is equal to general up/down trend plus some random behavior.

The change in price (S) equals drift multiplied by the Asset price at time (t) multiplied by the change in time plus v(t) (function that models the volatility of S(t)) multiplied by asset price at time (t) multiplied by a standard Wiener process (random).

The main focus for stochastic volatility models is to model variable (v) which is not constant throughout time.

Stochastic Volatility model framework

The change in (v) is given as two new functions in terms of (v). Where alpha capture trends in (v) and beta captures the randomness.

Using this stochastic volatility framework will be key in the creation of the innovative volatility model

GARCH Model

The GARCH model is one of the most common volatility models. The Generalized Autoregressive Conditional Heteroscedastic (GARCH) model is given as:

GARCH

The GARCH model is an expansion on the ARCH model. In the ARCH(q) process the conditional variance is specified as a linear function of past sample variances only, whereas the GARCH(p, q) process accounts for lagged conditional variances as well.

The GARCH(1,1) model is given as

GARCH(1,1)

Below is the implementation of the GARCH model in Python using BTC as the sample data.

Looking back at the GARCH formula the (alpha0) term dictates the mean to which the volatility reverts to.

GARCH Implementation in Python

The implementation in Python for the GARCH model is shown below. In line 20 we are able to control the number of terms for the GARCH model, the defaults are p = 1 & q = 1.

Using the price change of bitcoin over the last year on the daily time scale. The data for this investigation is fetched using yahoo BTC-USD data from the yfinance API. The testing period contains both sections of prolonged low volatility and high volatility which will be good when testing the various models.

Plotting the bitcoin volatility (price changes) with the modelled GARCH volatility. The modelled volatility displays mean reverting characteristic where large price changes cause upward spikes and then decay back down towards the mean volatility.

Constant Mean - GARCH Model Results                       ====================================================================Dep. Variable:                  Close   R-squared:                       0.000 Mean Model:             Constant Mean   Adj. R-squared:                  0.000 Vol Model:                      GARCH   Log-Likelihood:               -7205.30 Distribution:                  Normal   AIC:                           14418.6 Method:            Maximum Likelihood   BIC:                           14437.7                                         No. Observations:                  881 Date:                Mon, Sep 26 20xx   Df Residuals:                      880 Time:                        xx:xx:xx   Df Model:                            1                                  Mean Model                                  ====================================================================     coef    std err          t      P>|t|      95.0% Conf. Int. ---------------------------------------------------------------------------- mu           280.6952     33.780      8.310  9.609e-17                               Volatility Model                               ====================================================================         coef    std err          t      P>|t|       95.0% Conf. Int. ---------------------------------------------------------------------------omega        844.5496    729.040      1.158      0.247 
alpha[1]       0.0438  1.157e-02      3.788  1.520e-04  
beta[1]        0.9562  1.250e-02     76.476      0.000      ====================================================================

The output for the GARCH modelling process provides a plethora of information. Let’s begin with the coefficients for our GARCH(1,1) model. Beta is representative of the moving average and controls how the previous volatility impacts the current. When beta > 1 the variance grows to infinity and when beta < 1 it decays with time. Omega is the standard deviation for returns; we are on a daily scale which explains why omega is so high. The alpha term tells us how much the previous period’s volatility to carry forward to today.

The input into the GARCH model is the absolute value of the daily price change.

Conclusion

This was part one of three introducing stochastic volatility modeling. In the next part, I will expand on the Heston model, and then finally move to an innovative volatility model. Hopefully you have a few takeaways about how the GARCH model works and its benefits. In the next section, I will introduce Heston’s model and explore how we can use it to model BTC-USD price volatility.

About the author:

Ethan Skinner holds a Master’s of Applied Mathematics from Ryerson University, in Toronto, Canada, where he also completed his Bachelor’s in Aerospace Engineering. Ethan has published two academic papers at the IEEE COMSAC 2021 conference.

He was part of the financial mathematics group specializing in statistics, and studied volatility modelling and algorithmic trading in-depth. Ethan previously worked as an engineering professional at Bombardier Aerospace, where he was responsible for modelling the life-cycle costs associated with aircraft maintenance.

I am actively training for triathlon and love fitness.

If you have any suggestions on the topics below let me know

  • Data science
  • Machine Learning
  • Mathematics
  • Statistical Modelling

LinkedIn: https://www.linkedin.com/in/ethanjohnsonskinner/

Twitter : @Ethan_JS94

Subscribe to DDIntel Here.

Join our network here: https://datadriveninvestor.com/collaborate

Algorithmic Trading
Volatility
Statistics
Recommended from ReadMedium