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.

42

plt.plot(

x, stats.beta.pdf(x, alpha_post, beta_post),

label=’Posterior (Analytic)’, color="green"

)

# Update the graph labels

plt.legend(title="Parameters", loc="best")

plt.xlabel("$\\theta$, Fairness")

plt.ylabel("Density")

plt.show()

When the code is executed the following output is given:

Applied logodds-transform to theta and added transformed theta_logodds to

model.

[----- 14% ] 14288 of 100000 complete in 0.5 sec

[---------- 28% ] 28857 of 100000 complete in 1.0 sec

[---------------- 43% ] 43444 of 100000 complete in 1.5 sec

[-----------------58%-- ] 58052 of 100000 complete in 2.0 sec

[-----------------72%------- ] 72651 of 100000 complete in 2.5 sec

[-----------------87%------------- ] 87226 of 100000 complete in 3.0 sec

[-----------------100%-----------------] 100000 of 100000 complete in 3.4 sec

Clearly, the sampling time will depend upon the speed of your computer.

output of the analysis is given in Figure 4.2:

The graphical

Figure 4.2: Comparison of the analytic and MCMC-sampled posterior belief distributions of the

fairness θ, overlaid with the prior belief

In this particular case of a single-parameter model, with 100,000 samples, the convergence

of the Metropolis algorithm is extremely good. The histogram closely follows the analytically

calculated posterior distribution, as we would expect. In a relatively simple model such as this

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

Saved successfully!

Ooh no, something went wrong!