Skip to main content

Crate openquant

Crate openquant 

Source
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

ChapterModules
2. Financial data structuresdata_structures, filters, etf_trick
3. Labelinglabeling, util::volatility
4. Sample weightssampling, sample_weights, sb_bagging
5. Fractionally differentiated featuresfracdiff
6. Ensemble methodsensemble_methods
7. Cross-validation in financecross_validation
8. Feature importancefeature_importance, fingerprint
9. Hyper-parameter tuninghyperparameter_tuning
10. Bet sizingbet_sizing, ef3m
11–12. Backtesting, walk-forward and CPCVbacktesting_engine
13. Backtesting on synthetic datasynthetic_backtesting
14. Backtest statisticsbacktest_statistics, risk_metrics
15. Understanding strategy riskstrategy_risk
16. Machine learning asset allocationhrp, hcaa, onc, cla, portfolio_optimization
17. Structural breaksstructural_breaks
18–19. Entropy and microstructural featuresmicrostructural_features, codependence
20. Multiprocessing and vectorizationhpc_parallel, streaming_hpc
21. Brute force and quantum computersdynamic_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 # Panics on 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.