TensorTrade

February 6, 2026 Β· View on GitHub

TensorTrade Logo

TensorTrade

Train RL agents to trade. Can they beat Buy-and-Hold?

Tests Documentation Status Apache License Discord Python 3.12+

TensorTrade is an open-source Python framework for building, training, and evaluating reinforcement learning agents for algorithmic trading. The framework provides composable components for environments, action schemes, reward functions, and data feeds that can be combined to create custom trading systems.

Quick Start

# Requires Python 3.12+
python3.12 -m venv tensortrade-env && source tensortrade-env/bin/activate
pip install -e .

# For training with Ray/RLlib (recommended)
pip install -r examples/requirements.txt

# Run training
python examples/training/train_simple.py

Documentation & Tutorials

πŸ“š Tutorial Index β€” Start here for the complete learning curriculum.

Foundations

Domain Knowledge

Core Components

Training

Advanced Topics

Additional Resources


Research Findings

We conducted extensive experiments training PPO agents on BTC/USD. Key results:

ConfigurationTest P&Lvs Buy-and-Hold
Agent (0% commission)+$239+$594
Agent (0.1% commission)-$650-$295
Buy-and-Hold-$355β€”

The agent demonstrates directional prediction capability at zero commission. The primary challenge is trading frequencyβ€”commission costs currently exceed prediction profits. See EXPERIMENTS.md for methodology and detailed analysis.


Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        TradingEnv                               β”‚
β”‚                                                                 β”‚
β”‚   Observer ──────> Agent ──────> ActionScheme ──────> Portfolio β”‚
β”‚   (features)      (policy)      (BSH/Orders)        (wallets)  β”‚
β”‚       ^                                                  β”‚      β”‚
β”‚       └──────────── RewardScheme <β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”‚                        (PBR)                                    β”‚
β”‚                                                                 β”‚
β”‚   DataFeed ──────> Exchange ──────> Broker ──────> Trades       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
ComponentPurposeDefault
ActionSchemeConverts agent output to ordersBSH (Buy/Sell/Hold)
RewardSchemeComputes learning signalPBR (Position-Based Returns)
ObserverGenerates observationsWindowed features
PortfolioManages wallets and positionsUSD + BTC
ExchangeSimulates executionConfigurable commission

Training Scripts

ScriptDescription
examples/training/train_simple.pyBasic demo with wallet tracking
examples/training/train_ray_long.pyDistributed training with Ray RLlib
examples/training/train_optuna.pyHyperparameter optimization
examples/training/train_best.pyBest configuration from experiments

Installation

Requirements: Python 3.11 or 3.12

# Create environment
python3.12 -m venv tensortrade-env
source tensortrade-env/bin/activate  # Windows: tensortrade-env\Scripts\activate

# Install
pip install --upgrade pip
pip install -r requirements.txt
pip install -e .

# Verify
pytest tests/tensortrade/unit -v

# Training dependencies (optional)
pip install -r examples/requirements.txt

See ENVIRONMENT_SETUP.md for platform-specific instructions and troubleshooting.

Docker

make run-notebook  # Jupyter
make run-docs      # Documentation
make run-tests     # Test suite

Project Structure

tensortrade/
β”œβ”€β”€ tensortrade/           # Core library
β”‚   β”œβ”€β”€ env/              # Trading environments
β”‚   β”œβ”€β”€ feed/             # Data pipeline
β”‚   β”œβ”€β”€ oms/              # Order management
β”‚   └── data/             # Data fetching
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ training/         # Training scripts
β”‚   └── notebooks/        # Jupyter tutorials
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ tutorials/        # Learning curriculum
β”‚   └── EXPERIMENTS.md    # Research log
└── tests/

Troubleshooting

IssueSolution
"No stream satisfies selector"Update to v1.0.4-dev1+
Ray installation failsRun pip install --upgrade pip first
NumPy version conflictpip install "numpy>=1.26.4,<2.0"
TensorFlow CUDA issuespip install tensorflow[and-cuda]>=2.15.1

Contributing

See CONTRIBUTING.md for guidelines.

Priority areas:

  1. Trading frequency reduction (position sizing, holding periods)
  2. Commission-aware reward schemes
  3. Alternative action spaces

Community


License

Apache 2.0