Skip to content

Examples

Python examples covering key chapters from Advances in Financial Machine Learning (AFML) by Marcos Lopez de Prado, implemented using pymlfinance.

Inspired by the BlackArbsCEO AFML Exercises.

Chapters

Chapter Topic Polars Expressions
Ch 2 Financial Data Structures
Ch 3 Labeling .ml.daily_volatility(), .ml.trend_scanning_label_series()
Ch 4 Sample Weights
Ch 5 Fractional Differentiation .ml.frac_diff_ffd(), .ml.find_min_d(), .ml.adf_test()
Ch 6 Ensemble Methods
Ch 7 Cross-Validation
Ch 8 Feature Importance
Ch 10 Bet Sizing .ml.sigmoid_bet_size(), .ml.power_bet_size()
Ch 11-12 Backtesting Dangers
Ch 13 Synthetic Data
Ch 14 Backtest Statistics .ml.sharpe_ratio(), .ml.hit_ratio(), .ml.compute_drawdowns()
Ch 17 Structural Breaks .ml.adf_test(), .ml.sadf()
Ch 18 Entropy Features .ml.binary_encode(), .ml.shannon_entropy(), .ml.lempel_ziv_complexity()
Ch 19+20 Microstructure .ml.tick_rule_classify(), _lib.vpin(), _lib.kyle_lambda()

Design

  • All synthetic data — no external files or API keys required
  • Both APIs — each example shows the NumPy API and Polars expression API (where applicable)
  • Self-contained — each notebook runs independently
  • Exercises — suggested parameter variations at the end of each example