Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. AI in Finance
  3. btgym

btgym

LGPL-3.0Python

A scalable, event-driven backtesting library for reinforcement learning in algorithmic trading, built on Backtrader with OpenAI Gym API.

Visit WebsiteGitHubGitHub
1.0k stars258 forks0 contributors

What is btgym?

BTGym is a scalable, event-driven backtesting library specifically designed for reinforcement learning experiments in algorithmic trading. It wraps the Backtrader trading engine with an OpenAI Gym-compatible API, allowing developers to train RL agents on historical market data in a realistic, episodic environment. The library supports both discrete and continuous action spaces, multiple data sampling strategies, and includes implementations of advanced RL algorithms like A3C and PPO.

Target Audience

Researchers and developers working on reinforcement learning for algorithmic trading, quantitative finance, or financial AI who need a flexible, gym-integrated backtesting environment to prototype and test trading strategies.

Value Proposition

BTGym uniquely combines the robust event-driven backtesting of Backtrader with the standardized RL interface of OpenAI Gym, offering a scalable and realistic environment for training trading agents. Its support for multiple data sampling methods, multi-asset trading, and pre-built RL algorithms accelerates research and experimentation in financial reinforcement learning.

Overview

Scalable, event-driven, deep-learning-friendly backtesting library

Use Cases

Best For

  • Training reinforcement learning agents on historical financial data
  • Prototyping algorithmic trading strategies with RL
  • Researching meta-learning and non-stationary environment adaptation in trading
  • Backtesting multi-asset portfolio optimization strategies
  • Experimenting with continuous action spaces in financial RL
  • Developing and comparing advanced RL algorithms (A3C, UNREAL, PPO) for trading

Not Ideal For

  • Production trading systems requiring stable, bug-free software
  • Windows users without Linux compatibility or virtualization
  • Teams seeking out-of-the-box profitable strategies without RL development
  • Simple backtesting projects not involving reinforcement learning

Pros & Cons

Pros

OpenAI Gym Integration

Provides a standardized RL environment interface, making it easy to integrate with existing RL algorithms and frameworks, as highlighted in the key features.

Event-Driven Architecture

Built on Backtrader for scalable, realistic market simulations that support both discrete and continuous action spaces, enabling close-to-real-world trading scenarios.

Flexible Data Sampling

Offers random, sequential, and sliding time-window sampling methods to combat non-stationarity and overfitting, as described in the data selection options.

Multi-Asset Trading Support

Allows trading of multiple financial instruments with discrete or continuous portfolio optimization, though multi-asset setups are noted as buggy or incomplete in updates.

Cons

Research-Grade Instability

The README explicitly states the code can be unstable, buggy, poor performing, and subject to change, making it unsuitable for production use.

Complex Installation and Dependencies

Requires specific setups like Matplotlib 2.0.2, LSOF utility, and virtual environments, with noted issues on Windows and Python version constraints.

Limited Out-of-the-Box Functionality

Default configuration is tailored for Forex 1 min data from HistData.com, and advanced features like multi-asset trading are still in beta or buggy, as per known limitations.

Steep Learning Curve

Setting meaningful experiments requires practical programming experience and reinforcement learning knowledge, as warned in the disclaimer, not just basic usage.

Frequently Asked Questions

Quick Stats

Stars1,033
Forks258
Contributors0
Open Issues10
Last commit4 years ago
CreatedSince 2017

Tags

#openai-gym#a3c#backtesting#algorithmic-trading#deep-learning#backtesting-trading-strategies#python#time-series#tensorflow#deep-reinforcement-learning#gym-environment#research-framework#reinforcement-learning#financial-markets#trading-bots

Built With

T
TensorFlow
P
Pillow
p
pandas
P
Python
N
NumPy
D
Docker
m
matplotlib

Links & Resources

Website

Included in

AI in Finance5.6k
Auto-fetched 12 hours ago

Related Projects

TradingGymTradingGym

Trading and Backtesting environment for training reinforcement learning agent or simple rule base algo.

Stars1,904
Forks373
Last commit2 years ago
TradzQAITradzQAI

Trading environnement for RL agents, backtesting and training.

Stars167
Forks42
Last commit4 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub