How jonusnattapong/reinforcement-learning-for-gold-trading works
This repository trains and evaluates PPO agents for XAUUSD trading. The user starts a train, evaluation, or combined run; the runner loads and prepares price history, builds training and evaluation environments, and coordinates learning and validation/testing. The trading environment simulates positions, costs, rewards, and risk limits; evaluation reports daily profit, win rate, drawdown, Sharpe ratio, and trades. README capabilities also include CSV or Hugging Face data, configurable settings, and loading a pretrained model. Edges follow sampled calls, SOURCE INDEX references, or README statements; unsampled implementation details are not inferred.
Main entry points: run.py Run coordinator · data.py Load and split · metrics.py Performance metrics · vec_env.py Vector environments
Components 13
Market data
- CSV history
- Hugging Face dataset
- Load and split
src/rl_gold_trading/data.py - Market features
src/rl_gold_trading/features.py
Trading simulation
- Trading environment
src/rl_gold_trading/envs.py - Vector environments
src/rl_gold_trading/vec_env.py
PPO learning
- Run coordinator
src/rl_gold_trading/run.py - Configuration
src/rl_gold_trading/config.py - PPO training
src/rl_gold_trading/train.py - Stable-Baselines3 PPO
Evaluation
- Performance metrics
src/rl_gold_trading/metrics.py
Other components
- User
- CLI entry
train.py
Connections 14
- User → CLI entry: starts run
README.md - CLI entry → Run coordinator: dispatches
train.py - Run coordinator → Configuration: configures
src/rl_gold_trading/run.py - Run coordinator → Load and split: loads and splits
src/rl_gold_trading/run.py - Load and split → CSV history: reads optionally
README.md - Load and split → Hugging Face dataset: loads fallback
src/rl_gold_trading/data.py - Run coordinator → Market features: computes features
src/rl_gold_trading/run.py - Run coordinator → Vector environments: builds environments
src/rl_gold_trading/run.py - Vector environments → Trading environment: wraps
src/rl_gold_trading/vec_env.py - Run coordinator → PPO training: builds and trains
src/rl_gold_trading/run.py - PPO training → Stable-Baselines3 PPO: creates and learns
src/rl_gold_trading/train.py - Run coordinator → Performance metrics: evaluates splits
src/rl_gold_trading/run.py - Performance metrics → Vector environments: resets and steps
src/rl_gold_trading/metrics.py - Performance metrics → Stable-Baselines3 PPO: predicts actions
src/rl_gold_trading/metrics.py