REX-AI is not a registered investment, legal or tax advisor or a broker/dealer. All investment or financial opinions expressed or predicted by the model are from personal research and experience of the owners and are intended as educational material.
IMPORTANT WARNINGS:
- 📚 Educational purposes only - This is a research project, not professional trading advice
- 💰 Trading involves substantial risk - You can lose all your invested capital
- 🚫 Not financial advice - Always consult with licensed financial advisors
- ⚖️ Use at your own risk - The authors are not liable for any trading losses
- 🧪 Test thoroughly - Always test with paper trading before risking real money
- 📊 Past performance ≠ Future results - Historical data doesn't guarantee future profits
REX-AI is a sophisticated Forex Automated Trading System that combines deep learning with quantitative finance. When properly trained and configured, it can predict forex price movements one hour ahead, manage risk intelligently, and execute trades automatically through the Oanda broker API.
The system processes historical forex data through a multi-tiered pipeline, applies advanced technical indicators, trains LSTM (Long Short-Term Memory) neural networks on patterns, and generates trading signals with confidence scores and risk assessments.
- 🧠 Deep Learning Models - 6 LSTM/RNN model variants trained on 17+ years of data
- 📊 28 Currency Pairs - Comprehensive forex market coverage (EUR/USD, GBP/JPY, etc.)
- 📈 Technical Indicators - 50+ indicators including RSI, EMA, Bollinger Bands, ATR
- 🔮 COT Analysis - CFTC Commitment of Traders data integration for sentiment analysis
- 📉 ARIMA-GARCH - Time series forecasting and volatility modeling
- 🎯 Risk Management - Position sizing, stop-loss, take-profit automation
- 📱 Interactive Dashboard - Real-time visualization with Dash/Plotly
- 🐳 Docker Support - Containerized deployment for cloud scalability
- ⚡ Oanda API Integration - Live trading and historical data access
- 📓 Research Notebooks - 17+ Jupyter notebooks for analysis and experimentation
- 🔄 Auto-Update - Continuous data pipeline for latest market information
- 🌐 Cloud Ready - Designed for GCP/AWS deployment
- 📊 Multi-Timeframe - Support for S5, M1, M15, H1, H8, D intervals
- 💾 Persistent Storage - Local database with yearly data organization
- Python 3.9 or higher
- pip package manager
- Oanda broker account (practice or live)
- 10GB+ disk space for historical data
# Clone the repository
git clone https://github.com/alexcolls/rex-ai.git
cd rex-ai
# Install dependencies
python setup.py install
# or
pip install -r requirements.txt# Install with Poetry
poetry install
# Activate environment
poetry shellCreate a .env file in the project root:
cp .env.sample .envAdd your Oanda API credentials:
OANDA_API_KEY=your_api_key_here
OANDA_ACCOUNT_ID=your_account_id_here
OANDA_ENVIRONMENT=practice # or 'live' for real tradingAlternatively, edit db/bin/apis/oanda_key.json:
{
"PUBLIC_TOKEN": "your_public_token_here",
"PRIVATE_TOKEN": "your_private_token_for_live_trading"
}Edit db/bin/config.py to customize:
# Trading universe - select currency pairs
SYMBOLS = [
'EUR_USD', 'GBP_USD', 'USD_JPY', 'AUD_USD',
# ... add/remove pairs as needed
]
# Timeframe - model granularity
TIMEFRAME = 'H1' # Options: S5, M1, M15, H1, H8, D
# Database start year
START_YEAR = 2010 # Download data from this year onwards# Initialize the system (downloads historical data)
python first_run.pyThe script will:
- Check Python installation
- Install/update dependencies
- Prompt for data download options:
- Option A: Last 3 years (1-2 hours)
- Option B: Last 10 years (6-12 hours)
- Option C: Full history since 2005 (12-24 hours)
Note: First-time data download requires stable internet and can take hours. Keep the process running.
# Update with latest market data
python db/bin/update_db.py# Train all 6 model variants on all currency pairs
cd models/m1
python m1.py
# Repeat for m2, m3, m4, m5, m6Models are saved as .h5 files in their respective directories.
# Start the interactive dashboard
python frontend/dash_db.pyAccess at http://localhost:8050 to visualize:
- Cumulative log returns
- Volatility charts
- Price action across timeframes
- Model performance metrics
cd systems/s1
python install.py # First time only
python run.py # Execute trading algorithmFollow terminal instructions carefully. Start with paper trading!
- Machine Learning: TensorFlow/Keras (LSTM, RNN), Scikit-learn
- Data Processing: Pandas, NumPy, Statsmodels, Arch (GARCH)
- Visualization: Dash, Plotly, Matplotlib
- API Integration: Requests (Oanda REST API)
- Testing: Pytest
- Deployment: Docker, Python 3.9
rex-ai/
├── db/ # Database and data processing
│ ├── bin/ # Core processing scripts
│ │ ├── apis/ # Oanda API integration
│ │ │ ├── oanda_api.py
│ │ │ └── oanda_key.json
│ │ ├── cot/ # CFTC COT data processing
│ │ ├── config.py # Main configuration
│ │ ├── data_primary.py # Raw data download
│ │ ├── data_secondary.py # Feature engineering
│ │ ├── data_tertiary.py # Advanced processing
│ │ ├── indicators.py # Technical indicators
│ │ ├── volatility.py # Volatility models
│ │ ├── risk_management.py # Position sizing
│ │ └── update_db.py # Database updater
│ └── data/ # Stored market data
│ ├── primary/ # Raw OHLCV data by year
│ ├── secondary/ # Processed features
│ └── tertiary/ # ML-ready datasets
├── models/ # Machine learning models
│ ├── m1/ # LSTM Model 1
│ ├── m2/ # LSTM Model 2 (variant)
│ ├── m3/ # LSTM Model 3 (variant)
│ ├── m4/ # RNN Model 1
│ ├── m5/ # RNN Model 2 (variant)
│ └── m6/ # Ensemble model
├── systems/ # Trading execution systems
│ ├── s1/ # Trading system 1
│ └── s2/ # Trading system 2
├── notebooks/ # Research & analysis
│ ├── alex/ # Contributor notebooks
│ ├── marti/
│ ├── paul/
│ └── roger/
├── frontend/ # Web dashboard
│ └── dash_db.py
├── docker/ # Docker deployment
│ ├── Dockerfile
│ └── requirements.txt
├── first_run.py # Initial setup script
├── requirements.txt # Python dependencies
├── setup.py # Package installer
└── README.md # This file
┌─────────────┐ ┌──────────────┐ ┌──────────────┐
│ PRIMARY │────▶│ SECONDARY │────▶│ TERTIARY │
│ │ │ │ │ │
│ Raw OHLCV │ │ Technical │ │ ML Features │
│ from Oanda │ │ Indicators │ │ + COT Data │
│ │ │ │ │ │
│ - Open │ │ - RSI │ │ - Normalized │
│ - High │ │ - EMA │ │ - Sequences │
│ - Low │ │ - Bollinger │ │ - Labels │
│ - Close │ │ - ATR │ │ - Train/Test │
│ - Volume │ │ - Momentum │ │ Splits │
└─────────────┘ └──────────────┘ └──────────────┘
│
▼
┌─────────────────┐
│ LSTM MODELS │
│ │
│ Predict 1h │
│ Price Movement │
│ (Buy/Sell/Hold)│
└─────────────────┘
Each model (m1-m6) implements an LSTM-based architecture:
Sequential([
LSTM(200, activation='tanh', input_shape=(features, 1)),
Dropout(0.2),
Dense(200, activation='tanh'),
Dropout(0.2),
Dense(3, activation='softmax') # Buy / Hold / Sell
])Hyperparameters:
- Epochs: 100 (with early stopping)
- Neurons: 200 per layer
- Threshold: ±5% for classification
- Train split: 2010-2017
- Validation: 2018-2020
- Test: 2021-2022
docker build -t rex-ai-data docker/docker volume create rex-ai-datadocker run -d \
-v rex-ai-data:/data \
-e OANDA_API_KEY=your_key \
rex-ai-data:latestThe container automatically:
- Creates data directories
- Updates the database
- Processes new data hourly
- Provider: Oanda Corporation
- Access: REST API v3
- Coverage: 28 forex pairs
- History: 2005 to present
- Granularity: Second, Minute, Hour, Day bars
- Rate Limits: 5000 candles per request
- Provider: Commodity Futures Trading Commission
- Type: Commitment of Traders (Disaggregated Futures)
- Purpose: Institutional positioning data for sentiment analysis
- Frequency: Weekly reports
- Coverage: 8 major currencies
Explore the notebooks/ directory for experimental analysis:
- Data exploration - Statistical properties of forex data
- Feature engineering - Indicator effectiveness testing
- Model comparisons - Performance across architectures
- Backtesting results - Historical strategy validation
Edit db/bin/indicators.py:
def your_custom_indicator(df, window=14):
"""
Add your technical indicator logic here
"""
data = pd.DataFrame([])
for currency in df.columns:
data[f'{currency}_custom'] = df[currency].rolling(window).apply(your_logic)
data.index = df.index
return dataThen update data_tertiary.py to include it in the pipeline.
# Run unit tests
pytest
# Run specific test file
pytest tests/test_indicators.py| Model | Type | Description | Best For |
|---|---|---|---|
| m1 | LSTM | Base model with standard features | EUR/USD, GBP/USD |
| m2 | LSTM | Extended lookback period | Trending markets |
| m3 | LSTM | Volatility-focused features | High volatility |
| m4 | RNN | Simpler recurrent architecture | Faster training |
| m5 | RNN | Deep variant (3+ layers) | Complex patterns |
| m6 | Ensemble | Combines predictions from m1-m5 | Overall best |
Performance Metrics (Validation Set):
- Precision: 55-62% (varies by pair and timeframe)
- Loss: 0.65-0.85 (categorical crossentropy)
- Sharpe Ratio: 0.8-1.5 (backtested)
Note: Results vary significantly by market conditions. Always validate with recent data.
Built-in risk controls in db/bin/risk_management.py:
- Position Sizing - Kelly Criterion and fixed fractional
- Stop Loss - ATR-based dynamic stops
- Take Profit - Risk-reward ratio targets
- Max Drawdown - Portfolio-level limits
- Correlation Filter - Avoid over-exposure to correlated pairs
Before Live Trading:
- ✅ Test extensively with paper/demo account (months, not days)
- ✅ Understand every line of code you're running
- ✅ Start with minimum position sizes
- ✅ Monitor 24/7 initially - algo trading isn't "set and forget"
- ✅ Have emergency stop procedures ready
- ✅ Comply with your jurisdiction's trading regulations
- ✅ Keep detailed logs and records for taxes
- ❌ Never risk money you can't afford to lose
- ❌ Don't over-leverage or chase losses
- ❌ Don't trust the model blindly - markets change
Contributions are welcome! This is a research project and improvements are always appreciated.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m '✨ Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow PEP 8 style guidelines for Python
- Add docstrings to all functions
- Include unit tests for new features
- Update documentation as needed
- Use meaningful commit messages with emojis
- Test thoroughly before submitting PR
- 📊 Additional technical indicators
- 🧠 Transformer-based models (attention mechanisms)
- 🔄 Real-time streaming data pipeline
- 📱 Mobile app for monitoring
- 🌐 Multi-broker support (beyond Oanda)
- 📈 Cryptocurrency trading integration
- 🧪 More robust backtesting framework
- 🔐 Enhanced security and encryption
REX-AI is a collaborative research project developed by a team of quantitative finance and machine learning enthusiasts.
|
Alex Colls Lead Developer & Architecture 152 commits |
Martí Llanes ML Models & Data Science 57 commits |
Roger Solé Quantitative Analysis 47 commits |
Paul Bogumilo Risk Management & Systems 25 commits |
Each team member has contributed research notebooks in their respective directories:
- 📂
notebooks/alex/- Core architecture and system design - 📂
notebooks/marti/- Machine learning model experiments - 📂
notebooks/paul/- Risk management strategies - 📂
notebooks/roger/- Quantitative analysis and backtesting
We welcome contributions from the community! See the Contributing section above for guidelines.
Copyright (c) 2022 Quantium Rock
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Built with TensorFlow, Keras, Pandas, Scikit-learn, Dash, and Oanda API.
Key Libraries:
- TensorFlow/Keras - Deep learning framework
- Pandas - Data manipulation and analysis
- NumPy - Numerical computing
- Statsmodels - ARIMA time series models
- Arch - GARCH volatility models
- Plotly/Dash - Interactive visualizations
- Scikit-learn - Machine learning utilities
- BeautifulSoup - Web scraping for COT data
Data Providers:
- Oanda - Forex market data and execution
- CFTC - Commitment of Traders reports
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: See
notebooks/for detailed examples
If this project helped you learn about algorithmic trading or AI, please consider:
- ⭐ Starring the repository
- 🐛 Reporting bugs
- 💡 Suggesting features
- 🤝 Contributing code
- 📢 Sharing with others
- 💬 Joining discussions
Made with ❤️ and 🐍 Python
Where Algorithmic Trading Meets Deep Learning
© 2022 REX-AI | MIT License | For Educational Purposes Only