|
1 | 1 | # Deep Reinforcement Learning for Order Execution |
2 | 2 |
|
3 | | -This project implements a Deep Q-Network (DQN) agent designed to execute large financial trade orders optimally. The agent learns to balance the trade-off between **market impact** (slippage caused by trading too fast) and **market risk** (price volatility risk from holding inventory too long). |
| 3 | +This project implements a Deep Q-Network (DQN) agent designed to execute large financial trade orders optimally. The agent learns to balance the trade-off between **market impact** (slippage caused by trading too fast) and **market risk** (price volatility risk from holding inventory too long), targeting a superior **Implementation Shortfall (IS)** compared to standard TWAP strategies. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Project Structure |
| 8 | + |
| 9 | +``` |
| 10 | +rl-order-execution/ |
| 11 | +├── .github/workflows/ |
| 12 | +│ ├── ci.yml # CI pipeline (Lint, Test, Type-Check) |
| 13 | +│ └── update-docs.yml # Auto-update README config table |
| 14 | +├── config/ |
| 15 | +│ └── config.yaml # Runtime configuration parameters |
| 16 | +├── src/ |
| 17 | +│ └── rl_order_execution/ |
| 18 | +│ ├── agent.py # DQN Agent & ReplayBuffer implementation |
| 19 | +│ ├── settings.py # Pydantic configuration & validation |
| 20 | +│ ├── environment.py # Custom Gymnasium Market Environment |
| 21 | +│ ├── evaluation.py # TWAP comparison & plotting logic |
| 22 | +│ ├── optimize.py # Optuna hyperparameter tuning script |
| 23 | +│ └── training.py # Core training loop with TensorBoard |
| 24 | +├── tests/ # Pytest suite |
| 25 | +├── Dockerfile # Container definition |
| 26 | +├── Makefile # Automation commands |
| 27 | +├── pyproject.toml # Dependencies (uv) |
| 28 | +├── README.md # Documentation |
| 29 | +└── main.py # Application entry point |
| 30 | +``` |
4 | 31 |
|
5 | 32 | ## Getting Started |
6 | 33 |
|
@@ -80,31 +107,6 @@ To run the simulation in a completely isolated environment: |
80 | 107 | make docker-run |
81 | 108 | ``` |
82 | 109 |
|
83 | | -## Project Structure |
84 | | -
|
85 | | -``` |
86 | | -rl-order-execution/ |
87 | | -├── .github/workflows/ |
88 | | -│ ├── ci.yml # CI pipeline (Lint, Test, Type-Check) |
89 | | -│ └── update-docs.yml # Auto-update README config table |
90 | | -├── config/ |
91 | | -│ └── config.yaml # Runtime configuration parameters |
92 | | -├── src/ |
93 | | -│ └── rl_order_execution/ |
94 | | -│ ├── agent.py # DQN Agent & ReplayBuffer implementation |
95 | | -│ ├── settings.py # Pydantic configuration & validation |
96 | | -│ ├── environment.py # Custom Gymnasium Market Environment |
97 | | -│ ├── evaluation.py # TWAP comparison & plotting logic |
98 | | -│ ├── optimize.py # Optuna hyperparameter tuning script |
99 | | -│ └── training.py # Core training loop with TensorBoard |
100 | | -├── tests/ # Pytest suite |
101 | | -├── Dockerfile # Container definition |
102 | | -├── Makefile # Automation commands |
103 | | -├── pyproject.toml # Dependencies (uv) |
104 | | -├── README.md # Documentation |
105 | | -└── main.py # Application entry point |
106 | | -``` |
107 | | -
|
108 | 110 | ## Key Metrics Explained |
109 | 111 |
|
110 | 112 | The simulation output provides several metrics to assess agent performance against the TWAP benchmark: |
@@ -204,9 +206,25 @@ While this project demonstrates a robust RL pipeline, it makes certain simplifyi |
204 | 206 |
|
205 | 207 | ### 1. Discrete vs. Continuous Control (DQN vs. PPO/SAC) |
206 | 208 |
|
207 | | -**Limitation:** The current agent uses a Deep Q-Network (DQN), which necessitates a discrete action space. Execution rates are quantized into specific bins (e.g., 0.5x, 1.0x, 2.0x TWAP). |
| 209 | +**Limitation:** The current agent uses a Deep Q-Network (DQN), which necessitates a discrete action space. Execution rates are quantized into specific bins (e.g., 0.5x, 1.0x, 2.0x TWAP). This lacks the granularity required for precise optimal control. |
| 210 | +
|
| 211 | +**Future Improvement:** Implement **Proximal Policy Optimization (PPO)** or **Soft Actor-Critic (SAC)**. These algorithms natively support continuous action spaces, allowing the agent to output precise float values for execution rates. |
| 212 | +
|
| 213 | +### 2. Market Simulation Realism (GBM vs. Stylized Facts) |
| 214 | +
|
| 215 | +**Limitation:** The environment utilizes Geometric Brownian Motion (GBM). While standard for theoretical derivatives pricing, GBM fails to capture the "stylized facts" of high-frequency market data, specifically **Volatility Clustering**, **Fat Tails**, and **Mean Reversion**. |
| 216 | +
|
| 217 | +**Future Improvement:** |
| 218 | +
|
| 219 | +- Implement an **Ornstein-Uhlenbeck (OU)** process to simulate mean-reverting price dynamics. |
| 220 | +
|
| 221 | +- Develop a `HistoricalReplayEnv` to train agents on real minute-bar or tick-level data (L2/L3) to validate performance on historical scenarios. |
| 222 | +
|
| 223 | +### 3. State Space Complexity |
| 224 | +
|
| 225 | +**Limitation:** The current state observation includes only normalized time, inventory, and recent price trend. |
208 | 226 |
|
209 | | -**Future Improvement:** Implement Proximal Policy Optimization (PPO) or Soft Actor-Critic (SAC). These algorithms support continuous action spaces, allowing the agent to output precise execution rates without artificial quantization buckets. |
| 227 | +Future Improvement: Enrich the state space with microstructure signals such as **Order Book Imbalance (OBI)**, **Volume Weighted Average Price (VWAP) deviation**, and **Bid-Ask Spread** to give the agent deeper market visibility. |
210 | 228 |
|
211 | 229 | ## License |
212 | 230 |
|
|
0 commit comments