Apidog

All-in-one Collaborative API Development Platform

API Design

API Documentation

API Debugging

API Mocking

API Automated Testing

Someone Has Built an Open Source AI Hedge Fund, Let's Check It Out!

Create your own AI Hedge Fund with this beginner-friendly guide! Simulate trades with AI agents for stocks like AAPL and MSFT, learn trading strategies, and explore sentiment analysis—all for free!

Ashley Goolam

Ashley Goolam

Updated on May 26, 2025

Have you ever wondered how Wall Street’s elite use AI to rake in millions? With the AI Hedge Fund project, you can dive into the world of automated trading without risking a dime. This open-source gem from GitHub lets you simulate a hedge fund powered by AI agents inspired by legends like Warren Buffett and Cathie Wood. I got hooked exploring its trading strategies, and in this tutorial, I’ll show you how to set up your own AI Hedge Fund, run a trading simulation with stocks like Apple and Microsoft, and peek under the hood of its brainy agents. No finance PhD needed—just curiosity and a laptop! Ready to play hedge fund manager? Let’s roll!

💡
Need to document your APIs? Try APIdog for a slick, interactive way to create and share API docs—perfect for your AI trading projects!
button

What is the AI Hedge Fund? Your Virtual Trading Team

The AI Hedge Fund is an open-source project on GitHub that simulates a hedge fund using AI agents to make trading decisions. You can think of it as a digital dream team where each agent has a specialty, mimicking real-world investing gurus. Built for educational purposes, it uses large language models (LLMs) like GPT-4o or Llama 3 to analyze financial data and simulate trades—no real money involved. Key features include:

  • Specialized Agents: Fundamentals, Technicals, Sentiment, Risk Manager, and Portfolio Manager analyze data and make decisions.
  • Data Sources: Pulls free financial data for stocks like AAPL, MSFT, NVDA, GOOGL, and TSLA via the Financial Datasets API.
  • Customizable: Run it with cloud-based LLMs (OpenAI, Groq) or local models via Ollama.
  • Simulation: Backtests strategies to see how trades would’ve performed.

With 2K+ stars, it’s a hit for learning how AI is shaking up hedge funds. Let’s set it to trade smarter than a Wall Street bro!

ai hedge fund architecture

Setting Up Your AI Hedge Fund Environment

Before we unleash your AI Hedge Fund, let’s prep your system. This is beginner-friendly, and I’ll guide you through each step.

1. Check System Requirements:

  • OS: Windows (with WSL2), macOS, or Linux (Ubuntu 20.04+ recommended).
  • Software:
  • Python 3.10 (check with python3 --version).
  • Git (check with git --version).
  • Docker CLI or Docker Desktop for Ollama (optional, for local LLMs).
  • If you’re on Windows, install WSL2 WSL2 by running wsl --install in PowerShell (Admin) and reboot. Missing anything? Install it now from python.org or git-scm.com.

2. Install Poetry: Poetry manages Python dependencies. Install it:

curl -sSL https://install.python-poetry.org | python3 -

Verify with poetry --version (e.g., 1.8.0). Add Poetry to your PATH if needed: export PATH="$HOME/.local/bin:$PATH".

3. Get API Keys:

  • OpenAI: Sign up at platform.openai.com for GPT-4o access. Copy your API key.
  • Financial Datasets: Register at financialdatasets.ai for free stock data (AAPL, MSFT, etc.). Copy the key.
  • Optional: Groq (groq.com) or Anthropic (anthropic) keys for other LLMs, or Ollama for local models.

4. Create a Project Folder: Stay organized:

mkdir ai-hedge-fund
cd ai-hedge-fund

Installing the AI Hedge Fund

Now, let’s clone and set up the AI Hedge Fund project. It’s quick and sets you up for trading simulations.

1. Clone the Repository: Grab the code from GitHub:

git clone https://github.com/virattt/ai-hedge-fund.git
cd ai-hedge-fund

This pulls the project (~50MB), including agent scripts and tools.

2. Install Dependencies: Use Poetry to install required libraries:

poetry install

This sets up Python packages like pandas, requests, and LLM SDKs. It takes a minute or two.

3. Configure API Keys: Create a .env file to store your keys:

cp .env.example .env

Edit .env with a text editor (e.g., nano .env) and add:

# 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

Save and exit. For local LLMs, skip OpenAI and use Ollama (see below).

4. Optional: Set Up Ollama for Local LLMs: Want to run models like Llama 3 locally? Install Ollama:

curl -fsSL https://ollama.com/install.sh | sh
ollama pull llama3

Start Ollama: ollama serve. This uses ~5GB for Llama 3. Ensure Docker is installed (docker.com) if running via Docker.

ollama

Running Your AI Hedge Fund: A Trading Simulation

Let’s fire up your AI Hedge Fund and simulate trades on stocks like Apple (AAPL) and Microsoft (MSFT). We’ll see how the AI agents work together.

1. Run the Simulation: In the ai-hedge-fund folder, execute:

poetry run python src/main.py --ticker AAPL,MSFT

Or, for local LLMs:

poetry run python src/main.py --ticker AAPL,MSFT --ollama

This command:

  • Targets AAPL and MSFT (free data from Financial Datasets).
  • Uses AI agents to analyze fundamentals (e.g., P/E ratios), technicals (e.g., moving averages), sentiment (e.g., news), and risks.
  • Simulates trades and outputs decisions.

2. What Happens?: The agents collaborate:

  • Fundamentals Agent: Checks AAPL’s revenue growth and MSFT’s cash flow.
  • Technicals Agent: Analyzes 50-day moving averages for buy/sell signals.
  • Sentiment Agent: Scans news for positive/negative vibes (e.g., “Apple launches new iPhone”).
  • Risk Manager: Sets position limits to avoid big losses.
  • Portfolio Manager: Decides to buy 100 AAPL shares and hold MSFT based on signals.
run tests

View Results: Check the terminal for trade decisions, probabilities, and backtest results. Logs are saved in src/logs/.

3. Running the Backtester: use the following command:

poetry run python src/backtester.py --ticker AAPL,MSFT,NVDA

Sample Output:

backtest

You also have the option to specify the start and end dates to backtest over a specific time period.

# 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
How to Download and Use Ollama to Run LLMs Locally
The world of Artificial Intelligence (AI) is evolving at breakneck speed, with Large Language Models (LLMs) like ChatGPT, Claude, and Gemini capturing imaginations worldwide. These powerful tools can write code, draft emails, answer complex questions, and even generate creative content. However, usi…

Exploring AI Hedge Fund Features

Your AI Hedge Fund is more than a script—it’s a learning playground. Here’s how to dig deeper:

  • Agent Customization: Edit agent scripts in src/agents/ (e.g., bill_ackman.py for activist investing). Tweak strategies like buying undervalued stocks.
  • Add Stocks: Try NVDA or TSLA in the --ticker flag (requires a Financial Datasets API key for non-free stocks).
  • Backtesting: The backtester.py tool simulates historical performance. Run poetry run python src/backtester.py --ticker AAPL to see past returns.
  • Sentiment Analysis: The Sentiment Agent uses NLP to parse news and social media, boosting decision accuracy. Test it with: “Analyze NVDA news sentiment.”
  • Run Locally: Use Ollama with llama3 for offline trading simulations, saving API costs.

I tweaked the Technicals Agent to focus on RSI (Relative Strength Index) and saw sharper buy signals—super fun to experiment!

Documenting Your APIs with APIdog

Building on your AI Hedge Fund and want to document its APIs for others? APIdog is a top-notch tool for creating interactive API docs. Its sleek design and self-hosting options make it perfect for sharing your trading system’s endpoints—give it a spin!

apidog documentation

Troubleshooting and Tips

  • API Key Errors: Ensure .env keys match your OpenAI/Financial Datasets accounts. Check with cat .env.
  • Dependency Issues: If poetry install fails, update Poetry: poetry self update.
  • Ollama Not Connecting: Verify ollama serve is running and port 11434 is open (netstat -tulpn | grep 11434 on Linux).
  • Performance: For faster runs, use a GPU with Ollama or stick to cloud LLMs like GPT-4o.
  • Community: Join the project’s GitHub Discussions for help or to share your custom agents.

Why Use an AI Hedge Fund?

This AI Hedge Fund project is a goldmine for learning:

  • Educational: Understand how AI drives trading at firms like Two Sigma.
  • No Risk: Simulate trades without losing money.
  • Customizable: Tweak agents to match your investing style.
  • Cutting-Edge: Uses LLMs and NLP, mirroring real hedge fund tech.

It’s like a finance lab where you’re the mad scientist. I loved seeing the Sentiment Agent catch bullish news on MSFT and adjust trades!

Final Thoughts: Become an AI Trading Pro

Congrats—you’ve launched your own AI Hedge Fund and simulated trades like a Wall Street wizard! From setting up AI agents to running trades on AAPL and MSFT, you’re now part of the AI investing revolution. Experiment with new stocks, tweak agents, or document your APIs with APIdog. Share your AI Hedge Fund tweaks on X or GitHub—I’m pumped to see your trading empire grow! Happy simulating!

button
How to Use The Coinbase API: A Step by Step GuideViewpoint

How to Use The Coinbase API: A Step by Step Guide

This guide provides a detailed technical exploration of the Coinbase Exchange API, focusing on practical implementation, core functionalities, and operational best practices.

Rebecca Kovács

May 27, 2025

How to Use the Google Gen AI TypeScript/JavaScript SDK to Build Powerful Generative AI ApplicationsViewpoint

How to Use the Google Gen AI TypeScript/JavaScript SDK to Build Powerful Generative AI Applications

The world of Artificial Intelligence is rapidly evolving, and Google is at the forefront with its powerful Gemini models. For TypeScript and JavaScript developers looking to harness this power, the Google Gen AI SDK provides a comprehensive and flexible solution. This SDK empowers you to easily build applications fueled by Gemini 2.5 and other cutting-edge models, offering robust support for both the Gemini Developer API and Vertex AI. This article will be your guide to understanding and utilizi

Mark Ponomarev

May 27, 2025

A Complete Guide to Cursor's New Pricing: Subscriptions and Request QuotasViewpoint

A Complete Guide to Cursor's New Pricing: Subscriptions and Request Quotas

Delve into the intricacies of Cursor pricing, from its subscription plans and request quotas to the differences between Normal and Max modes. Understand how Cursor models cost. Stop guessing and start coding smarter with Cursor and Apidog!

Oliver Kingsley

May 27, 2025