An AI-assisted trading platform that combines quantitative analysis, machine learning, and large language models to trade call debit spreads autonomously.
- AI-Powered Analysis: GPT-4/Claude integration for market thesis scoring
- Machine Learning: Gradient boosting classifier for entry prediction
- Options Analytics: Advanced Greeks computation using optlib
- Strategy Optimization: Parameter optimization using Optuna
- Real-time Execution: Alpaca API integration for live trading
- Comprehensive Dashboard: Streamlit UI for monitoring and control
- Risk Management: Automated position sizing and exit strategies
- Performance Analytics: Detailed trade journal and insights
-
Data Ingestion (
src/data_ingestion/)- Market data fetching via optlib integration
- Technical indicator computation
- Option chain analysis with Greeks
-
Spread Constructor (
src/spread_constructor/)- Call debit spread identification
- Strike selection based on delta targets
- Risk/reward optimization
-
AI Analysis (
src/llm_integration/,src/ml_classifier/)- LLM thesis scoring (OpenAI/Anthropic)
- ML entry classification
- Pattern recognition and insights
-
Strategy Optimizer (
src/optimizer/)- Parameter optimization using Optuna
- Backtesting with optionlab
- Performance validation
-
Trade Execution (
src/trade_execution/)- Alpaca API integration
- Multi-leg order management
- Position monitoring and exits
-
Analytics (
src/trade_journal/)- Performance tracking
- AI model evaluation
- Insight generation
- Backend: FastAPI, SQLAlchemy, PostgreSQL
- Frontend: Streamlit
- AI/ML: OpenAI GPT-4, Anthropic Claude, Scikit-learn, Optuna
- Options: optlib, optionlab
- Trading: pyalgostrategypool, Alpaca API
- Deployment: Docker, Docker Compose
- Python 3.11+
- Docker & Docker Compose
- API Keys:
- OpenAI API key
- Anthropic API key
- Alpaca API key (paper trading recommended)
- Polygon.io API key (optional)
- Clone the repository
git clone <repository-url>
cd ai_call_debit_spread_trader- Set up environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt- Configure environment variables
cp .env.example .env
# Edit .env with your API keys- Install external dependencies
cd external/optlib && pip install -e .
cd ../pyalgostrategypool && pip install -e .
cd ../..- Initialize database
python -c "from src.core.database import create_tables; create_tables()"- Run the application
# Start FastAPI backend
uvicorn src.api.main:app --reload --port 8000
# Start Streamlit dashboard (new terminal)
streamlit run src/dashboard_ui/app.py --server.port 8501- Configure environment
cp .env.example .env
# Edit .env with your production settings- Deploy with Docker Compose
docker-compose up -d- Access the application
- API: http://localhost:8000
- Dashboard: http://localhost:8501
- API Docs: http://localhost:8000/docs
# API Keys
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
ALPACA_API_KEY=your_alpaca_api_key
ALPACA_SECRET_KEY=your_alpaca_secret_key
# Trading Configuration
MAX_RISK_PER_TRADE=0.02
MAX_POSITIONS=5
PAPER_TRADING=true
# Database
DATABASE_URL=postgresql://user:password@localhost/ai_trader- Risk Management: 2% max risk per trade, 5 max positions
- Target Deltas: Long ~0.5, Short ~0.3
- Exit Strategy: 80% profit target, 50% stop loss
- Expiration Range: 20-60 days
# Via API
POST /spreads/scan
{
"symbols": ["SPY", "QQQ", "AAPL"],
"max_spreads_per_symbol": 3
}
# Via Dashboard
# Navigate to "AI Spreads" page and click "Scan Spreads"The system automatically:
- Scores setups using LLM reasoning (70+ confidence threshold)
- Predicts win probability using ML model (60%+ threshold)
- Filters candidates based on combined AI signals
# Paper trading enabled by default
POST /trades/execute
{
"spread_id": "SPY_450_455_2024-03-15",
"quantity": 1
}- Real-time position tracking
- Automated exit management
- Comprehensive performance analytics
- AI-generated insights
# Run unit tests
pytest tests/
# Run integration tests
pytest tests/integration/
# Test API endpoints
pytest tests/api/
# Test ML models
pytest tests/ml/- Expected Win Rate: 65-75%
- Risk/Reward Ratio: 1.5-2.0
- Maximum Drawdown: <15%
- Sharpe Ratio: >1.5
- LLM Correlation: 0.3-0.5 with actual outcomes
- ML Accuracy: 70-80% on historical data
- Combined Signals: 80%+ win rate for high-confidence trades
- Environment variable protection
- API key encryption
- Secure database connections
- Rate limiting on API endpoints
- Position size limits
- Maximum drawdown protection
- Correlation limits across positions
- Real-time risk monitoring
- Automatic trade halting on API failures
- Model performance monitoring
- Emergency position closure capabilities
- Build and push Docker images
docker build -t ai-trader:latest .
docker tag ai-trader:latest your-ecr-repo/ai-trader:latest
docker push your-ecr-repo/ai-trader:latest- Deploy to ECS
- Use provided ECS task definitions
- Configure load balancer for API
- Set up CloudWatch monitoring
- Prometheus metrics collection
- Grafana dashboards
- CloudWatch alarms
- Slack/email notifications
Visit /docs endpoint for interactive API documentation.
GET /health- Health checkPOST /spreads/scan- Scan for spreadsGET /spreads/optimize- Strategy optimizationPOST /trades/execute- Execute tradesGET /analytics/performance- Performance metricsGET /analytics/insights- AI insights
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This software is for educational and research purposes only. Trading options involves substantial risk and is not suitable for all investors. Past performance does not guarantee future results. Always paper trade and thoroughly test strategies before risking real capital.
- optlib: Options pricing and Greeks computation
- optionlab: Strategy simulation and payoff analysis
- pyalgostrategypool: Backtesting infrastructure
- Alpaca Markets: Trading API and execution
- OpenAI & Anthropic: AI model providers
For support, email [email protected] or open an issue on GitHub.
¡ Ready to revolutionize your options trading with AI? Get started today!