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.

52

Figure 5.1: Simulation of noisy linear data via Numpy, pandas and seaborn

Calculates the Markov Chain Monte Carlo trace of

a Generalised Linear Model Bayesian linear regression

model on supplied data.

df: DataFrame containing the data

iterations: Number of iterations to carry out MCMC for

"""

# Use PyMC3 to construct a model context

basic_model = pm.Model()

with basic_model:

# Create the glm using the Patsy model syntax

# We use a Normal distribution for the likelihood

pm.glm.glm("y ~ x", df, family=pm.glm.families.Normal())

# Use Maximum A Posteriori (MAP) optimisation

# as initial value for MCMC

start = pm.find_MAP()

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

Saved successfully!

Ooh no, something went wrong!