NumPy & Pandas Syllabus for Quant Trading
§ NUMPY AND PANDAS IN QUANTITATIVE TRADING
Course Syllabus
1. Introduction
2. NumPy Core Syntax (1)
2.1. Basic Data Structures
2.1.1. Creating Arrays
Common methods for creating arrays, along with several built-in array types frequently used in quantitative finance.
2.1.2. Adding, Deleting, and Modifying Elements
How to append, insert, delete, and modify elements in an array?
2.1.3. Indexing, Slicing, and Searching
Introduces indexing, slicing, searchsorted, etc.
2.1.4. Inspecting Arrays
2.2. Array Operations
2.2.1. Dimensionality Increase
2.2.2. Dimensionality Reduction
2.2.3. Transposition
3. NumPy Core Syntax (2)
3.1. Structured Arrays
3.2. Mathematical Operations
3.2.1. Logical Operations and Comparisons
3.2.2. Set Operations
3.2.3. Mathematical and Statistical Functions
Matrix operations, as well as statistical functions such as mean, variance, covariance, and percentiles.
3.3. Type Conversion and Typing
In-depth understanding of NumPy data types and conversions, along with the typing library, to help write robust code.
4. NumPy Core Syntax (3)
4.1. Handling Data with np.nan
Data obtained from third parties may contain np.nan values; technical indicator values during the warm-up period are often np.nan. This section introduces np.isnan, nanmean, nanmax, and other nan* functions for calculating mean or max when data contains None or np.nan.
4.2. Random Numbers and Sampling
Random number generation and sampling are high-frequency operations in quantitative finance, particularly useful for synthetic data generation.
4.3. I/O Operations
Introduces how to read and save CSV files and other I/O operations.
4.4. Dates and Times
How to convert time and date formats from market data obtained via other libraries?
4.5. String Operations
How to perform string searches and other operations within NumPy arrays?
5. NumPy Quantitative Finance Use Cases
5.1. Continuous Value Statistics
Example: How to efficiently identify consecutive price limits (limit-up/limit-down), N consecutive bullish/bearish days, and calculate streaks in Connor’s RSI.
5.2. cumsum and Intraday Average Price Line Calculation
The intraday average price line is crucial for intraday trading. Generally, if the price fails to break the average line twice during an attack, it signals an intraday buy (or sell). How do we calculate this average line?
5.3. Moving Average Calculation
How to quickly calculate moving averages using NumPy? Introduces a convolution algorithm.
5.4. Rational Selection of Adaptive Parameters
Often, adaptive parameters are required. How to select them? Percentiles are often a good solution.
5.5. Calculating Maximum Drawdown
With experience, one can identify the major rebound on February 7th. On rebound days, we seek stocks with the largest declines. How to select them?
5.6. Determining Long-Term Trends for Individual Stocks
Do not buy stocks with long-term bearish trends. The key is how to determine this. This section introduces polynomial regression.
5.7. Alpha101 Function Routines
Alpha101 contains several basic functions on which factors are built. How to implement them efficiently?
5.8. Finding Similar Candlestick Patterns
Introduces corrcoef and correlate.
5.9. Asset Portfolio Return and Volatility Example
Starts with randomly generating several assets, then calculates expected return and volatility. This is one of the high-frequency application scenarios.
6. NumPy High-Performance Programming Practices
6.1. Broadcasting
In-depth exploration of NumPy’s efficient underlying principles.
6.2. Using NumExpr
6.3. Enabling Multithreading
6.4. Using the Bottleneck Library
6.5. Other Alternatives to NumPy
7. Pandas Core Syntax (1)
7.1. Basic Data Structures
7.1.1. Series
7.1.2. Creating DataFrames
7.1.3. Rapid Exploration of DataFrames
Index, info, describe, columns, head, tail, etc.
7.1.4. Merging and Joining DataFrames
7.1.5. Deleting Rows and Columns
7.1.6. Indexing, Reading, and Modifying
Introduces indexing and data selection in Pandas.
7.1.7. Transposition
7.1.8. Resampling
Intraday real-time minute-level data is surprisingly expensive. Therefore, we need to synthesize it from tick-level data ourselves. This is resampling.
8. Pandas Core Syntax (2)
8.1. Logical Operations and Comparisons
The DataFrame contains the features we extracted. How to select the top 30 columns with the highest PE and lowest PB?
8.2. Groupby Operations
The factor analysis data table contains industry labels and each company’s PE value. How to select the top 5 stocks with the strongest PE in each industry?
8.3. Multi-Index and Advanced Indexing
One of the more difficult concepts in Pandas.
8.4. Window Functions
Used to calculate moving averages and other indicators with sliding windows.
8.5. Mathematical Operations and Statistics
Mean, variance, covariance, percentile, diff, pct_change, rank, and other statistical functions, forming the foundation of quantitative finance.
9. Pandas Core Syntax (3)
9.1. Data Preprocessing
What to do during factor analysis preprocessing, such as handling missing values, outlier clipping, and deduplication?
9.2. I/O Operations
How to read data from CSVs, web pages, databases, Parquet files, etc.
9.2.1. CSV
Beyond basic operations, we will also introduce how to accelerate CSV reading.
9.2.2. PKL and HDF5
9.2.3. Parquet
9.2.4. HTML and MD
12.5. Other Alternatives to Pandas
12.5.1. Modin
One line of code to replace Pandas, gaining multi-core and memory-unlimited computing capabilities.
12.5.2. Polars
The fastest table solution.
12.5.3. Dask
Distributed table processing, capable of running on thousands of nodes.