TensorTrade: The Open-Source Python Framework for Building RL-Powered Trading Bots
TensorTrade is a new open-source Python framework that lets developers build, train, and evaluate reinforcement learning agents for algorithmic trading using NumPy, Pandas, TensorFlow, and Keras.

Algorithmic trading just got an open-source upgrade. TensorTrade: The Open-Source Python Framework for Building RL-Powered Trading Bots enables developers to create custom systems. You can now compose environments, action schemes, and reward functions easily. Furthermore, this tool helps answer whether AI agents can beat passive strategies.
What Is TensorTrade?
This Apache 2.0 licensed framework targets reinforcement learning-based algorithmic trading specifically. Unlike general libraries, it offers composable components for the entire pipeline. Therefore, you get tools ranging from data ingestion to order execution.
The system relies on the standard Python scientific stack:
- NumPy & Pandas for data wrangling and feature engineering.
- Gym as the standard RL environment interface.
- Keras & TensorFlow for deep learning policy networks.
- Ray / RLlib for distributed training at scale.
- Optuna for automated hyperparameter optimisation.
Note that this requires Python 3.11 or 3.12.
Core Architecture of TensorTrade: The Open-Source Python Framework for Building RL-Powered Trading Bots
Modular composition drives the design philosophy here. The central TradingEnv connects four key components seamlessly. First, the ActionScheme translates agent output into market orders. The default BSH option provides a clean discrete action space for experiments.
Next, the RewardScheme computes learning signals after each step. Default PBR ties rewards directly to portfolio performance. Additionally, the Observer generates feature vectors from price history. Finally, the Portfolio manages wallets and open positions efficiently.
The Exchange component simulates order execution with configurable commissions. Meanwhile, the DataFeed pipeline handles upstream feature engineering.
Getting Started in Four Commands
Installation is straightforward for most users. Create a virtual environment using Python 3.12 first. Then, activate it and install the core library via pip. Docker users can also spin up Jupyter environments quickly using make commands.
# Create a virtual environment (Python 3.12 recommended)
python3.12 -m venv tensortrade-env
source tensortrade-env/bin/activate # Windows: tensortrade-env\Scripts\activate
# Install the core library
pip install --upgrade pip
pip install -r requirements.txt
pip install -e .
# Optional: add Ray/RLlib for distributed training
pip install -r examples/requirements.txt
# Verify everything works
pytest tests/tensortrade/unit -v
Training Scripts and Optimisation
The framework ships with ready-to-run training scripts. Consequently, you can go from zero to a tuned agent without boilerplate. Start with train_simple.py for a basic demo with wallet tracking.
For longer experiments, use train_ray_long.py for distributed training. Alternatively, train_optuna.py performs Bayesian hyperparameter searches automatically. You can even run train_best.py to replicate published experiment configurations.
Research Results: Can Agents Beat Buy-and-Hold?
The team trained PPO agents on BTC/USD price data extensively. Results show genuine directional prediction capability at zero commission. However, realistic 0.1% commissions currently swamp the prediction edge due to overtrading.
| Configuration | Test P&L | vs Buy-and-Hold |
|---|---|---|
| Agent (0% commission) | +$239 | +$594 |
| Agent (0.1% commission) | −$650 | −$295 |
| Buy-and-Hold (baseline) | −$355 | — |
This transparency identifies exactly where gaps exist. Priority research areas include position sizing and commission-aware reward schemes. These improvements aim to reduce unnecessary trading frequency effectively.
Where This Fits in Your Stack
This platform serves ML engineers exploring applied RL beyond robotics. It also helps quant developers benchmark policies against classical strategies. If you are newer to AI engineering, consider foundational roadmaps first.
Understanding production agent loops is also crucial before diving in. For broader context, check out our article on Oracle Stock Nears 52-Week Low: Retail Traders Call ORCL ‘Ridiculously Undervalued’ to see how market sentiment impacts algorithmic inputs.
Common Issues and Fixes
Users may encounter specific setup challenges occasionally. Update to v1.0.4-dev1+ if streams fail to satisfy selectors. Always upgrade pip before installing Ray to prevent failures.
Additionally, pin NumPy versions to avoid conflicts. For TensorFlow CUDA issues, install the specific and-cuda package variant. These small adjustments ensure a smoother development experience overall.
Conclusion
TensorTrade: The Open-Source Python Framework for Building RL-Powered Trading Bots brings principled RL to finance. Its honest research results build trust within the community. You know exactly what works and where the frontier lies.
Whether you are an ML practitioner or trading developer, this is a strong starting point. The codebase remains clean and the documentation thorough. Visit the GitHub repository to begin your journey today.