A production-ready DRL framework for financial trading โ covering data acquisition, model training, backtesting, and live paper trading across stocks, crypto, and portfolios.
- About the Project
- Key Features
- Architecture
- Tech Stack
- Project Structure
- Supported Data Sources
- Installation
- Quick Start Tutorial
- API Reference
- Notes & Recommendations
- License
FLX is a deep reinforcement learning framework for automated quantitative trading. It provides end-to-end support for the full trading pipeline โ from market data acquisition and feature engineering to model training, backtesting, and live paper trading.
The framework is designed around three core layers:
- ๐๏ธ Market Environments โ Gym-style environments for stocks, crypto, and portfolios
- ๐ค DRL Agents โ Plug-and-play support for ElegantRL, RLlib, and Stable Baselines 3
- ๐ Financial Applications โ Ready-to-use trading strategies and backtesting pipelines
Whether you're a researcher prototyping new trading strategies or a developer building production trading systems โ FLX provides the foundation.
| Feature | Description |
|---|---|
| ๐งช Multi-Agent Training | Train 5 DRL agents simultaneously: A2C, DDPG, PPO, TD3, SAC |
| ๐ Backtesting Engine | Compare agent performance against MVO and market index baselines |
| ๐ก 14+ Data Sources | Yahoo Finance, Alpaca, Binance, WRDS, CCXT, and more |
| ๐ง Technical Indicators | Built-in MACD, RSI, Bollinger Bands, CCI, SMA via stockstats |
| ๐น Multi-Asset Support | Stocks, cryptocurrencies, forex, and portfolio allocation |
| ๐๏ธ Gym-Style Environments | OpenAI Gymnasium-compatible market environments |
| ๐ฑ Paper Trading | Live paper trading integration with Alpaca API |
| ๐งฎ Ensemble Strategies | Combine multiple agents for robust trading decisions |
The framework follows a train โ test โ trade pipeline:
Data Acquisition โ Feature Engineering โ Environment Setup โ Agent Training โ Backtesting โ Paper Trading
Three-Layer Design:
- Application Layer โ Stock trading, portfolio allocation, crypto trading, HFT
- Agent Layer โ ElegantRL, RLlib, Stable Baselines 3 algorithms
- Environment Layer โ Market data processors, gym environments, preprocessors
| Technology | Purpose |
|---|---|
| Python 3.7+ | Core language |
| Stable Baselines 3 | Primary DRL algorithm library |
| ElegantRL | Lightweight DRL algorithms |
| Ray/RLlib | Scalable distributed RL |
| Gymnasium | Environment interface |
| yfinance | Market data (Yahoo Finance) |
| Alpaca API | Paper/live trading |
| stockstats | Technical indicators |
| Matplotlib / Recharts | Visualization and plotting |
| pandas / numpy | Data manipulation |
Finance_pro/
โโโ flx/ # Core library
โ โโโ applications/ # Trading task implementations
โ โ โโโ cryptocurrency_trading/
โ โ โโโ high_frequency_trading/
โ โ โโโ portfolio_allocation/
โ โ โโโ stock_trading/
โ โโโ agents/ # DRL algorithm integrations
โ โ โโโ elegantrl/
โ โ โโโ rllib/
โ โ โโโ stablebaseline3/
โ โโโ meta/ # Market environments & data
โ โ โโโ data_processors/
โ โ โโโ env_cryptocurrency_trading/
โ โ โโโ env_portfolio_allocation/
โ โ โโโ env_stock_trading/
โ โ โโโ preprocessor/
โ โ โโโ data_processor.py
โ โโโ config.py # Global configuration
โ โโโ config_tickers.py # Ticker lists (DOW 30, NASDAQ, etc.)
โ โโโ main.py # CLI entry point
โ โโโ train.py # Training pipeline
โ โโโ test.py # Testing pipeline
โ โโโ trade.py # Live trading pipeline
โ โโโ plot.py # Visualization utilities
โ
โโโ examples/ # Tutorial scripts
โ โโโ FLX_StockTrading_2026_1_data.py
โ โโโ FLX_StockTrading_2026_2_train.py
โ โโโ FLX_StockTrading_2026_3_Backtest.py
โ
โโโ unit_tests/ # Test suite
โโโ docs/ # Documentation (Sphinx)
โโโ docker/ # Docker configuration
โโโ figs/ # Diagrams and figures
โโโ setup.py # Package setup
โโโ pyproject.toml # Poetry configuration
โโโ requirements.txt # Dependencies
โโโ README.md
| Data Source | Type | Range & Frequency | Raw Data | Preprocessed Data |
|---|---|---|---|---|
| YahooFinance | US Securities | Frequency-specific, 1min | OHLCV | Prices & Indicators |
| Alpaca | US Stocks, ETFs | 2015-now, 1min | OHLCV | Prices & Indicators |
| Binance | Cryptocurrency | API-specific, 1s | OHLCV | Prices & Indicators |
| CCXT | Cryptocurrency | API-specific, 1min | OHLCV | Prices & Indicators |
| WRDS | US Securities | 2003-now, 1ms | Intraday Trades | Prices & Indicators |
| Akshare | CN Securities | 2015-now, 1day | OHLCV | Prices & Indicators |
| Baostock | CN Securities | 1990-now, 5min | OHLCV | Prices & Indicators |
| IEXCloud | NMS US Securities | 1970-now, 1day | OHLCV | Prices & Indicators |
| JoinQuant | CN Securities | 2005-now, 1min | OHLCV | Prices & Indicators |
| QuantConnect | US Securities | 1998-now, 1s | OHLCV | Prices & Indicators |
| Tushare | CN Securities | -now, 1min | OHLCV | Prices & Indicators |
| Sinopac | Taiwan Securities | 2023-now, 1min | OHLCV | Prices & Indicators |
OHLCV: Open, High, Low, Close prices + Volume
Technical Indicators: MACD, Bollinger Bands, RSI, CCI, DX, SMA (30/60 day)
- Python 3.7 or higher
- pip or Poetry
git clone <your-repo-url>
cd Finance_pro
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
pip install -e .pip install flxcd docker
bash bin/build_container.shcd Finance_pro
python -m venv venv
venv\Scripts\activate # Windows
pip install -e .python examples/FLX_StockTrading_2026_1_data.pyThis downloads DOW 30 stock data from Yahoo Finance, adds technical indicators (MACD, RSI, etc.), VIX, and turbulence index, then splits into training (2014โ2025) and trading (2026) sets.
python examples/FLX_StockTrading_2026_2_train.pyTrains 5 DRL agents (A2C, DDPG, PPO, TD3, SAC) using Stable Baselines 3. Models are saved to trained_models/.
Key Hyperparameters:
| Parameter | Description | Default |
|---|---|---|
total_timesteps |
Total environment interactions for training | 20,000 |
learning_rate |
Weight update step size | 0.001 |
batch_size |
Samples per gradient update | 100 |
buffer_size |
Replay buffer capacity (off-policy) | 1,000,000 |
python examples/FLX_StockTrading_2026_3_Backtest.pyRuns trained agents on trading data and compares against MVO and DJIA baselines. Results are printed to console and saved as backtest_result.png.
| Variable | Default | Description |
|---|---|---|
TRAIN_START_DATE |
2014-01-06 |
Training period start |
TRAIN_END_DATE |
2025-12-31 |
Training period end |
TRADE_START_DATE |
2026-01-01 |
Trading/test period start |
TRADE_END_DATE |
2026-03-20 |
Trading/test period end |
INDICATORS |
MACD, RSI, Bollinger, etc. | Technical indicators to compute |
| Agent | Key Parameters |
|---|---|
| A2C | n_steps=5, ent_coef=0.01, lr=0.0007 |
| PPO | n_steps=2048, batch_size=64, lr=0.00025 |
| DDPG | batch_size=128, buffer_size=50k, lr=0.001 |
| TD3 | batch_size=100, buffer_size=1M, lr=0.001 |
| SAC | batch_size=64, buffer_size=100k, lr=0.0001 |
- API Keys โ Set your Alpaca, Binance, or other API keys in
flx/config.pyor via environment variables. Never commit secrets. - Training Time โ Start with low
total_timesteps(1,000) to verify the pipeline works, then scale up (100k+) for serious training. - GPU Support โ Stable Baselines 3 supports CUDA. Install PyTorch with GPU support for faster training.
- Data Quality โ Yahoo Finance is free but has limitations. For institutional-grade data, use WRDS or Alpaca.
- Backtesting โ Always backtest before paper/live trading. Compare against multiple baselines.
This project is licensed under the MIT License โ see the LICENSE file for details.
Disclaimer: This software is for educational and research purposes only. Nothing herein constitutes financial advice or a recommendation to trade real money. Users are solely responsible for any financial decisions made using this software. Consult a qualified professional before deploying capital.
Built by Digital Metro ๐