Skip to content
Back to skills

Tensortrade Rl

ASecurity

TensorTrade — composable RL framework for building and training reinforcement learning trading agents. Modular TradingEnv with Observer, ActionScheme, RewardScheme, Portfolio, Exchange components. Integrates Ray RLlib for distributed training. Python

  • 14 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 3, 2026
ai-agentspythongobashtestinggit

Works with

  • cli

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned June 3, 2026

npx -y skills add mahmoud20138/Tradecraft --skill tensortrade-rl --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Tensortrade Rl?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Tensortrade Rl
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mahmoud20138-tensortrade-rl/badge)](https://www.skillsdirectory.com/skills/mahmoud20138-tensortrade-rl)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: tensortrade-rl
description: TensorTrade — composable RL framework for building and training reinforcement learning trading agents. Modular TradingEnv with Observer, ActionScheme, RewardScheme, Portfolio, Exchange components. Integrates Ray RLlib for distributed training. Python
kind: reference
category: trading/quant
status: active
tags: [portfolio, python, quant, rl, tensortrade, trading]
related_skills: [backtesting-sim, backtest-report-generator, hurst-exponent-dynamics-crisis-prediction, ml-trading, quant-ml-trading]
---

# tensortrade-rl

USE FOR:
  - "train RL agent to trade"
  - "reinforcement learning for algorithmic trading"
  - "PPO / DQN / A3C trading agent"
  - "custom trading environment (gym-style)"
  - "backtesting with RL agent"
  - "distributed RL training with Ray"
  - "position-based reward function trading"
tags: [RL, reinforcement-learning, trading, PPO, DQN, Ray, RLlib, backtesting, gym, TensorTrade, algorithmic]
kind: framework
category: quant-ml-trading

---

## What Is TensorTrade?

Open-source Python RL trading framework. Builds composable `TradingEnv` environments
to train and evaluate RL agents against market data.

- Repo: https://github.com/tensortrade-org/tensortrade
- Docs: tensortrade.org
- License: Apache 2.0
- Python: 3.12+

> Research finding: PPO on BTC/USD achieves directional prediction at zero commission,
> but trading frequency → commissions exceed profits in live conditions.

---

## Core Architecture

```
┌─────────────── TradingEnv ────────────────────┐
│                                               │
│  Observer      → feature engineering          │
│  ↓                                            │
│  Agent         → RL policy (PPO/DQN/etc.)     │
│  ↓                                            │
│  ActionScheme  → BUY / SELL / HOLD orders     │
│  ↓                                            │
│  Exchange      → simulated execution + fees   │
│  ↓                                            │
│  Portfolio     → wallet + position tracking   │
│  ↓                                            │
│  RewardScheme  → position-based returns       │
└───────────────────────────────────────────────┘
```

---

## Installation

```bash
python3.12 -m venv tensortrade-env
source tensortrade-env/bin/activate
pip install -e .
pip install -r examples/requirements.txt
```

---

## Basic Usage

```python
import tensortrade.env.default as default
from tensortrade.feed.core import Stream, DataFeed
from tensortrade.oms.exchanges import Exchange
from tensortrade.oms.services.execution.simulated import execute_order
from tensortrade.oms.wallets import Wallet, Portfolio

# Define exchange and portfolio
coinbase = Exchange("coinbase", service=execute_order)(
    Stream.source(price_data, dtype="float").rename("USD-BTC")
)
portfolio = Portfolio(USD, [Wallet(coinbase, 10000 * USD), Wallet(coinbase, 0 * BTC)])

# Build environment
env = default.create(
    portfolio=portfolio,
    action_scheme="managed-risk",     # BUY/SELL/HOLD with risk sizing
    reward_scheme="risk-adjusted",    # Sharpe-ratio based reward
    feed=DataFeed([price_stream, volume_stream, rsi_stream]),
    window_size=20,
)
```

---

## Training with Ray RLlib

```python
from ray import tune
from ray.rllib.algorithms.ppo import PPOConfig

config = (
    PPOConfig()
    .environment(env_class, env_config={"window_size": 20})
    .training(lr=1e-4, gamma=0.99, train_batch_size=4000)
    .rollouts(num_rollout_workers=4)
)

tune.run("PPO", config=config.to_dict(), stop={"episodes_total": 500})
```

---

## Hyperparameter Optimization (Optuna)

```python
# examples/training/train_optuna.py
# Searches: lr, gamma, clip_param, window_size, reward_scheme
```

---

## Action Schemes

| Scheme | Description |
|--------|-------------|
| `simple` | BUY / SELL / HOLD discrete actions |
| `managed-risk` | Position sizing + stop-loss built-in |
| `bsh` | Binary: BUY or SELL only |

## Reward Schemes

| Scheme | Description |
|--------|-------------|
| `simple` | Raw P&L per step |
| `risk-adjusted` | Sharpe ratio-based |
| `position-based` | Return based on current position |

---

## Key Research Insights

| Finding | Detail |
|---------|--------|
| Directional accuracy | PPO learns BTC direction at 0 commission |
| Commission sensitivity | Even small fees (0.1%) significantly hurt returns |
| Training regime | Needs 200+ episodes to converge on noisy data |
| Overfitting risk | Walk-forward validation critical |

---

## Pre-built Examples

```bash
# Simple training run
python examples/training/train_simple.py

# Distributed training (Ray)
python examples/training/train_ray.py

# Hyperparameter search
python examples/training/train_optuna.py

# Use pre-tuned config
python examples/training/train_best.py
```


---

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.