An AI-powered hedge fund that uses multiple agents to make trading decisions. The system employs several specialized agents working together:
- Market Data Agent - Gathers and preprocesses market data
- Quantitative Agent - Analyzes technical indicators and generates trading signals
- Risk Management Agent - Evaluates portfolio risk and sets position limits
- Portfolio Management Agent - Makes final trading decisions and generates orders
- Multi-agent architecture for sophisticated trading decisions
- Technical analysis using MACD, RSI, Bollinger Bands, and OBV
- Risk management with position sizing recommendations
- Portfolio management with automated trading decisions
- Backtesting capabilities with performance analytics
- Support for multiple stock tickers
Clone the repository:
git clone https://github.com/your-repo/ai-hedge-fund.git
cd ai-hedge-fund
- Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 -
- Install dependencies:
poetry install
- Set up your environment variables:
cp .env.example .env
export OPENAI_API_KEY='your-api-key-here'
export FINANCIAL_DATASETS_API_KEY='your-api-key-here'
poetry run python src/agents.py --ticker AAPL
Example Output:
{
"action": "buy",
"quantity": 50000,
}
You can optionally specify the start and end dates to make decisions for a specific time period.
poetry run python src/agents.py --ticker AAPL --start-date 2024-01-01 --end-date 2024-03-01
This will print the reasoning of each agent to the console.
poetry run python src/agents.py --ticker AAPL --show-reasoning
Example Output:
========== Quant Agent ==========
{
"signal": "bearish",
"confidence": 0.5,
"reasoning": {
"MACD": {
"signal": "neutral",
"details": "MACD Line crossed neither above nor below Signal Line"
},
"RSI": {
"signal": "bearish",
"details": "RSI is 72.07 (overbought)"
},
"Bollinger": {
"signal": "bearish",
"details": "Price is above upper band"
},
"OBV": {
"signal": "bullish",
"details": "OBV slope is 30612582.00 (bullish)"
}
}
}
========================================
========== Risk Management Agent ==========
{
"max_position_size": 10000.0,
"risk_score": 6,
"trading_action": "hold",
"reasoning": "The overall signal is bearish with moderate confidence, indicated by overbought RSI and price above the Bollinger band, suggesting potential downside. However, the bullish OBV could offset some bearish pressure. Therefore, it's prudent to hold off on new positions until clearer direction emerges."
}
========================================
========== Portfolio Management Agent ==========
{
"action": "hold",
"quantity": 0,
"reasoning": "The team's analysis indicates a bearish outlook with moderate confidence due to overbought RSI and price above the Bollinger band, while the bullish OBV suggests some counterbalancing. The risk management team recommends holding off on new positions until clearer direction emerges. Additionally, the current portfolio has no shares to sell, and the risk profile advises against new purchases."
}
========================================
poetry run python src/backtester.py --ticker AAPL
Example Output:
Starting backtest...
Date Ticker Action Quantity Price Cash Stock Total Value
----------------------------------------------------------------------
2024-01-01 AAPL buy 519.0 192.53 76.93 519.0 100000.00
2024-01-02 AAPL hold 0 185.64 76.93 519.0 96424.09
2024-01-03 AAPL hold 0 184.25 76.93 519.0 95702.68
2024-01-04 AAPL hold 0 181.91 76.93 519.0 94488.22
2024-01-05 AAPL hold 0 181.18 76.93 519.0 94109.35
2024-01-08 AAPL sell 519 185.56 96382.57 0.0 96382.57
2024-01-09 AAPL buy 520.0 185.14 109.77 520.0 96382.57
You can optionally specify the start and end dates to backtest over a specific time period.
poetry run python src/backtester.py --ticker AAPL --start-date 2024-01-01 --end-date 2024-03-01
ai-hedge-fund/
├── src/
│ ├── agents.py # Main agent definitions and workflow
│ ├── backtester.py # Backtesting functionality
│ ├── tools.py # Technical analysis tools
├── pyproject.toml # Poetry configuration
├── .env.example # Environment variables
└── README.md # Documentation
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.