This is a proof of concept for an AI-powered hedge fund. The goal of this project is to explore the use of AI to make trading decisions. This project is for educational purposes only and is not intended for real trading or investment.
This system employs several agents working together:
- Aswath Damodaran Agent - The Dean of Valuation, focuses on story, numbers, and disciplined valuation
- Ben Graham Agent - The godfather of value investing, only buys hidden gems with a margin of safety
- Bill Ackman Agent - An activist investor, takes bold positions and pushes for change
- Cathie Wood Agent - The queen of growth investing, believes in the power of innovation and disruption
- Charlie Munger Agent - Warren Buffett's partner, only buys wonderful businesses at fair prices
- Michael Burry Agent - The Big Short contrarian who hunts for deep value
- Mohnish Pabrai Agent - The Dhandho investor, who looks for doubles at low risk
- Peter Lynch Agent - Practical investor who seeks "ten-baggers" in everyday businesses
- Phil Fisher Agent - Meticulous growth investor who uses deep "scuttlebutt" research
- Rakesh Jhunjhunwala Agent - The Big Bull of India
- Stanley Druckenmiller Agent - Macro legend who hunts for asymmetric opportunities with growth potential
- Warren Buffett Agent - The oracle of Omaha, seeks wonderful companies at a fair price
- Valuation Agent - Calculates the intrinsic value of a stock and generates trading signals
- Sentiment Agent - Analyzes market sentiment and generates trading signals
- Fundamentals Agent - Analyzes fundamental data and generates trading signals
- Technicals Agent - Analyzes technical indicators and generates trading signals
- Risk Manager - Calculates risk metrics and sets position limits
- Portfolio Manager - Makes final trading decisions and generates orders
Note: the system does not actually make any trades.
This project is for educational and research purposes only.
- Not intended for real trading or investment
- No investment advice or guarantees provided
- Creator assumes no liability for financial losses
- Consult a financial advisor for investment decisions
- Past performance does not indicate future results
By using this software, you agree to use it solely for learning purposes.
- How to Install
- How to Run
- Environment Variables Reference
- How to Contribute
- Feature Requests
- License
Before you can run the AI Hedge Fund, you'll need to install it and set up your API keys. These steps are common to both the full-stack web application and command line interface.
git clone https://github.com/virattt/ai-hedge-fund.git
cd ai-hedge-fundCreate a .env file for your API keys:
# Create .env file for your API keys (in the root directory)
cp .env.example .envOpen and edit the .env file to add your API keys:
# For running LLMs hosted by openai (gpt-4o, gpt-4o-mini, etc.)
OPENAI_API_KEY=your-openai-api-key
# For getting financial data to power the hedge fund
FINANCIAL_DATASETS_API_KEY=your-financial-datasets-api-keyImportant: You must set at least one LLM API key (e.g. OPENAI_API_KEY, GROQ_API_KEY, ANTHROPIC_API_KEY, or DEEPSEEK_API_KEY) for the hedge fund to work.
Financial Data Options:
- Yahoo Finance (Free): Set
USE_YAHOO_FINANCE=trueto use free Yahoo Finance data for any ticker - Financial Datasets API (Paid): Use
FINANCIAL_DATASETS_API_KEYfor comprehensive data including insider trades and sentiment - Database Cache (Recommended for Backtesting): Set
USE_DATABASE=trueto use pre-cached data for 10-20x faster backtests
Note: Data for AAPL, GOOGL, MSFT, NVDA, and TSLA is free with Financial Datasets API without a key.
You can run the AI Hedge Fund directly via terminal. This approach offers more granular control and is useful for automation, scripting, and integration purposes.
- Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 -- Install dependencies:
poetry install- Set up PostgreSQL:
The system uses PostgreSQL for data caching. Choose one option:
Option A: Docker (Recommended for Development)
docker run --name ai-hedge-fund-postgres \
-e POSTGRES_PASSWORD=your_password \
-e POSTGRES_DB=ai_hedge_fund \
-p 5432:5432 \
-d postgres:16Option B: Local PostgreSQL
# macOS
brew install postgresql@16
brew services start postgresql@16
createdb ai_hedge_fund
# Ubuntu/Debian
sudo apt update && sudo apt install postgresql
sudo systemctl start postgresql
sudo -u postgres createdb ai_hedge_fund- Configure database environment variables:
Add to your .env file:
# PostgreSQL Configuration
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=ai_hedge_fund
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_password- Initialize database tables:
export POSTGRES_PASSWORD=your_password
cd app/backend
python -c "from database.init_db import init_db; init_db()"
cd ../..For optimal performance, especially when running multiple backtests, we recommend using the two-step data workflow that separates data acquisition from analysis:
Benefits:
- ⚡ 10-20x faster backtests - No API calls during analysis
- 💰 Reduced API costs - Fetch data once, reuse indefinitely
- 🔌 Offline capability - Run backtests without internet connection
- 📊 Consistent data - All backtests use the same historical snapshot
- 🔄 Better iteration - Quickly test different strategies
Step 1: Acquire and Cache Data (One-time)
# Using Yahoo Finance (free) - recommended for most users
poetry run python -m src.acquire_data \
--tickers AAPL MSFT NVDA GOOGL \
--start-date 2020-01-01 \
--end-date 2024-12-31
# With environment variable
USE_YAHOO_FINANCE=true poetry run python -m src.acquire_data \
--tickers AAPL MSFT NVDA \
--start-date 2023-01-01 \
--end-date 2023-12-31Available options:
--tickers: Space-separated list of ticker symbols (required)--start-date: Start date in YYYY-MM-DD format (required)--end-date: End date in YYYY-MM-DD format (defaults to today)--force-refresh: Re-fetch and update existing data--prices-only: Only acquire price data (skip metrics, news, etc.)
Step 2: Run Analysis with Cached Data (Fast & Repeatable)
# Run backtest using cached data - 10-20x faster!
USE_DATABASE=true poetry run python src/backtester.py \
--ticker AAPL,MSFT,NVDA \
--start-date 2023-01-01 \
--end-date 2023-12-31For detailed documentation on data caching, see docs/DATA_CACHING.md.
poetry run python src/main.py --ticker AAPL,MSFT,NVDAYou can also specify a --ollama flag to run the AI hedge fund using local LLMs.
poetry run python src/main.py --ticker AAPL,MSFT,NVDA --ollamaYou can optionally specify the start and end dates to make decisions over a specific time period.
poetry run python src/main.py --ticker AAPL,MSFT,NVDA --start-date 2024-01-01 --end-date 2024-03-01Standard Mode (with real-time API calls):
poetry run python src/backtester.py --ticker AAPL,MSFT,NVDAHigh-Performance Mode (with cached data - recommended):
# First, acquire data (one-time)
USE_YAHOO_FINANCE=true poetry run python -m src.acquire_data \
--tickers AAPL MSFT NVDA \
--start-date 2023-01-01 \
--end-date 2023-12-31
# Then run backtest with cached data (10-20x faster!)
USE_DATABASE=true poetry run python src/backtester.py \
--ticker AAPL,MSFT,NVDA \
--start-date 2023-01-01 \
--end-date 2023-12-31Note: The --ollama, --start-date, and --end-date flags work for the backtester, as well!
💡 Pro Tip: For repeated backtests with different parameters, use the two-step workflow (acquire data once, then run multiple backtests with USE_DATABASE=true) for significant time savings.
The new way to run the AI Hedge Fund is through our web application that provides a user-friendly interface. This is recommended for users who prefer visual interfaces over command line tools.
Please see detailed instructions on how to install and run the web application here.
The AI Hedge Fund supports several environment variables to configure data sources and behavior:
| Variable | Values | Description |
|---|---|---|
USE_DATABASE |
true/false |
Use cached database data (recommended for backtesting) |
USE_YAHOO_FINANCE |
true/false |
Use Yahoo Finance API (free, real-time data) |
| (none) | - | Use Financial Datasets API (paid, requires API key) |
Priority: USE_DATABASE > USE_YAHOO_FINANCE > Financial Datasets API
For Data Acquisition:
# Use Yahoo Finance to fetch and cache data
USE_YAHOO_FINANCE=true poetry run python -m src.acquire_data --tickers AAPL --start-date 2023-01-01For Backtesting:
# Use cached data for fast backtests
USE_DATABASE=true poetry run python src/backtester.py --ticker AAPL --start-date 2023-01-01For Real-time Analysis:
# Use Yahoo Finance for real-time data
USE_YAHOO_FINANCE=true poetry run python src/main.py --ticker AAPL| Mode | Speed | Cost | Use Case |
|---|---|---|---|
Database Cache (USE_DATABASE=true) |
⚡⚡⚡ Fastest (10-20x) | Free | Backtesting, strategy iteration |
Yahoo Finance (USE_YAHOO_FINANCE=true) |
⚡⚡ Fast | Free | Real-time analysis, data acquisition |
| Financial Datasets API | ⚡ Standard | Paid | Comprehensive data needs |
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
Important: Please keep your pull requests small and focused. This will make it easier to review and merge.
If you have a feature request, please open an issue and make sure it is tagged with enhancement.
This project is licensed under the MIT License - see the LICENSE file for details.