An exploratory learning project implementing a deep reinforcement learning approach for leveraged trading, combining sentiment analysis with technical indicators using Alpaca for market data access.
- Prerequisites: Python 3.8+, Jupyter, free Alpaca account
- Install UV:
curl -LsSf https://astral.sh/uv/install.sh | sh - Setup environment:
uv python install 3.11 uv venv && source .venv/bin/activate uv pip install ray[rllib] gymnasium pandas numpy transformers alpaca-py talib accelerate bitsandbytes peft sentencepiece jupyter
- Configure Alpaca API: Create
Alpaca API Key.txtandAlpaca API Secret.txtfiles - Run notebooks in order:
fetch_market_data.ipynb→generate_sentiment_scores.ipynb→train_and_inference.ipynb→evaluate_performance.ipynb
train_and_inference.ipynb: Main RL training and inference pipelineevaluate_performance.ipynb: Performance benchmarking and visualizationfetch_market_data.ipynb: Alpaca API data acquisition with technical indicatorsgenerate_sentiment_scores.ipynb: Transformer-based news sentiment analysisProject Report.pdf: Comprehensive technical documentation
Core Components:
- Ray RLlib-powered reinforcement learning for trading decisions
- Transformer models for financial news sentiment analysis
- Technical indicators (EMA, RSI, MFI, Directional Movement)
- Built-in leverage mechanism for position sizing
Analysis & Evaluation:
- Backtesting against buy-and-hold and market benchmarks
- Risk metrics: Sharpe ratio, maximum drawdown, win rate
- Performance visualization and comparative analysis
Data Generation (no large files included):
- Market data: Run
fetch_market_data.ipynbwith Alpaca credentials - News sentiment: Run
generate_sentiment_scores.ipynbon financial news - Technical indicators: Automatically calculated during data processing
API Setup:
- Register at alpaca.markets
- Get API keys from dashboard
- Create credential files:
Alpaca API Key.txt: Your API keyAlpaca API Secret.txt: Your API secret
- RAM: 8GB+ recommended (16GB+ for GPU acceleration)
- Python: 3.8+ (3.11 recommended)
- GPU: CUDA-compatible for sentiment analysis acceleration
- Storage: ~500MB for dependencies + data generation
- Data Acquisition: Fetch historical market data and compute technical indicators
- Sentiment Processing: Generate sentiment scores from financial news
- Model Training: Train RL agent with combined market and sentiment features
- Performance Evaluation: Compare against benchmarks and analyze risk metrics
Common Issues:
- API errors: Verify Alpaca credentials and account permissions
- Memory issues: Reduce batch sizes or use CPU for sentiment analysis
- UV not found: Restart terminal after installation
- Jupyter kernels: Run
uv pip install ipykerneland restart Jupyter
Performance Tips:
- Use GPU for faster sentiment analysis training
- Start with smaller datasets for initial testing
- Monitor Alpaca API rate limits during data fetching
This project is for educational and research purposes only. Not financial advice. Trading involves substantial risk. Past performance ≠ future results. Consult professionals before investing.