给大家补充点目录,方便大家更好的了解书的内容
Contents
I Introduction 1
1 Introduction To Advanced Algorithmic Trading . . . . . . . . . . . . . . . . . 3
1.1 The Hunt for Alpha . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Why Time Series Analysis, Bayesian Statistics and Machine Learning? . . . . . . 3
1.2.1 Bayesian Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.2 Time Series Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.3 Machine Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.3 How Is The Book Laid Out? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4 Required Technical Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4.1 Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4.2 Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5 How Does This Book Differ From "Successful Algorithmic Trading"? . . . . . . . 8
1.6 Software Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6.1 Installing Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6.2 Installing R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.7 QSTrader Backtesting Simulation Software . . . . . . . . . . . . . . . . . . . . . 9
1.7.1 Alternatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.8 Where to Get Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
II Bayesian Statistics 11
2 Introduction to Bayesian Statistics . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1 What is Bayesian Statistics? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.1 Frequentist vs Bayesian Examples . . . . . . . . . . . . . . . . . . . . . . 14
2.2 Applying Bayes’ Rule for Bayesian Inference . . . . . . . . . . . . . . . . . . . . . 17
2.3 Coin-Flipping Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3 Bayesian Inference of a Binomial Proportion . . . . . . . . . . . . . . . . . . . 23
3.1 The Bayesian Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.2 Assumptions of the Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.3 Recalling Bayes’ Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.4 The Likelihood Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.4.1 Bernoulli Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.4.2 Bernoulli Likelihood Function . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4.3 Multiple Flips of the Coin . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.5 Quantifying our Prior Beliefs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
12
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 . . . . . . . . . . . . . . . . . . . . . . 783
8.2 Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
8.2.1 Example: Sample Correlation in R . . . . . . . . . . . . . . . . . . . . . . 80
8.3 Stationarity in Time Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
8.4 Serial Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
8.5 The Correlogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
8.5.1 Example 1 - Fixed Linear Trend . . . . . . . . . . . . . . . . . . . . . . . 84
8.5.2 Example 2 - Repeated Sequence . . . . . . . . . . . . . . . . . . . . . . . 84
8.6 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
9 Random Walks and White Noise Models . . . . . . . . . . . . . . . . . . . . . . 87
9.1 Time Series Modelling Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
9.2 Backward Shift and Difference Operators . . . . . . . . . . . . . . . . . . . . . . 88
9.3 White Noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
9.3.1 Second-Order Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
9.3.2 Correlogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
9.4 Random Walk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
9.4.1 Second-Order Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
9.4.2 Correlogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
9.4.3 Fitting Random Walk Models to Financial Data . . . . . . . . . . . . . . 93
10 Autoregressive Moving Average Models . . . . . . . . . . . . . . . . . . . . . . 97
10.1 How Will We Proceed? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
10.2 Strictly Stationary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
10.3 Akaike Information Criterion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
10.4 Autoregressive (AR) Models of order p . . . . . . . . . . . . . . . . . . . . . . . . 99
10.4.1 Rationale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
10.4.2 Stationarity for Autoregressive Processes . . . . . . . . . . . . . . . . . . 100
10.4.3 Second Order Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
10.4.4 Simulations and Correlograms . . . . . . . . . . . . . . . . . . . . . . . . . 102
10.4.5 Financial Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
10.5 Moving Average (MA) Models of order q . . . . . . . . . . . . . . . . . . . . . . . 111
10.5.1 Rationale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
10.5.2 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
10.5.3 Second Order Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
10.5.4 Simulations and Correlograms . . . . . . . . . . . . . . . . . . . . . . . . . 113
10.5.5 Financial Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
10.5.6 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
10.6 Autogressive Moving Average (ARMA) Models of order p, q . . . . . . . . . . . . 124
10.6.1 Bayesian Information Criterion . . . . . . . . . . . . . . . . . . . . . . . . 125
10.6.2 Ljung-Box Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
10.6.3 Rationale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
10.6.4 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
10.6.5 Simulations and Correlograms . . . . . . . . . . . . . . . . . . . . . . . . . 126
10.6.6 Choosing the Best ARMA(p,q) Model . . . . . . . . . . . . . . . . . . . . 130
10.6.7 Financial Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1324
10.7 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
|