설명 없음
Find a file
2026-06-02 19:42:53 +00:00
l1_pipeline_29pairs.py Загрузить файлы в «/» 2026-06-02 19:42:53 +00:00
README.md Загрузить файлы в «/» 2026-06-02 19:41:38 +00:00

Article-22674-L1-Trend-Filter-Multi-Asset-VaR-Portfolio

This repository is an article-derived reference project based on the original MQL5 article. It does not claim to reproduce the full original source code unless files are explicitly attached.

Overview

Reference repository for an MQL5 article describing a Python-based multi-asset trading research pipeline built around:

  • causal L1 Trend Filtering via ADMM,
  • feature engineering on filtered trend geometry,
  • per-symbol CatBoost walk-forward evaluation,
  • 29-instrument diversification,
  • VaR-based lot allocation,
  • portfolio backtesting and visualization,
  • optional live-trading loop concepts through MetaTrader 5.

The article presents the full methodology and several code fragments, but the processed input does not provide the complete original repository contents or confirmed attached source files.

Original Article

Repository Purpose

This repository should be treated as a reconstruction/reference project for the article’s ideas rather than a verified mirror of the original implementation.

Its purpose is to document and, where possible, organize the article-described pipeline for:

  • noise-robust trend extraction from H1 price series,
  • cross-instrument ML evaluation,
  • risk-weighted portfolio allocation,
  • backtest structure and live-trading mode design.

Key Concepts

  • L1 Trend Filter with convex optimization objective min_x 0.5 * ||y - x||^2 + lam * ||D2 x||_1
  • ADMM solver with:
  • banded linear system solve,
  • soft-thresholding,
  • adaptive rho,
  • residual balancing
  • Causal filtering through a sliding window to avoid look-ahead bias
  • 29-symbol universe:
  • 28 FX majors/crosses
  • XAUUSD
  • L1-bars defined by slope sign changes in the filtered trend
  • Trend-geometry features:
  • filtered returns,
  • slope / curvature / acceleration,
  • price-vs-trend deviation,
  • rolling volatility,
  • RSI,
  • Bollinger position,
  • regime-change flags
  • Per-symbol CatBoost classification
  • Walk-forward validation with internal early stopping
  • Purge + embargo to reduce label leakage
  • Parametric VaR lot allocation inversely proportional to instrument risk
  • Portfolio equity aggregation and contribution analysis

Algorithm / Architecture Summary

The article describes a three-stage pipeline:

  1. Data acquisition
  • Download approximately 45,000 H1 bars from MetaTrader 5
  • Universe includes 29 instruments: EURUSD, GBPUSD, USDJPY, USDCHF, AUDUSD, USDCAD, NZDUSD, EURGBP, EURJPY, EURAUD, EURCAD, EURCHF, EURNZD, GBPJPY, GBPAUD, GBPCAD, GBPCHF, GBPNZD, AUDJPY, CADJPY, CHFJPY, NZDJPY, AUDCAD, AUDCHF, AUDNZD, NZDCAD, NZDCHF, CADCHF, XAUUSD
  1. Signal research and model evaluation
  • Apply a causal L1 trend filter with a rolling window
  • Detect breakpoints from sign changes in filtered slope
  • Build approximately 29 engineered features from raw close and L1 trend
  • Define target using a structural horizon of 3 future L1-bars
  • Train per-symbol CatBoost models
  • Evaluate with expanding-window walk-forward validation
  • Use internal validation split with early stopping
  • Apply purge/embargo logic between train and test segments
  1. Risk allocation and portfolio backtest
  • Estimate per-symbol volatility
  • Compute parametric 95% VaR
  • Allocate lots inversely to VaR
  • Re-run backtests using final lot sizes
  • Aggregate portfolio equity and instrument-level contributions
  • Produce visualizations such as:
  • portfolio equity and drawdown,
  • VaR allocation pie chart,
  • per-symbol return curves,
  • PnL contribution bar chart

The article also describes two live-trading operation modes conceptually:

  • close all positions when portfolio profit target is reached,
  • close positions only on reverse signal.

Mentioned or Attached Files

Explicitly attached files

No attached source files were available in the processed input.

Files mentioned in the article text

  • l1_pipeline_29pairs.py — described as the main Python script containing the full pipeline
  • checkpoints_29pairs/ — described as a cache/checkpoint directory
  • Output image examples mentioned:
  • 01_equity_drawdown.png
  • 02_var_allocation.png
  • 03_symbol_returns.png

Statistics

  • Timeframe: H1
  • Bars per instrument: 45,000
  • Instrument count: 29
  • Forecast horizon: 3 L1-bars
  • L1 filter lambda: 150
  • Causal window: 200
  • Causal stride: 5
  • L1 causal max_iter: 120
  • Full L1 max_iter: 1000
  • Walk-forward folds: 10
  • Internal early stopping rounds: 40
  • VaR confidence level: 95%
  • Reported mean accuracy: 0.683 ± 0.043
  • Reported forward trades: 10,047
  • Reported win rate: 64.9%
  • Reported profit factor: 2.74
  • Reported portfolio Sharpe: 12.80
  • Reported portfolio PnL: +$412,467

Tags

MQL5 Python MetaTrader5 CatBoost L1-Trend-Filter ADMM Walk-Forward VaR Portfolio-Allocation Algorithmic-Trading Feature-Engineering Time-Series

Difficulty

Advanced

Requires familiarity with:

  • quantitative finance and market microstructure noise,
  • convex optimization and ADMM,
  • time-series validation,
  • supervised ML for trading,
  • portfolio risk allocation,
  • MetaTrader 5 Python integration.

Limitations

  • The full original source code is not available in the processed input.
  • Article metadata such as article ID, author, and publication date were not provided here.
  • The README reflects an article-based reconstruction of the described system, not a verified code archive.
  • Some implementation details are only available as inline article snippets and narrative descriptions.
  • Reported performance metrics are taken from the article text and are not independently verified here.
  • No installation or execution instructions are included because the complete repository contents were not supplied.

Reference

  • MQL5 article page pattern: https://www.mql5.com/ /articles/
  • Kim et al., ℓ1 Trend Filtering, SIAM Review, 2009
  • Boyd et al., Distributed Optimization and Statistical Learning via the Alternating Direction Method of Multipliers, 2011
  • López de Prado concepts referenced in the article discussion of purge/embargo for financial ML validation