Add market impact trading environments with pluggable cost models#360
Add market impact trading environments with pluggable cost models#360BruceYanghy merged 2 commits intoAI4Finance-Foundation:masterfrom
Conversation
Update env_mace_stock_trading.py Update README.md Update README.md
for more information, see https://pre-commit.ci
|
Thanks for this substantial contribution — I’m happy to merge it. This PR adds meaningful new capability to FinRL-Meta by introducing a self-contained meta/env_market_impact/ module with Gymnasium-compatible environments and pluggable nonlinear market impact models. The design is especially strong in three aspects: I also appreciate that the module is self-contained and does not require intrusive changes to the existing FinRL-Meta codebase. Overall, this is a strong addition that improves the realism, extensibility, and experimental rigor of the framework. Merging. Bruce |
15405db
into
AI4Finance-Foundation:master
Summary
This PR adds a new
meta/env_market_impact/module with three Gymnasium-compatible trading environments that integrate realistic, nonlinear market impact models. Most open-source RL trading environments assume negligible or fixed transaction costs (typically 10 bps), which causes agents to learn policies that break under real execution. This module provides pluggable cost models grounded in established microstructure theory so that researchers can evaluate how cost assumptions affect agent behavior.Paper: L. R. Abbade and A. H. R. Costa, "Realistic Market Impact Modeling for Reinforcement Learning Trading Environments," arXiv:2603.29086, 2026. [arXiv]
Environments
env_mace_stock_trading.pyenv_margin_trader_impact.pyenv_portfolio_optimization_impact.pyMarket Impact Models
BaselineImpactModelSqrtImpactModelACImpactModelOWImpactModelAll models inherit from an
ImpactModelABC, track per-symbol permanent impact state with exponential decay, and record full impact history for post-hoc analysis.Supporting Infrastructure
market_data.py— Data pipeline: download via FinRL-Meta'sDataProcessor, compute volatility/ADV20, cache, and split into train/trade setsbacktest_config.py— Shared config:BacktestParamsdataclass,MODEL_KWARGS, network architecture presets, Optuna parameter reconstructionbacktest_report_generator.py— Interactive Plotly HTML reports from backtest summary JSON filesutils.py— Logger,compute_performance_stats()(single source of truth for all metrics)example_*.py— Runner scripts for each environment with epoch-by-epoch training and multi-mode evaluation (IS, OOS continued, OOS blank-slate)optuna_*.py— Optuna HPO scripts for each environment (TPE + median pruning, objective = OOS Sharpe)Key Results (NASDAQ-100, $1B initial capital, 2010–2026)
Design Decisions
meta/env_market_impact/with no modifications to existing FinRL-Meta filesImpactModelsubclass works with any environment, enabling controlled experiments where only the cost assumption variesBaselineImpactModel(basis_points=10)reproduces the fixed-fee assumption, so existing workflows are unaffectedBoxobservation/action spaces and work withDRLAgent+DummyVecEnv