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.

50

Var(y) = V (E(y)) = V (g −1 (Xβ)) (5.7)

In the frequentist setting, as with ordinary linear regression above, the unknown β coefficients

are estimated via a maximum likelihood approach.

I’m not going to discuss GLMs in depth here as they are not the focus of the chapter or the

book. We are interested in them because we will be using the glm module from PyMC3, which

was written by Thomas Wiecki[102] and others, in order to easily specify our Bayesian linear

regression.

5.3.2 Simulating Data and Fitting the Model with PyMC3

Before we utilise PyMC3 to specify and sample a Bayesian model, we need to simulate some

noisy linear data. The following snippet carries this out, which is modified and extended from

Jonathan Sedar’s post[90]:

import numpy as np

import pandas as pd

import seaborn as sns

sns.set(style="darkgrid", palette="muted")

def simulate_linear_data(N, beta_0, beta_1, eps_sigma_sq):

"""

Simulate a random dataset using a noisy

linear process.

N: Number of data points to simulate

beta_0: Intercept

beta_1: Slope of univariate predictor, X

"""

# Create a pandas DataFrame with column ’x’ containing

# N uniformly sampled values between 0.0 and 1.0

df = pd.DataFrame(

{"x":

np.random.RandomState(42).choice(

map(

lambda x: float(x)/100.0,

np.arange(100)

), N, replace=False

)

}

)

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

Saved successfully!

Ooh no, something went wrong!