``` ├── .dockerignore ├── .env.example ├── .github/ ├── ISSUE_TEMPLATE/ ├── bug_report.md ├── feature_request.md ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── docker-compose.yml ├── poetry.lock ``` ## /.dockerignore ```dockerignore path="/.dockerignore" # Git .git .gitignore # Poetry .venv __pycache__/ *.py[cod] *$py.class .pytest_cache/ # Environment .env # IDEs and editors .idea/ .vscode/ *.swp *.swo # Logs and data logs/ data/ *.log # OS specific .DS_Store Thumbs.db ``` ## /.env.example ```example path="/.env.example" # For running LLMs hosted by anthropic (claude-3-5-sonnet, claude-3-opus, claude-3-5-haiku) # Get your Anthropic API key from https://anthropic.com/ ANTHROPIC_API_KEY=your-anthropic-api-key # For running LLMs hosted by deepseek (deepseek-chat, deepseek-reasoner, etc.) # Get your DeepSeek API key from https://deepseek.com/ DEEPSEEK_API_KEY=your-deepseek-api-key # For running LLMs hosted by groq (deepseek, llama3, etc.) # Get your Groq API key from https://groq.com/ GROQ_API_KEY=your-groq-api-key # For running LLMs hosted by gemini (gemini-2.0-flash, gemini-2.0-pro) # Get your Google API key from https://console.cloud.google.com/ GOOGLE_API_KEY=your-google-api-key # For getting financial data to power the hedge fund # Get your Financial Datasets API key from https://financialdatasets.ai/ FINANCIAL_DATASETS_API_KEY=your-financial-datasets-api-key # For running LLMs hosted by openai (gpt-4o, gpt-4o-mini, etc.) # Get your OpenAI API key from https://platform.openai.com/ OPENAI_API_KEY=your-openai-api-key ``` ## /.github/ISSUE_TEMPLATE/bug_report.md --- name: Bug report about: Create a report to help us improve title: '' labels: bug assignees: '' --- **Describe the bug** A clear and concise description of what the bug is. **Screenshot** Add a screenshot of the bug to help explain your problem. **Additional context** Add any other context about the problem here. ## /.github/ISSUE_TEMPLATE/feature_request.md --- name: Feature request about: Suggest an idea for this project title: '' labels: enhancement assignees: '' --- **Describe the feature you'd like** A clear and concise description of what you want to happen. ## /.gitignore ```gitignore path="/.gitignore" # Python __pycache__/ *.py[cod] *$py.class *.so .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ *.egg-info/ .installed.cfg *.egg # Virtual Environment venv/ ENV/ # Environment Variables .env # IDE .idea/ .vscode/ *.swp *.swo .cursorrules .cursorignore .cursorindexingignore # OS .DS_Store Thumbs.db # graph *.png # Txt files *.txt # PDF files *.pdf ``` ## /Dockerfile ``` path="/Dockerfile" FROM python:3.11-slim WORKDIR /app # Install Poetry RUN pip install poetry==1.7.1 # Copy only dependency files first for better caching COPY pyproject.toml poetry.lock* /app/ # Configure Poetry to not use a virtual environment RUN poetry config virtualenvs.create false \ && poetry install --no-interaction --no-ansi # Copy rest of the source code COPY . /app/ # Default command (will be overridden by Docker Compose) CMD ["python", "src/main.py"] ``` ## /LICENSE ``` path="/LICENSE" MIT License Copyright (c) 2024 Virat Singh 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. ``` ## /README.md # AI Hedge Fund 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: 1. Ben Graham Agent - The godfather of value investing, only buys hidden gems with a margin of safety 2. Bill Ackman Agent - An activist investors, takes bold positions and pushes for change 3. Cathie Wood Agent - The queen of growth investing, believes in the power of innovation and disruption 4. Charlie Munger Agent - Warren Buffett's partner, only buys wonderful businesses at fair prices 5. Michael Burry Agent - The Big Short contrarian who hunts for deep value 6. Peter Lynch Agent - Practical investor who seeks "ten-baggers" in everyday businesses 7. Phil Fisher Agent - Meticulous growth investor who uses deep "scuttlebutt" research 8. Stanley Druckenmiller Agent - Macro legend who hunts for asymmetric opportunities with growth potential 9. Warren Buffett Agent - The oracle of Omaha, seeks wonderful companies at a fair price 10. Valuation Agent - Calculates the intrinsic value of a stock and generates trading signals 11. Sentiment Agent - Analyzes market sentiment and generates trading signals 12. Fundamentals Agent - Analyzes fundamental data and generates trading signals 13. Technicals Agent - Analyzes technical indicators and generates trading signals 14. Risk Manager - Calculates risk metrics and sets position limits 15. Portfolio Manager - Makes final trading decisions and generates orders Screenshot 2025-03-22 at 6 19 07 PM **Note**: the system simulates trading decisions, it does not actually trade. [![Twitter Follow](https://img.shields.io/twitter/follow/virattt?style=social)](https://twitter.com/virattt) ## Disclaimer This project is for **educational and research purposes only**. - Not intended for real trading or investment - No warranties or guarantees provided - Past performance does not indicate future results - Creator assumes no liability for financial losses - Consult a financial advisor for investment decisions By using this software, you agree to use it solely for learning purposes. ## Table of Contents - [Setup](#setup) - [Using Poetry](#using-poetry) - [Using Docker](#using-docker) - [Usage](#usage) - [Running the Hedge Fund](#running-the-hedge-fund) - [Running the Backtester](#running-the-backtester) - [Project Structure](#project-structure) - [Contributing](#contributing) - [Feature Requests](#feature-requests) - [License](#license) ## Setup ### Using Poetry Clone the repository: ```bash git clone https://github.com/virattt/ai-hedge-fund.git cd ai-hedge-fund ``` 1. Install Poetry (if not already installed): ```bash curl -sSL https://install.python-poetry.org | python3 - ``` 2. Install dependencies: ```bash poetry install ``` 3. Set up your environment variables: ```bash # Create .env file for your API keys cp .env.example .env ``` 4. Set your API keys: ```bash # For running LLMs hosted by openai (gpt-4o, gpt-4o-mini, etc.) # Get your OpenAI API key from https://platform.openai.com/ OPENAI_API_KEY=your-openai-api-key # For running LLMs hosted by groq (deepseek, llama3, etc.) # Get your Groq API key from https://groq.com/ GROQ_API_KEY=your-groq-api-key # For getting financial data to power the hedge fund # Get your Financial Datasets API key from https://financialdatasets.ai/ FINANCIAL_DATASETS_API_KEY=your-financial-datasets-api-key ``` ### Using Docker 1. Make sure you have Docker installed on your system. If not, you can download it from [Docker's official website](https://www.docker.com/get-started). 2. Clone the repository: ```bash git clone https://github.com/virattt/ai-hedge-fund.git cd ai-hedge-fund ``` 3. Set up your environment variables: ```bash # Create .env file for your API keys cp .env.example .env ``` 4. Edit the .env file to add your API keys as described above. 5. Build the Docker image: ```bash # On Linux/Mac: ./run.sh build # On Windows: run.bat build ``` **Important**: You must set `OPENAI_API_KEY`, `GROQ_API_KEY`, `ANTHROPIC_API_KEY`, or `DEEPSEEK_API_KEY` for the hedge fund to work. If you want to use LLMs from all providers, you will need to set all API keys. Financial data for AAPL, GOOGL, MSFT, NVDA, and TSLA is free and does not require an API key. For any other ticker, you will need to set the `FINANCIAL_DATASETS_API_KEY` in the .env file. ## Usage ### Running the Hedge Fund #### With Poetry ```bash poetry run python src/main.py --ticker AAPL,MSFT,NVDA ``` #### With Docker ```bash # On Linux/Mac: ./run.sh --ticker AAPL,MSFT,NVDA main # On Windows: run.bat --ticker AAPL,MSFT,NVDA main ``` **Example Output:** Screenshot 2025-01-06 at 5 50 17 PM You can also specify a `--ollama` flag to run the AI hedge fund using local LLMs. ```bash # With Poetry: poetry run python src/main.py --ticker AAPL,MSFT,NVDA --ollama # With Docker (on Linux/Mac): ./run.sh --ticker AAPL,MSFT,NVDA --ollama main # With Docker (on Windows): run.bat --ticker AAPL,MSFT,NVDA --ollama main ``` You can also specify a `--show-reasoning` flag to print the reasoning of each agent to the console. ```bash # With Poetry: poetry run python src/main.py --ticker AAPL,MSFT,NVDA --show-reasoning # With Docker (on Linux/Mac): ./run.sh --ticker AAPL,MSFT,NVDA --show-reasoning main # With Docker (on Windows): run.bat --ticker AAPL,MSFT,NVDA --show-reasoning main ``` You can optionally specify the start and end dates to make decisions for a specific time period. ```bash # With Poetry: poetry run python src/main.py --ticker AAPL,MSFT,NVDA --start-date 2024-01-01 --end-date 2024-03-01 # With Docker (on Linux/Mac): ./run.sh --ticker AAPL,MSFT,NVDA --start-date 2024-01-01 --end-date 2024-03-01 main # With Docker (on Windows): run.bat --ticker AAPL,MSFT,NVDA --start-date 2024-01-01 --end-date 2024-03-01 main ``` ### Running the Backtester #### With Poetry ```bash poetry run python src/backtester.py --ticker AAPL,MSFT,NVDA ``` #### With Docker ```bash # On Linux/Mac: ./run.sh --ticker AAPL,MSFT,NVDA backtest # On Windows: run.bat --ticker AAPL,MSFT,NVDA backtest ``` **Example Output:** Screenshot 2025-01-06 at 5 47 52 PM You can optionally specify the start and end dates to backtest over a specific time period. ```bash # With Poetry: poetry run python src/backtester.py --ticker AAPL,MSFT,NVDA --start-date 2024-01-01 --end-date 2024-03-01 # With Docker (on Linux/Mac): ./run.sh --ticker AAPL,MSFT,NVDA --start-date 2024-01-01 --end-date 2024-03-01 backtest # With Docker (on Windows): run.bat --ticker AAPL,MSFT,NVDA --start-date 2024-01-01 --end-date 2024-03-01 backtest ``` You can also specify a `--ollama` flag to run the backtester using local LLMs. ```bash # With Poetry: poetry run python src/backtester.py --ticker AAPL,MSFT,NVDA --ollama # With Docker (on Linux/Mac): ./run.sh --ticker AAPL,MSFT,NVDA --ollama backtest # With Docker (on Windows): run.bat --ticker AAPL,MSFT,NVDA --ollama backtest ``` ## Project Structure ``` ai-hedge-fund/ ├── src/ │ ├── agents/ # Agent definitions and workflow │ │ ├── bill_ackman.py # Bill Ackman agent │ │ ├── fundamentals.py # Fundamental analysis agent │ │ ├── portfolio_manager.py # Portfolio management agent │ │ ├── risk_manager.py # Risk management agent │ │ ├── sentiment.py # Sentiment analysis agent │ │ ├── technicals.py # Technical analysis agent │ │ ├── valuation.py # Valuation analysis agent │ │ ├── ... # Other agents │ │ ├── warren_buffett.py # Warren Buffett agent │ ├── tools/ # Agent tools │ │ ├── api.py # API tools │ ├── backtester.py # Backtesting tools │ ├── main.py # Main entry point ├── pyproject.toml ├── ... ``` ## Contributing 1. Fork the repository 2. Create a feature branch 3. Commit your changes 4. Push to the branch 5. Create a Pull Request **Important**: Please keep your pull requests small and focused. This will make it easier to review and merge. ## Feature Requests If you have a feature request, please open an [issue](https://github.com/virattt/ai-hedge-fund/issues) and make sure it is tagged with `enhancement`. ## License This project is licensed under the MIT License - see the LICENSE file for details. ## /docker-compose.yml ```yml path="/docker-compose.yml" services: ollama: image: ollama/ollama:latest container_name: ollama environment: - OLLAMA_HOST=0.0.0.0 # Apple Silicon GPU acceleration - METAL_DEVICE=on - METAL_DEVICE_INDEX=0 volumes: - ollama_data:/root/.ollama ports: - "11434:11434" restart: unless-stopped hedge-fund: build: . image: ai-hedge-fund depends_on: - ollama volumes: - ./.env:/app/.env command: python src/main.py --ticker AAPL,MSFT,NVDA environment: - PYTHONUNBUFFERED=1 - OLLAMA_BASE_URL=http://ollama:11434 tty: true stdin_open: true hedge-fund-reasoning: build: . image: ai-hedge-fund depends_on: - ollama volumes: - ./.env:/app/.env command: python src/main.py --ticker AAPL,MSFT,NVDA --show-reasoning environment: - PYTHONUNBUFFERED=1 - OLLAMA_BASE_URL=http://ollama:11434 tty: true stdin_open: true hedge-fund-ollama: build: . image: ai-hedge-fund depends_on: - ollama volumes: - ./.env:/app/.env command: python src/main.py --ticker AAPL,MSFT,NVDA --ollama environment: - PYTHONUNBUFFERED=1 - OLLAMA_BASE_URL=http://ollama:11434 tty: true stdin_open: true backtester: build: . image: ai-hedge-fund depends_on: - ollama volumes: - ./.env:/app/.env command: python src/backtester.py --ticker AAPL,MSFT,NVDA environment: - PYTHONUNBUFFERED=1 - OLLAMA_BASE_URL=http://ollama:11434 tty: true stdin_open: true backtester-ollama: build: . image: ai-hedge-fund depends_on: - ollama volumes: - ./.env:/app/.env command: python src/backtester.py --ticker AAPL,MSFT,NVDA --ollama environment: - PYTHONUNBUFFERED=1 - OLLAMA_BASE_URL=http://ollama:11434 tty: true stdin_open: true volumes: ollama_data: ``` The content has been capped at 50000 tokens, and files over NaN bytes have been omitted. The user could consider applying other filters to refine the result. The better and more specific the context, the better the LLM can follow instructions. If the context seems verbose, the user can refine the filter using uithub. Thank you for using https://uithub.com - Perfect LLM context for any GitHub repo.