Expand description
Rust implementations of the methods in Marcos López de Prado, Advances in Financial Machine Learning (Wiley, 2018; “AFML”), and of the portfolio and HPC tooling around them.
Each module maps to one or more AFML chapters, and its documentation cites the section and
snippet it implements. Where a function departs from the book or from the mlfinlab
reference it mirrors, the item’s documentation says so.
§Modules by AFML chapter
| Chapter | Modules |
|---|---|
| 2. Financial data structures | data_structures, filters, etf_trick |
| 3. Labeling | labeling, util::volatility |
| 4. Sample weights | sampling, sample_weights, sb_bagging |
| 5. Fractionally differentiated features | fracdiff |
| 6. Ensemble methods | ensemble_methods |
| 7. Cross-validation in finance | cross_validation |
| 8. Feature importance | feature_importance, fingerprint |
| 9. Hyper-parameter tuning | hyperparameter_tuning |
| 10. Bet sizing | bet_sizing, ef3m |
| 11–12. Backtesting, walk-forward and CPCV | backtesting_engine |
| 13. Backtesting on synthetic data | synthetic_backtesting |
| 14. Backtest statistics | backtest_statistics, risk_metrics |
| 15. Understanding strategy risk | strategy_risk |
| 16. Machine learning asset allocation | hrp, hcaa, onc, cla, portfolio_optimization |
| 17. Structural breaks | structural_breaks |
| 18–19. Entropy and microstructural features | microstructural_features, codependence |
| 20. Multiprocessing and vectorization | hpc_parallel, streaming_hpc |
| 21. Brute force and quantum computers | dynamic_allocation, combinatorial_optimization |
pipeline strings several of these together (events, signals, portfolio, risk,
backtest) for research workflows, data_processing loads, cleans and calendar-aligns
OHLCV bars, and util holds shared primitives such as util::fast_ewma and the common
util::InputError.
§Conventions
- Series are ordered oldest first. Whether a function wants prices, log prices or returns, and whether returns are per period or annualised, is stated on each function.
- Fallible functions return a typed error per module (or
util::InputError) rather than panicking; any remaining reachable panic is listed under# Panicson the item. - Randomised functions take a seed or a generator, or have a variant that does, so that results can be reproduced.
The same material, with worked examples and caveats, is on the documentation site’s module pages, which these docs follow.
use openquant::fracdiff::frac_diff_ffd;
// Fractional differencing of order 1 is the ordinary first difference (AFML Snippet 5.3).
let diffed = frac_diff_ffd(&[1.0, 2.0, 4.0, 7.0], 1.0, 1e-5);
assert!(diffed[0].is_nan());
assert_eq!(&diffed[1..], &[1.0, 2.0, 3.0]);Modules§
- backtest_
statistics - Backtest statistics (AFML chapter 14): Sharpe ratios with their uncertainty, plus drawdown, concentration and holding-period statistics.
- backtesting_
engine - Walk-forward, purged cross-validation and combinatorial purged cross-validation (CPCV) backtests (AFML Chapters 11 and 12).
- bet_
sizing - Bet sizing (AFML chapter 10): turning a prediction into a position size.
- cla
- The Critical Line Algorithm (Markowitz, 1956; Bailey and López de Prado, 2013), the mean-variance benchmark of AFML chapter 16.
- codependence
- Codependence measures between two series: correlation-based distances, distance correlation, mutual information and variation of information.
- combinatorial_
optimization - AFML Chapter 21: brute-force and combinatorial optimization adapters.
- cross_
validation - Purged k-fold cross-validation with an embargo, and combinatorial purged cross-validation (AFML Chapter 7 and §12.4).
- data_
processing - OHLCV data hygiene: deduplication, calendar alignment and a data-quality report.
- data_
structures - Financial data structures (AFML chapter 2): time, tick, volume, dollar, run and imbalance bars built from a stream of trades.
- dynamic_
allocation - Dynamic portfolio allocation by exhaustive integer search (AFML Chapter 21).
- ef3m
- EF3M: fit a mixture of two Gaussians by matching its raw moments exactly.
- ensemble_
methods - Ensemble-method diagnostics aligned to AFML Chapter 6.
- etf_
trick - The ETF trick and futures roll gaps (AFML §2.4.1 and §2.4.3, Snippet 2.2).
- feature_
importance - Feature importance for models validated on purged folds (AFML Chapter 8).
- filters
- Event-sampling filters: the symmetric CUSUM filter (AFML §2.5.2.1, Snippet 2.4) and a rolling z-score filter ported from mlfinlab.
- fingerprint
- Model fingerprints (Li, Turkington and Yazdani, 2020): decompose what a fitted model has learned into linear, non-linear and pairwise-interaction effects per feature.
- fracdiff
- Fractional differentiation (AFML chapter 5).
- hcaa
- Hierarchical Clustering-based Asset Allocation (HCAA): split weight down a hierarchical cluster tree with a choice of risk measure.
- hpc_
parallel - AFML Chapter 20: multiprocessing and vectorization utilities.
- hrp
- Hierarchical Risk Parity (AFML chapter 16, Snippets 16.1–16.4).
- hyperparameter_
tuning - Leakage-aware hyperparameter search (AFML chapter 9).
- labeling
- Triple-barrier labeling and meta-labeling (AFML chapter 3).
- microstructural_
features - Market-microstructure features (AFML Chapter 19) and entropy features (AFML Chapter 18).
- onc
- Optimal Number of Clusters (ONC): partition a correlation matrix with k-means, choosing the number of clusters by silhouette quality.
- pipeline
- End-to-end mid-frequency research pipeline: CUSUM events, bet sizing, a max-Sharpe portfolio, tail-risk metrics and a single-asset backtest in one call.
- portfolio_
optimization - Mean-variance portfolio allocation with weight bounds: inverse variance, minimum volatility, maximum Sharpe ratio, and minimum risk for a target return.
- risk_
metrics - Historical (non-parametric) risk measures: portfolio variance, value at risk, expected shortfall and conditional drawdown at risk.
- sample_
weights - Training sample weights for overlapping labels (AFML Chapter 4).
- sampling
- Label concurrency, average uniqueness and the sequential bootstrap (AFML chapter 4).
- sb_
bagging - Bagging ensembles whose bootstrap samples are drawn with the sequential bootstrap (AFML §4.5, §4.5.1; bagging per §6.3 and Breiman, 1996).
- strategy_
risk - Strategy-risk diagnostics aligned to AFML Chapter 15.
- streaming_
hpc - AFML Chapter 22: streaming analytics utilities for low-latency early warning.
- structural_
breaks - Structural break tests (AFML chapter 17).
- synthetic_
backtesting - Synthetic-data backtesting utilities aligned to AFML Chapter 13.
- util
- Small building blocks shared across modules: the EWMA primitive, descriptive statistics, volatility estimators and the common invalid-argument error.