# rujter/rl-trading-env architecture

> Architecture diagram of the GitHub repository rujter/rl-trading-env, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rujter/rl-trading-env
- Repository: https://github.com/rujter/rl-trading-env

## Overview

This repository contains two experimental reinforcement-learning trading simulators. In the historical variant, an experiment runner trains and evaluates an agent against daily market data, then saves results for plotting. The synthetic variant instead simulates a price and limit-order market with background trader strategies; its runner likewise trains and evaluates an agent and saves results for plots. The sampled code supports the core execution paths, but the synthetic environment excerpt omits substantial sections, so uncertain internal order-book wiring is not expanded. No README content was provided.

Main entry points: [`synthetic/Combined/env_combined.py`](https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/env_combined.py) (Synthetic environment), [`historical/run.py`](https://github.com/rujter/rl-trading-env/blob/master/historical/run.py) (Train and evaluate), [`synthetic/Combined/run.py`](https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/run.py) (Train and evaluate), [`historical/main.py`](https://github.com/rujter/rl-trading-env/blob/master/historical/main.py) (Historical environment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_historical["Historical trading"]
  node_historical_runner["Train and evaluate<br/>[run.py]"]
  node_historical_env["Historical environment<br/>[main.py]"]
  node_historical_models["Portfolio models<br/>[Classes.py]"]
  node_historical_results["Evaluation results<br/>[eval_results.npz]"]
end

subgraph group_synthetic["Synthetic market"]
  node_synthetic_runner["Train and evaluate<br/>[run.py]"]
  node_synthetic_env["Synthetic environment<br/>[env_combined.py]"]
  node_tradingbots["Background traders<br/>[Tradingbots.py]"]
  node_synthetic_models["Market models<br/>[Classes.py]"]
  node_synthetic_results["Evaluation results<br/>[eval_results.npz]"]
end

subgraph group_analysis["Results and charts"]
  node_historical_charts["Historical charts<br/>[plotonly.py]"]
  node_synthetic_charts["Synthetic charts<br/>[plotonly.py]"]
  node_chart_overlay["Chart overlay<br/>[Overlayer.py]"]
end

node_researcher(("Experimenter"))
node_marketdata(("Yahoo Finance"))
node_chart_images["Chart images"]

node_researcher -->|"runs"| node_historical_runner
node_marketdata -->|"provides prices"| node_historical_env
node_historical_runner -->|"trains and steps"| node_historical_env
node_historical_env -->|"uses models"| node_historical_models
node_historical_runner -->|"writes results"| node_historical_results
node_historical_results -->|"loads results"| node_historical_charts
node_researcher -->|"runs"| node_synthetic_runner
node_synthetic_runner -->|"trains and steps"| node_synthetic_env
node_synthetic_env -->|"dispatches traders"| node_tradingbots
node_tradingbots -->|"submits orders"| node_synthetic_env
node_synthetic_env -->|"uses models"| node_synthetic_models
node_synthetic_runner -->|"writes results"| node_synthetic_results
node_synthetic_results -->|"loads results"| node_synthetic_charts
node_synthetic_charts -->|"writes charts"| node_chart_images
node_chart_overlay -.->|"writes overlays"| node_chart_images

click node_historical_runner "https://github.com/rujter/rl-trading-env/blob/master/historical/run.py"
click node_historical_env "https://github.com/rujter/rl-trading-env/blob/master/historical/main.py"
click node_historical_models "https://github.com/rujter/rl-trading-env/blob/master/historical/Classes.py"
click node_historical_results "https://github.com/rujter/rl-trading-env/blob/master/historical/eval_results.npz"
click node_historical_charts "https://github.com/rujter/rl-trading-env/blob/master/historical/plotonly.py"
click node_synthetic_runner "https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/run.py"
click node_synthetic_env "https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/env_combined.py"
click node_tradingbots "https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/Tradingbots.py"
click node_synthetic_models "https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/Classes.py"
click node_synthetic_results "https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/eval_results.npz"
click node_synthetic_charts "https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/plotonly.py"
click node_chart_overlay "https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/Overlayer.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_historical_runner,node_historical_env,node_historical_models,node_historical_results toneBlue
class node_synthetic_runner,node_synthetic_env,node_tradingbots,node_synthetic_models,node_synthetic_results toneAmber
class node_historical_charts,node_synthetic_charts,node_chart_overlay toneMint
class node_researcher,node_marketdata,node_chart_images toneIndigo
```

## Components

### Historical trading

- [Train and evaluate](https://github.com/rujter/rl-trading-env/blob/master/historical/run.py): `historical/run.py`
- [Historical environment](https://github.com/rujter/rl-trading-env/blob/master/historical/main.py): `historical/main.py`
- [Portfolio models](https://github.com/rujter/rl-trading-env/blob/master/historical/Classes.py): `historical/Classes.py`
- [Evaluation results](https://github.com/rujter/rl-trading-env/blob/master/historical/eval_results.npz): `historical/eval_results.npz`

### Synthetic market

- [Train and evaluate](https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/run.py): `synthetic/Combined/run.py`
- [Synthetic environment](https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/env_combined.py): `synthetic/Combined/env_combined.py`
- [Background traders](https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/Tradingbots.py): `synthetic/Combined/Tradingbots.py`
- [Market models](https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/Classes.py): `synthetic/Combined/Classes.py`
- [Evaluation results](https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/eval_results.npz): `synthetic/Combined/eval_results.npz`

### Results and charts

- [Historical charts](https://github.com/rujter/rl-trading-env/blob/master/historical/plotonly.py): `historical/plotonly.py`
- [Synthetic charts](https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/plotonly.py): `synthetic/Combined/plotonly.py`
- [Chart overlay](https://github.com/rujter/rl-trading-env/blob/master/synthetic/Combined/Overlayer.py): `synthetic/Combined/Overlayer.py`

### Other components

- **Experimenter**
- **Yahoo Finance**
- **Chart images**

## Connections

- Experimenter → Train and evaluate: runs
- Yahoo Finance → Historical environment: provides prices
- Train and evaluate → Historical environment: trains and steps
- Historical environment → Portfolio models: uses models
- Train and evaluate → Evaluation results: writes results
- Evaluation results → Historical charts: loads results
- Experimenter → Train and evaluate: runs
- Train and evaluate → Synthetic environment: trains and steps
- Synthetic environment → Background traders: dispatches traders
- Background traders → Synthetic environment: submits orders
- Synthetic environment → Market models: uses models
- Train and evaluate → Evaluation results: writes results
- Evaluation results → Synthetic charts: loads results
- Synthetic charts → Chart images: writes charts
- Chart overlay → Chart images: writes overlays
