Description
Expert guide on using AI to supercharge traders' productivity, optimize portfolios, and suggest new trading strategies
Generative AI for Trading and Asset Management is an essential guide to understand how generative AI has emerged as a transformative force in the realm of asset management, particularly in the context of trading, due to its ability to analyze vast datasets, identify intricate patterns, and suggest complex trading strategies. Practically, this book explains how to utilize various types of AI: unsupervised learning, supervised learning, reinforcement learning, and large language models to suggest new trading strategies, manage risks, optimize trading strategies and portfolios, and generally improve the productivity of algorithmic and discretionary traders alike. These techniques converge into an algorithm to trade on the Federal Reserve chair's press conferences in real time.
Written by Hamlet Medina, chief data scientist Criteo, and Ernie Chan, founder of QTS Capital Management and Predictnow.ai, this book explores topics including:
- How large language models and other machine learning techniques can improve productivity of algorithmic and discretionary traders from ideation, signal generations, backtesting, risk management, to portfolio optimization
- The pros and cons of tree-based models vs neural networks as they relate to financial applications. How regularization techniques can enhance out of sample performance
- Comprehensive exploration of the main families of explicit and implicit generative models for modeling high-dimensional data, including their advantages and limitations in model representation and training, sampling quality and speed, and representation learning.
- Techniques for combining and utilizing generative models to address data scarcity and enhance data augmentation for training ML models in financial applications like market simulations, sentiment analysis, risk management, and more.
- Application of generative AI models for processing fundamental data to develop trading signals.
- Exploration of efficient methods for deploying large models into production, highlighting techniques and strategies to enhance inference efficiency, such as model pruning, quantization, and knowledge distillation.
- Using existing LLMs to translate Federal Reserve Chair's speeches to text and generate trading signals.
Generative AI for Trading and Asset Management earns a well-deserved spot on the bookshelves of all asset managers seeking to harness the ever-changing landscape of AI technologies to navigate financial markets.
Table of Contents
Preface xv
Acknowledgments xix
About the Authors xxi
Part I Generative AI for Trading and Asset Management: A No-code Introduction 1
Chapter 1 No-code Generative AI for Basic Quantitative Finance 3
1.1 Retrieving Historical Market Data 4
1.2 Computing Sharpe Ratio 7
1.3 Data Formatting and Analysis 8
1.4 Translating Matlab Codes to Python Codes 11
1.5 Conclusion 16
Chapter 2 No-code Generative AI for Trading Strategies Development 17
2.1 Creating Codes from a Strategy Specification 19
2.2 Summarizing a Trading Strategy Paper and Creating Backtest Codes from It 34
2.3 Searching for a Portfolio Optimization Algorithm Based on Machine Learning 45
2.4 Explore Options Term Structure Arbitrage Strategies 50
2.5 Conclusion 64
2.6 Exercises 66
2A.1 Computing Next-day’s Return 67
2A.2 Uploading the Fama-French Factors 68
2A.3 Combining Fama-French Factors with Next-day’s Returns 68
Chapter 3 Whirlwind Tour of ML in Asset Management 71
3.1 Unsupervised Learning 72
3.2 Supervised Learning 77
3.3 Deep Reinforcement Learning 99
3.4 Data Engineering 100
3.5 Feature Engineering 102
3.6 Conclusion 106
Part II Deep Generative Models for Trading and Asset Management 107
Chapter 4 Understanding Generative AI 109
4.1 Why Generative Models 110
4.2 Difference with Discriminative Models 110
4.3 How Can We Use Them? 111
4.4 Illustrating Generative Models with ChatGPT 113
4.5 Hybrid Modeling: Combining Generative and Discriminative Models 119
4.6 Taxonomy of Generative Models 123
4.7 Conclusion 124
Chapter 5 Deep Autoregressive Models for Sequence Modeling 125
5.1 Representation Complexity 126
5.2 Representation and Complexity Reduction 127
5.3 A Short Tour of Key Model Families 128
5.4 Model Fitting 155
5.5 Conclusions 157
Chapter 6 Deep Latent Variable Models 159
6.1 Introduction 160
6.2 Latent Variable Models 162
6.3 Examples of Traditional Latent Variable Models 162
6.4 Learning 171
6.5 Variational Autoencoder (VAE) 176
6.6 VAEs for Sequential Data and Time Series 177
6.7 Conclusion 181
Chapter 7 Flow Models 183
7.1 Introduction 183
7.2 Model Training 185
7.3 Linear Flows 185
7.4 Designing Nonlinear Flows 187
7.5 Coupling Flows 188
7.6 Autoregressive Flows 195
7.7 Continuous Normalizing Flows 195
7.8 Modeling Financial Time Series with Flow Models 196
7.9 Conclusion 199
Chapter 8 Generative Adversarial Networks 201
8.1 Introduction 202
8.2 Training 204
8.3 Some Theoretical Insight in GANs 208
8.4 Why Is GAN Training Hard? Improving GAN Training Techniques 209
8.5 Wasserstein GAN (WGAN) 211
8.6 Extending GANs for Time Series 214
8.7 Conclusion 215
Chapter 9 Leveraging LLMs for Sentiment Analysis in Trading 217
9.1 Sentiment Analysis in Fed Press Conference Speeches Using Large Language Models 217
9.2 Data: Video + Market Prices 221
9.3 Speech-to-text Conversion 221
9.4 Sentiment Analysis 225
9.5 Experiment Results 232
9.6 Conclusion 234
Chapter 10 Efficient Inference 235
10.1 Introduction 235
10.2 Scaling Large Language Models: High Performance, High Computational Cost, and Emergent Abilities 236
10.3 Making FinBERT Faster 240
10.4 Model Quantization 247
10.5 Customizing Your LLM: Adapting Models to Your Needs 252
10.6 Conclusions 256
Chapter 11 Afterword 257
11.1 Diffusion Models 260
11.2 Combining Generative Model Variants 260
11.3 LLMs as Financial Advisors 261
References 263
Appendix 271
A.1 Retrieving Adjusted Closing Prices and Computing Daily Returns 271
A.2 Installing Python 273
A.2.1 Step 1: Download Python 273
A.2.2 Step 2: Install Python 274
A.2.3 Step 3: Set Up a Virtual Environment (Optional but Recommended) 274
A.2.4 Step 4: Install Packages with pip 274
A.2.5 Step 5: Consider an Integrated Development Environment (IDE) 274
A.2.6 Additional Tips 275
A.3 Plotting the Risk-free-rate over the Years 276
A.4 Computing the Sharpe Ratio of SPY 278
A.5 Matlab Code for Computing Efficient Frontier and Finding the Tangency Portfolio 280
Index 283