An AI-powered hedge fund analysis platform that uses charts and personas to analyze the 200 biggest companies on US markets and generate a list of potential investment long/short opportunities.
Hedgehog uses a graph-based workflow powered by Pydantic AI with agent functions and OpenRouter to simulate a complete investment analysis process. The system employs multiple specialized agents, each focusing on different aspects of company analysis:
- Fundamental Analysis Agent - Evaluates company financials and business health
- Technical Analysis Agent - Analyzes price patterns and technical indicators
- Sentiment Analysis Agent - Assesses market sentiment from news and social media
- Valuation Analysis Agent - Calculates intrinsic value using DCF and comparable methods
- Warren Buffett Agent - Applies Warren Buffett's investment principles
- Bill Ackman Agent - Applies Bill Ackman's investment principles
- Risk Manager Agent - Evaluates position and portfolio risk
- Portfolio Manager Agent - Makes final investment decisions
The analysis workflow is orchestrated through Pydantic AI's Graph feature, which creates a directed graph of analysis steps, automatically handling the flow of data between agents.
- Python 3.12+
- uv (modern Python package installer)
-
Clone the repository: """ git clone https://github.com/yourusername/hedgehog.git cd hedgehog """
-
Create a virtual environment and install dependencies: """ python -m venv .venv source .venv/bin/activate On Windows: .venv\Scripts\activate uv pip install -e . """
-
Set up environment variables by creating a
.env
file with your API keys: """ OPENROUTER_API_KEY=your_openrouter_api_key FINANCIAL_DATASETS_API_KEY=your_financial_data_api_key CHART_IMG_API_KEY=your_chart_image_api_key LOGFIRE_TOKEN=your_logfire_token STAGE=dev """
To analyze a single stock or a list of stocks:
""" python -m hedgehog.main analyze AAPL MSFT GOOGL """
This will run a comprehensive analysis for each ticker and provide investment recommendations.
Optional parameters:
--model
: Specify a different model for analysis (default: anthropic/claude-3.5-sonnet)
To backtest the AI hedge fund strategy on historical data:
""" python -m hedgehog.main backtest AAPL MSFT GOOGL AMZN NVDA --start 2023-01-01 --end 2023-12-31 """
Optional parameters:
--capital
: Initial capital (default: $1,000,000)--max-positions
: Maximum number of positions allowed (default: 10)--position-size
: Maximum position size as percentage (default: 10.0%)--rebalance
: Rebalance frequency in days (default: 30)--no-stop-loss
: Disable stop-loss for positions
""" hedgehog/ ├── agents/ # Specialized analysis agents │ ├── bill_ackman.py # Bill Ackman investment 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 │ └── warren_buffett.py # Warren Buffett investment agent ├── tools/ # API tools for data access │ └── api.py # API client tools ├── backtester.py # Backtesting tools ├── graph_workflow.py # Pydantic AI Graph workflow ├── logfire_setup.py # Logging configuration ├── main.py # CLI entry point └── predict.py # Basic prediction module """
The core of the system is built on Pydantic AI's Graph feature, which creates a directed graph workflow:
- Data Fetching Nodes - Fetch company, price history, news, and peer data
- Analysis Nodes - Run specialized agent functions for different analysis types
- Decision Nodes - Synthesize all analyses into an investment decision
- Compilation Nodes - Combine all results into a comprehensive output
Each node in the graph is a Pydantic AI-powered function that leverages large language models through OpenRouter to perform specific parts of the analysis.
The system uses strongly-typed Pydantic models throughout to ensure data consistency and validation:
- Analysis result models for each agent type
- Investment decision models
- Backtest models for simulating performance
Models are accessed through OpenRouter, allowing flexibility to use different LLM providers:
- OpenAI models (e.g., GPT-4)
- Anthropic models (e.g., Claude 3)
- Other providers supported by OpenRouter
- Multi-Agent Analysis: Employs specialized agents for comprehensive investment analysis
- Graph-Based Workflow: Orchestrates complex analysis processes efficiently
- Backtesting: Test investment strategies against historical data
- Model Flexibility: Switch between different LLM providers via OpenRouter
- Strongly-Typed: Uses Pydantic models throughout for robust data handling
This project is for educational and research purposes only and is not intended for real trading. The AI-generated investment recommendations should not be considered financial advice. Always consult with a qualified financial advisor before making investment decisions.
MIT
Inspired by virattt/ai-hedge-fund
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request