← all repositories
Kismuz/btgym

Backtrader meets OpenAI Gym: a trading gym for RL researchers

A bridge library that turns the Backtrader backtesting engine into an OpenAI Gym environment for reinforcement learning experiments.

btgym
Velocity · 7d
+0.3
★ / day
Trend
steady
star history

What it does

BTGym wraps the Backtrader event-driven backtesting engine with an OpenAI Gym API, letting you train RL agents on historical trading data. It supports discrete actions (buy/sell/hold/close) and a beta continuous mode for portfolio allocation. Data can be sampled randomly, sequentially, or via sliding windows.

The interesting bit

The library is explicitly research-grade, not a money-printing machine. The author warns it is “unstable, buggy, poor performing and is subject to change” — refreshing honesty in a space full of overfit trading bots. It ships with A3C, UNREAL, and PPO implementations, plus synthetic data generators including Ornstein-Uhlenbeck processes for controlled experiments.

Key highlights

  • Built on Backtrader + OpenAI Gym; minimal glue to get started
  • Multiple data sampling strategies (random, sequential, sliding window)
  • Includes A3C, UNREAL, PPO implementations
  • Synthetic data feeds and model-based extensions (SSA, state-space models)
  • Docker CPU image available

Caveats

  • Requires Matplotlib 2.0.2 specifically; newer versions break things
  • Windows support is partial at best
  • Not tested below Python 3.5
  • RL²/MAML adaptations and risk-sensitive agents remain unfinished

Verdict

Worth a look if you’re doing RL research on non-stationary environments and want realistic market frictions. Skip it if you want a polished, out-of-the-box trading strategy — the README makes clear you’ll need to write substantial code and understand RL theory.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.