An advanced algorithmic trading system for generating alpha through machine learning, sentiment analysis, and technical indicators.
Alpha Trader is a comprehensive algorithmic trading platform that implements multiple alpha-generating strategies, with a focus on:
- Machine Learning Alpha: Predicts price movements using technical features and machine learning
- Sentiment Analysis Alpha: Leverages news and social media sentiment for trading signals
- Technical Indicator Alpha: Implements classic trading strategies like moving average crossovers
The system integrates with Alpaca Markets API for paper/live trading and provides robust backtesting capabilities.
-
Multiple Alpha Strategies:
- Machine Learning strategy using Random Forest classification
- Sentiment Analysis using news and social media data
- Moving Average Crossover and other technical strategies
-
Risk Management:
- Position sizing based on model confidence
- Automatic stop-loss and take-profit orders
- Portfolio diversification controls
- Maximum drawdown protection
-
Performance Tracking:
- Real-time portfolio monitoring
- Strategy performance metrics
- Comprehensive backtesting
-
Modular Architecture:
- Easily add new strategies
- Configure strategies via JSON
- Run strategies in parallel
- Python 3.8+
- Alpaca Markets API key
- (Optional) News API and Finnhub API keys for sentiment analysis
-
Clone the repository:
git clone https://github.com/yourusername/alpha-trader.git cd alpha-trader -
Install dependencies:
pip install -r requirements.txt -
Configure your API keys:
- Copy
.env.exampleto.env - Add your Alpaca API keys and other credentials
- Copy
The system is configured via alpha_config.json. Key configuration options:
{
"ml": {
"enabled": true,
"lookback_period": 30,
"prediction_horizon": 5
},
"sentiment": {
"enabled": true,
"sentiment_lookback": 3
},
"ma_crossover": {
"enabled": true,
"short_window": 20,
"long_window": 50
}
}See the complete alpha_config.json for all configuration options.
python alpha_trader.py --symbols AAPL,MSFT,GOOG --config alpha_config.json
python strategies/backtest_alpha_strategy.py --symbol AAPL --start_date 2022-01-01 --end_date 2023-01-01 --strategy all
- alpha_trader.py: Main executor that manages all strategies
- connection.py: Handles API connectivity to Alpaca
- config.py: System-wide configuration settings
- strategies/:
- alpha_ml_strategy.py: Machine learning-based alpha generation
- sentiment_alpha_strategy.py: News and social sentiment analysis
- moving_average_crossover.py: Technical indicator strategy
- backtest_alpha_strategy.py: Backtesting framework
- Market data is fetched from Alpaca API
- Data preprocessing and feature engineering
- Alpha signal generation from multiple strategies
- Risk management and position sizing
- Order execution
- Performance monitoring and logging
- Create a new strategy file in the
strategies/directory - Implement the strategy class with at least:
__init__method with API and symbol parametersrun()method for continuous execution
- Add strategy configuration to
alpha_config.json - Import and register the strategy in
alpha_trader.py
Modify risk_management section in alpha_config.json:
"risk_management": {
"max_position_size_percent": 0.05,
"max_open_positions": 5,
"max_daily_loss": 0.02,
"stop_loss_percent": 0.02,
"take_profit_percent": 0.04
}Backtest results are saved in the results/ directory:
- Equity curves
- Performance metrics (Sharpe ratio, drawdown, win rate)
- Feature importance for ML strategies
Live trading performance is tracked in the performance/ directory:
- Portfolio value history
- Daily returns
- Drawdown history
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This software is for educational purposes only. Do not risk money which you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.