
Creating a Quantitative Investment Portfolio Using Python
Description
Book Introduction
From data collection for quantitative investing to stock selection and portfolio construction, the entire process is covered in one book! While the previous "Creating a Quantitative Investment Portfolio Using R" focused solely on collecting domestic stock data, this book also covers how to collect data on all stocks worldwide. We also covered not only stock selection using quantitative strategies, but also trading methods and backtesting using technical indicators. Finally, we've gone beyond simply choosing which stocks to invest in, and even covered how to automatically trade and rebalance using a brokerage API. |
- You can preview some of the book's contents.
Preview
index
Preface xi
About this book xii
Recommendation xiv
Part I: Learning the Basics of Quant and Programming
CHAPTER 1: Learning About Quants 3
1.1 Data: The Core Material of Quantitative Investment 4
1.2 Why Programming is Necessary for Quantitative Investing 4
1.3 The most popular language, Python 5
1.4 Data Management Standard, SQL 6
CHAPTER 2: Learning Python Basics 8
2.1 Constants and Variables 8
2.2 Data Type 9
2.3 Control Statements 30
2.4 Function 39
2.5 Using Packages 41
CHAPTER 3 Learning Data Analysis 48
3.1 Series 48
3.2 DataFrame 52
3.3 Loading and Saving Data 60
3.4 Reviewing Data Summary Information and Statistics 62
3.5 Handling Missing Values 67
3.6 Handling Indexes 72
3.7 Filtering 74
3.8 Creating a New Column 78
3.9 Merging Data Frames 80
3.10 Data Restructuring 88
3.11 Applying Functions to Data Frames 93
3.12 Group Operations 96
3.13 Handling Time Series Data 103
CHAPTER 4: Learning Data Visualization 110
4.1 Components of a Graph 110
4.2 Visualization using the matplotlib package 111
4.3 Visualization using the pandas package 117
4.4 Visualization using the seaborn package 121
CHAPTER 5: Learning SQL Basics 128
5.1 Creating a Database and Tables 128
5.2 Learning Basic SQL Syntax 133
5.3 Operator 135
5.4 Aggregate Functions 137
5.5 Grouping and Sorting 139
5.6 Views and Subqueries 141
5.7 Functions, Predicates, and Case Expressions 144
5.8 Sets and Joins of Tables 151
5.9 Advanced SQL Processing 156
CHAPTER 6 Connecting to SQL in Python 161
6.1 Connecting to an SQL Database in Python 161
6.2 Reading and Writing Data with Pandas 163
6.3 Implementing the upsert function 165
PART II Data Collection Using Crawling
CHAPTER 7 Web Basics for Crawling 173
7.1 Understanding Encoding 173
7.2 How the Web Works 175
7.3 HTML and CSS 176
CHAPTER 8 Static Crawling Practice 187
8.1 Understanding GET and POST Methods 187
8.2 Crawling Example 190
CHAPTER 9 Dynamic Crawling and Regular Expressions 204
9.1 What is dynamic crawling? 204
9.2 Regular Expressions 216
CHAPTER 10: Collecting Domestic Stock Data 223
10.1 Receiving data based on the most recent business day 223
10.2 Crawling through the Korea Exchange's industry classifications and individual indicators 224
10.3 Crawling sector information based on WICS 235
10.4 Correction Stock Crawl 240
10.5 Financial Statement Crawling 247
10.6 Calculating Value Indicators 256
CHAPTER 11 Collecting Global Stock Data 264
11.1 Using Paid Data Vendors 265
11.2 Collecting Tickers 270
11.3 Stock Price Download 279
11.4 Download Financial Statements 283
CHAPTER 12: Gathering Data for Investment Reference 288
12.1 Collecting Data Using DART's Open API 288
12.2 Download FRED data 297
12.3 Fear & Greed Index 301
PART III Portfolio Construction, Backtesting, and Trading
CHAPTER 13 Stock Selection Using Quantitative Strategies 307
13.1 Understanding Factors 308
13.2 Understanding Beta 308
13.3 Value Strategy 312
13.4 Momentum Strategy 322
13.5 Quality Strategy 331
13.6 Magic Formula 337
13.7 Sector-Neutral Portfolio 346
13.8 Handling Outlier Data and Combining Factors 349
13.9 Multifactor Portfolio 354
CHAPTER 14 Portfolio Construction Strategies 367
14.1 Calculating Returns and Checking Correlations 368
14.2 Maximum Sharpe Ratio Portfolio 369
14.3 Minimum Variance Portfolio 372
14.4 Risk-Balanced Portfolio 380
CHAPTER 15: Technical Indicators for Trading 385
15.1 Installing the TA-Lib Package 385
15.2 Moving Average 387
15.3 Relative Strength Index 389
15.4 Bollinger Bands 391
CHAPTER 16 Backtesting Simulation 393
16.1 bt package 394
16.2 Static Asset Allocation: All-Weather Portfolio 401
16.3 Dynamic Asset Allocation 403
16.4 Trend-Following Strategy Backtest 407
16.5 Mean Reversion Strategy Backtest 415
Function 419 of the 16.6 bt package
CHAPTER 17 Connecting to a Securities Firm's API and Trading 421
17.1 Applying for Simulated Investment and API Services 423
17.2 Obtaining Access Tokens and Hash Keys 427
17.3 Check current stock prices 429
17.4 Ordering Stocks 430
17.5 Stock Balance Inquiry 436
17.6 Scheduling 438
17.7 Portfolio Rebalancing 441
APPENDIXA Downloading and Installing Python 460
Installing Anaconda 460
Using Spider 465
APPENDIX B Downloading and Installing SQL 467
Search 482
About this book xii
Recommendation xiv
Part I: Learning the Basics of Quant and Programming
CHAPTER 1: Learning About Quants 3
1.1 Data: The Core Material of Quantitative Investment 4
1.2 Why Programming is Necessary for Quantitative Investing 4
1.3 The most popular language, Python 5
1.4 Data Management Standard, SQL 6
CHAPTER 2: Learning Python Basics 8
2.1 Constants and Variables 8
2.2 Data Type 9
2.3 Control Statements 30
2.4 Function 39
2.5 Using Packages 41
CHAPTER 3 Learning Data Analysis 48
3.1 Series 48
3.2 DataFrame 52
3.3 Loading and Saving Data 60
3.4 Reviewing Data Summary Information and Statistics 62
3.5 Handling Missing Values 67
3.6 Handling Indexes 72
3.7 Filtering 74
3.8 Creating a New Column 78
3.9 Merging Data Frames 80
3.10 Data Restructuring 88
3.11 Applying Functions to Data Frames 93
3.12 Group Operations 96
3.13 Handling Time Series Data 103
CHAPTER 4: Learning Data Visualization 110
4.1 Components of a Graph 110
4.2 Visualization using the matplotlib package 111
4.3 Visualization using the pandas package 117
4.4 Visualization using the seaborn package 121
CHAPTER 5: Learning SQL Basics 128
5.1 Creating a Database and Tables 128
5.2 Learning Basic SQL Syntax 133
5.3 Operator 135
5.4 Aggregate Functions 137
5.5 Grouping and Sorting 139
5.6 Views and Subqueries 141
5.7 Functions, Predicates, and Case Expressions 144
5.8 Sets and Joins of Tables 151
5.9 Advanced SQL Processing 156
CHAPTER 6 Connecting to SQL in Python 161
6.1 Connecting to an SQL Database in Python 161
6.2 Reading and Writing Data with Pandas 163
6.3 Implementing the upsert function 165
PART II Data Collection Using Crawling
CHAPTER 7 Web Basics for Crawling 173
7.1 Understanding Encoding 173
7.2 How the Web Works 175
7.3 HTML and CSS 176
CHAPTER 8 Static Crawling Practice 187
8.1 Understanding GET and POST Methods 187
8.2 Crawling Example 190
CHAPTER 9 Dynamic Crawling and Regular Expressions 204
9.1 What is dynamic crawling? 204
9.2 Regular Expressions 216
CHAPTER 10: Collecting Domestic Stock Data 223
10.1 Receiving data based on the most recent business day 223
10.2 Crawling through the Korea Exchange's industry classifications and individual indicators 224
10.3 Crawling sector information based on WICS 235
10.4 Correction Stock Crawl 240
10.5 Financial Statement Crawling 247
10.6 Calculating Value Indicators 256
CHAPTER 11 Collecting Global Stock Data 264
11.1 Using Paid Data Vendors 265
11.2 Collecting Tickers 270
11.3 Stock Price Download 279
11.4 Download Financial Statements 283
CHAPTER 12: Gathering Data for Investment Reference 288
12.1 Collecting Data Using DART's Open API 288
12.2 Download FRED data 297
12.3 Fear & Greed Index 301
PART III Portfolio Construction, Backtesting, and Trading
CHAPTER 13 Stock Selection Using Quantitative Strategies 307
13.1 Understanding Factors 308
13.2 Understanding Beta 308
13.3 Value Strategy 312
13.4 Momentum Strategy 322
13.5 Quality Strategy 331
13.6 Magic Formula 337
13.7 Sector-Neutral Portfolio 346
13.8 Handling Outlier Data and Combining Factors 349
13.9 Multifactor Portfolio 354
CHAPTER 14 Portfolio Construction Strategies 367
14.1 Calculating Returns and Checking Correlations 368
14.2 Maximum Sharpe Ratio Portfolio 369
14.3 Minimum Variance Portfolio 372
14.4 Risk-Balanced Portfolio 380
CHAPTER 15: Technical Indicators for Trading 385
15.1 Installing the TA-Lib Package 385
15.2 Moving Average 387
15.3 Relative Strength Index 389
15.4 Bollinger Bands 391
CHAPTER 16 Backtesting Simulation 393
16.1 bt package 394
16.2 Static Asset Allocation: All-Weather Portfolio 401
16.3 Dynamic Asset Allocation 403
16.4 Trend-Following Strategy Backtest 407
16.5 Mean Reversion Strategy Backtest 415
Function 419 of the 16.6 bt package
CHAPTER 17 Connecting to a Securities Firm's API and Trading 421
17.1 Applying for Simulated Investment and API Services 423
17.2 Obtaining Access Tokens and Hash Keys 427
17.3 Check current stock prices 429
17.4 Ordering Stocks 430
17.5 Stock Balance Inquiry 436
17.6 Scheduling 438
17.7 Portfolio Rebalancing 441
APPENDIXA Downloading and Installing Python 460
Installing Anaconda 460
Using Spider 465
APPENDIX B Downloading and Installing SQL 467
Search 482
Detailed image

Into the book
In quantitative investing, a 'quant' refers to a person who calculates the price of a financial product based on a model or makes investments based on this.
It will be easy to understand if you think about it as the word 'quant' being taken from the first letters of 'quantitative', which means 'quantitative'.
Unlike qualitative investment methods, where investors typically analyze industries and companies to determine their value, quantitative investment refers to a quantitative investment method that creates strategies based on mathematics, statistics, and data and then invests based on these strategies.
--- p.3
If you only need data for the US market, using a paid data vendor is also a good option.
There are numerous companies in the US that provide financial data as APIs, and in the case of Tiingo, for just $10 per month, you can receive data on over 40,000 stocks in the US and China in API form.
Not only does this cover delisted stocks, but it also has the advantage of being able to receive data at a speed incomparable to crawling because it uses an API.
There are also numerous data vendors, including Alpha Vantage, Quandl, and Polygon.
Tiingo allows up to 1,000 API requests per day even with a free account, and there's also a package available for Python, so let's use that to collect data.
--- p.265
Rather than investing based on just one factor, you can create a much better portfolio by combining two or more factors. This method is called multifactor.
Among these, the combination of value and quality is a traditionally used method, and a representative example is Joel Greenblatt's 'Magic Formula'.
--- p.337
Backtesting is the process of testing what kind of results would occur if the strategy you are currently considering were executed in the past.
This is a key step in quantitative investing, which involves executing strategies based on past data.
Backtest results allow you to roughly assess the strategy's profit and loss, as well as its various risks, and also help you understand which sections of the strategy performed well or poorly.
By continuing to invest quantitatively based on this understanding, you can develop an objective perspective on the reasons for short-term poor performance, allowing you to confidently pursue your strategy.
It will be easy to understand if you think about it as the word 'quant' being taken from the first letters of 'quantitative', which means 'quantitative'.
Unlike qualitative investment methods, where investors typically analyze industries and companies to determine their value, quantitative investment refers to a quantitative investment method that creates strategies based on mathematics, statistics, and data and then invests based on these strategies.
--- p.3
If you only need data for the US market, using a paid data vendor is also a good option.
There are numerous companies in the US that provide financial data as APIs, and in the case of Tiingo, for just $10 per month, you can receive data on over 40,000 stocks in the US and China in API form.
Not only does this cover delisted stocks, but it also has the advantage of being able to receive data at a speed incomparable to crawling because it uses an API.
There are also numerous data vendors, including Alpha Vantage, Quandl, and Polygon.
Tiingo allows up to 1,000 API requests per day even with a free account, and there's also a package available for Python, so let's use that to collect data.
--- p.265
Rather than investing based on just one factor, you can create a much better portfolio by combining two or more factors. This method is called multifactor.
Among these, the combination of value and quality is a traditionally used method, and a representative example is Joel Greenblatt's 'Magic Formula'.
--- p.337
Backtesting is the process of testing what kind of results would occur if the strategy you are currently considering were executed in the past.
This is a key step in quantitative investing, which involves executing strategies based on past data.
Backtest results allow you to roughly assess the strategy's profit and loss, as well as its various risks, and also help you understand which sections of the strategy performed well or poorly.
By continuing to invest quantitatively based on this understanding, you can develop an objective perspective on the reasons for short-term poor performance, allowing you to confidently pursue your strategy.
--- p.393
Publisher's Review
The only book written by a real quant, covering everything from how to collect stock data to stock selection using quantitative strategies and automated trading and rebalancing using brokerage APIs!
Programming allows even the average investor to collect financial data and construct a portfolio! This book covers not only domestic stock data but also methods for collecting data on all stocks worldwide. It also covers stock selection using quantitative strategies, as well as trading methods and backtesting using technical indicators.
Finally, we've gone beyond simply choosing which stocks to invest in, and even covered how to automatically trade and rebalance using a brokerage API.
Readers will be able to use Python to collect and process financial data, develop quantitative models, analyze portfolios, and perform automated trading, including techniques used by professional investors.
Programming allows even the average investor to collect financial data and construct a portfolio! This book covers not only domestic stock data but also methods for collecting data on all stocks worldwide. It also covers stock selection using quantitative strategies, as well as trading methods and backtesting using technical indicators.
Finally, we've gone beyond simply choosing which stocks to invest in, and even covered how to automatically trade and rebalance using a brokerage API.
Readers will be able to use Python to collect and process financial data, develop quantitative models, analyze portfolios, and perform automated trading, including techniques used by professional investors.
GOODS SPECIFICS
- Date of issue: February 17, 2023
- Page count, weight, size: 500 pages | 994g | 188*257*24mm
- ISBN13: 9791192469829
- ISBN10: 1192469828
You may also like
카테고리
korean
korean