Óscar Romero Quincoces

Projects / Research and master's

RL for trading

From Q-Learning to DQN and A3C on synthetic markets

2026MIAX master's, Instituto BME
The four synthetic markets of the assignment, with their series and the distribution of returns
Figure 1. The four synthetic markets of the assignment, with their series and the distribution of returns

Summary

Two reinforcement learning assignments on trading a single asset. Tabular Q-Learning and SARSA learn the expected strategy in each synthetic market: they follow the trend (×502 against ×33.6 for buy & hold), buy dips and stay out where there is no signal. DQN and A3C learn it too, but beat neither one-threshold rules nor the tabular agents: a richer state helps more than a bigger algorithm. Team of 3.

The question

Can an agent learn to trade one asset from its own trades? The workshop environment gives a minimal state (recent trend and position), three actions (sell, hold, buy) and a 0.1% commission. The four markets are synthetic and each has a known right strategy: trend with a cycle, geometric Brownian motion, mean reversion, and bull and bear regimes. Every episode uses a new series, and the test uses 200 series and 5 seeds.

How it's built

In the first assignment, tabular Q-Learning and SARSA, tuned in stages on validation (α, ε decay, γ and episodes). Then a richer state with the distance to the 30-session average and 20-session volatility, two more markets, a real S&P 500 series with time splits, and 360 robustness runs that change one factor at a time. In the second, DQN and asynchronous A3C with 3 processes on the same protocol, a noise band to tell real gains from luck, and 300 more one-factor runs.

Results

The tabular agents learn what is expected: ×502 in trend with a cycle, +27% in mean reversion (buy & hold, −0.3%) and 0% where there is no signal, which is right (in the regime market, none of 70 simple rules beats staying out). To learn at all, α had to drop to 0.001. The richer state adds about 25 points in mean reversion, but on the S&P 500 it lowers the return (and the drawdown), and in a 2019–2025 walk-forward no state beats buy & hold consistently. DQN (×300) and A3C (×375) stay below one-threshold rules (×630) and the tabular agents; A3C trains 3.4 times faster but converges in fewer seeds.

The third assignment, on how to execute an order, is in RL for execution.

Figures

Greedy policy map with the richer state in each market
Figure 2. Greedy policy map with the richer state in each market
Test episodes in trend and mean reversion, with the agent's trades
Figure 3. Test episodes in trend and mean reversion, with the agent's trades
Learning curves of Q-Learning and SARSA in trend and mean reversion
Figure 4. Learning curves of Q-Learning and SARSA in trend and mean reversion
Median test return of every agent and baseline in the four markets
Figure 5. Median test return of every agent and baseline in the four markets

Built with

PythonPyTorchNumPypandasJupyter