13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

63

( )

yi

log ∼ t(ν, 0, exp(−2s i )) (6.4)

y i−1

Thus the full stochastic volatility model is specified by four parameters, each with an associated

prior:

σ ∼ Exponential(50) (6.5)

ν ∼ Exponential(0.1) (6.6)

s i ∼ N (s i−1 , σ −2 ) (6.7)

( )

yi

log ∼ t(ν, 0, exp(−2s i )) (6.8)

y i−1

PyMC3 will now be used to fit this model to a set of historical financial asset pricing data.

6.3 PyMC3 Implementation

The first task is to import the necessary libraries used in the stochastic volatility model. This

consists of NumPy, SciPy, Pandas, Matplotlib and Seaborn. These libraries are used for data

import, manipulation and plotting.

As in previous chapters the PyMC3 library is used to carry out the MCMC procedure. The

GaussianRandomWalk model is imported and is used to model the returns of the daily equity

prices:

# pymc3_bayes_stochastic_vol.py

import datetime

import pprint

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import pandas_datareader as pdr

import pymc3 as pm

from pymc3.distributions.timeseries import GaussianRandomWalk

import seaborn as sns

The next step is to download a suitable equities price series. In this example the historical

prices of Amazon will be downloaded from Yahoo Finance.

6.3.1 Obtaining the Price History

The returns of Amazon, Inc. (AMZN) are downloaded from Yahoo Finance using the pandas_datareader

module. However, it is straightforward to utilise S&P500, FTSE100 or any other asset pricing

data.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!