13.08.2022 Views

advanced-algorithmic-trading

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2

3.5.1 Beta Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

3.5.2 Why Is A Beta Prior Conjugate to the Bernoulli Likelihood? . . . . . . . 30

3.5.3 Multiple Ways to Specify a Beta Prior . . . . . . . . . . . . . . . . . . . . 30

3.6 Using Bayes’ Rule to Calculate a Posterior . . . . . . . . . . . . . . . . . . . . . . 31

4 Markov Chain Monte Carlo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

4.1 Bayesian Inference Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

4.2 Why Markov Chain Monte Carlo? . . . . . . . . . . . . . . . . . . . . . . . . . . 36

4.2.1 Markov Chain Monte Carlo Algorithms . . . . . . . . . . . . . . . . . . . 37

4.3 The Metropolis Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

4.4 Introducing PyMC3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4.5 Inferring a Binomial Proportion with Markov Chain Monte Carlo . . . . . . . . . 38

4.5.1 Inferring a Binonial Proportion with Conjugate Priors Recap . . . . . . . 39

4.5.2 Inferring a Binomial Proportion with PyMC3 . . . . . . . . . . . . . . . . 40

4.6 Bibliographic Note . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

5 Bayesian Linear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

5.1 Frequentist Linear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

5.2 Bayesian Linear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

5.3 Bayesian Linear Regression with PyMC3 . . . . . . . . . . . . . . . . . . . . . . . 49

5.3.1 What are Generalised Linear Models? . . . . . . . . . . . . . . . . . . . . 49

5.3.2 Simulating Data and Fitting the Model with PyMC3 . . . . . . . . . . . . 50

5.4 Bibliographic Note . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

5.5 Full Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

6 Bayesian Stochastic Volatility Model . . . . . . . . . . . . . . . . . . . . . . . . 59

6.1 Stochastic Volatility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

6.2 Bayesian Stochastic Volatility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

6.3 PyMC3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

6.3.1 Obtaining the Price History . . . . . . . . . . . . . . . . . . . . . . . . . . 63

6.3.2 Model Specification in PyMC3 . . . . . . . . . . . . . . . . . . . . . . . . 65

6.3.3 Fitting the Model with NUTS . . . . . . . . . . . . . . . . . . . . . . . . . 65

6.4 Full Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

III Time Series Analysis 71

7 Introduction to Time Series Analysis . . . . . . . . . . . . . . . . . . . . . . . . 73

7.1 What is Time Series Analysis? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

7.2 How Can We Apply Time Series Analysis in Quantitative Finance? . . . . . . . . 74

7.3 Time Series Analysis Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

7.4 Time Series Analysis Roadmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

7.5 How Does This Relate to Other Statistical Tools? . . . . . . . . . . . . . . . . . . 76

8 Serial Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

8.1 Expectation, Variance and Covariance . . . . . . . . . . . . . . . . . . . . . . . . 77

8.1.1 Example: Sample Covariance in R . . . . . . . . . . . . . . . . . . . . . . 78

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

Saved successfully!

Ooh no, something went wrong!