A trading Gym that admits it won't make you rich
gym-anytrading exists because its author couldn't find a trading Gym environment that was simple enough to actually understand.

What it does
gym-anytrading is a collection of Gymnasium-compatible environments for training reinforcement learning agents on financial markets. At its core is an abstract TradingEnv that you subclass or configure with a pandas DataFrame, a window size, and your own feature-processing logic. The concrete ForexEnv and StocksEnv build on this to handle currency pairs and equities with market-specific fee structures.
The interesting bit
The author deliberately axed the usual smorgasbord of trading actions—no Hold, Enter, or Exit—leaving only Buy and Sell. The reasoning, backed by months of experimentation, is that extra actions just inflate learning time without improving results, and a well-trained agent wouldn’t sit out anyway. It’s a refreshingly narrow scope in a domain usually plagued by overambitious automation promises.
Key highlights
- Abstract
TradingEnvexposes hooks for custom reward functions, profit calculations, and fee models via a handful of override methods. ForexEnvsupports currency-pair-specific logic likeunit_side(left or right, e.g., EUR vs. USD) and flat per-trade fees.StocksEnvuses percentage-based bid and ask fees to simulate equity slippage.- Ships with default EUR/USD hourly and Google stock datasets so you can test agents immediately.
- Includes rendering methods to visualize Short and Long positions over a price series.
Caveats
- The README explicitly warns that this won’t handle budget allocation, multi-market policies, or other real-world portfolio management; it’s a narrow RL sandbox.
- The author points experts toward
gym-mtsim, suggesting this project is intentionally entry-to-mid-level. - The default action and position spaces are rigidly minimal; if your strategy requires more nuance, you’ll need to extend the base class yourself.
Verdict
A solid starting point if you want a clean, hackable Gym interface for prototyping DQN or Q-learning on price data. Look elsewhere if you need a full backtester or a strategy that handles real-world risk management.
Frequently asked
- What is AminHP/gym-anytrading?
- gym-anytrading exists because its author couldn't find a trading Gym environment that was simple enough to actually understand.
- Is gym-anytrading open source?
- Yes — AminHP/gym-anytrading is open source, released under the MIT license.
- What language is gym-anytrading written in?
- AminHP/gym-anytrading is primarily written in Python.
- How popular is gym-anytrading?
- AminHP/gym-anytrading has 2.4k stars on GitHub.
- Where can I find gym-anytrading?
- AminHP/gym-anytrading is on GitHub at https://github.com/AminHP/gym-anytrading.