Version 1.2 - AMD RX 7800 XT ROCm support
A proof-of-concept implementation demonstrating that a small LLM can learn to predict trading actions (BUY/SELL/HOLD) from tokenized market data sequences.
- β Fixed: NaN handling errors in indicator calculations
- β Fixed: Deprecated transformers API compatibility
- β Added: Accelerate library support for modern training
- β Added: Comprehensive .gitignore for model files
- β Optimized: AMD RX 7800 XT support with ROCm and FP16 mixed precision
- β Improved: Better error messages and debugging
See CHANGELOG.md for complete details.
Demonstrate technical feasibility of using an LLM to learn trading patterns by:
- Converting historical price data into a token-based trading language
- Fine-tuning a small language model (distilgpt2) on these sequences
- Testing if the model can predict trading actions better than random chance
This is a research/educational project, not investment advice.
Historical Price Data (SPY via configured market data provider)
β
Token Generator (converts OHLCV β trading language tokens)
β
Training Sequences (e.g., "<SYM_SPY> <TF_DAILY> ST_UpTrend Hi_Volume BUY")
β
Fine-tuned distilgpt2 model
β
Predictions (next token = BUY/SELL/HOLD)
Each sequence is composed of discrete tokens representing market state:
- Symbol:
<SYM_SPY>,<SYM_QQQ>, etc. - Timeframe:
<TF_DAILY>,<TF_WEEKLY>,<TF_60MIN> - State Trend:
ST_UpTrend,ST_DownTrend,ST_Flat - Volume:
Hi_Volume,Lo_Volume,Avg_Volume - Indicators:
HA_UpCross,HA_DownCross,STO_Cross,STO_NoCross - Actions:
BUY,SELL,HOLD
Example sequence:
<SYM_SPY> <TF_DAILY> ST_DownTrend Hi_Volume HA_UpCross STO_Cross BUY
# 1. Install PyTorch with ROCm
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.7
# 2. Install dependencies
pip install -r requirements.txt
# 3. Verify GPU
python -c "import torch; print(f'ROCm: {torch.cuda.is_available()}')"See RX7800XT_SETUP.md for detailed setup guide.
# Build the image
docker build -t tradebot .
# Run the Streamlit app (mount your trained model)
docker run -p 8501:8501 \
-v /path/to/your/models:/app/models \
tradebot
# Run with live market data (set API keys via -e)
docker run -p 8501:8501 \
-v /path/to/your/models:/app/models \
-e ALPHA_VANTAGE_API_KEY=your_key \
tradebot
# Run a different command (train, data gen, test, etc.)
docker run --rm \
-v /path/to/your/models:/app/models \
-v /path/to/your/data:/app/data \
tradebot \
python src/02_train_model.pyNote: The image does not bundle model or data files β they are mounted as volumes.
python src/01_generate_training_data.pyThis downloads SPY historical data and generates token sequences.
Set ALPHA_VANTAGE_API_KEY or STOOQ_API_KEY to use live data; otherwise the
generator falls back to the included sample data.
For the Streamlit demo, add a live data key in .env:
cp .env.example .env
# Edit .env and set ALPHA_VANTAGE_API_KEY
.venv/bin/streamlit run app.pypython src/02_train_model.pyFine-tunes distilgpt2 on the trading sequences.
python src/03_test_model.pyEvaluates model accuracy on held-out test sequences.
python src/04_interactive_inference.pyTest the model with custom market state inputs.
tradebot/
βββ README.md
βββ requirements.txt
βββ data/
β βββ raw/ # Downloaded price data
β βββ processed/ # Token sequences
β βββ train_test_split/ # Training/test datasets
βββ models/
β βββ tradebot/ # Saved model checkpoints
βββ src/
β βββ 01_generate_training_data.py
β βββ 02_train_model.py
β βββ 03_test_model.py
β βββ 04_interactive_inference.py
βββ utils/
βββ data_generator.py
βββ token_definitions.py
βββ indicators.py
- Primary: Model predicts correct action token >50% of the time (better than random 33%)
- Secondary: Model learns symbol/timeframe context (different predictions for same pattern under different symbols)
- Correlation β Causation: Model learns statistical patterns, not market dynamics
- Overfitting: May memorize historical sequences without generalizing
- No Risk Management: Predictions are binary (BUY/SELL), no position sizing or stop losses
- Lookback Bias: All training data is "from the future" relative to prediction point
- No Transaction Costs: Ignores fees, slippage, and execution delays
- Add more sophisticated indicators (RSI, MACD, Bollinger Bands)
- Implement proper backtesting with transaction costs
- Test on multiple symbols and timeframes
- Paper trading with live data
- Explore reinforcement learning approach (reward = profit)
- Adapt to prediction markets (Polymarket)
- Data Generation: 30 minutes
- Model Training: 1-2 hours (CPU) / 15-30 minutes (GPU)
- Testing & Evaluation: 30 minutes
- Total: ~3-4 hours for complete Hello World
Educational/Research use only. Not financial advice.