Skip to content

arunpatilgithub/portfolio_poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Portfolio POC

An AI-powered portfolio planning system built with CrewAI that uses multiple specialized agents to analyze stocks and generate investment recommendations.

๐Ÿš€ Overview

This project demonstrates how to build an intelligent portfolio planning system using CrewAI's multi-agent framework. The system consists of five specialized AI agents that work together to:

  1. Plan the portfolio strategy
  2. Analyze stock performance data
  3. Gather analyst opinions and ratings
  4. Validate the collected data
  5. Generate final portfolio recommendations

๐Ÿ—๏ธ Architecture

Agents

  • PlannerAgent: Orchestrates the portfolio planning process and coordinates other agents
  • StockPerformanceAgent: Analyzes historical stock performance and trends
  • AnalystOpinionAgent: Gathers and summarizes expert analyst ratings
  • ValidatorAgent: Validates data completeness and consistency
  • PortfolioAdvisorAgent: Allocates budget and generates final recommendations

Tools

The system uses a custom MCP (Model Context Protocol) server that provides:

  • get_market_data(): Retrieves stock price and 1-year return data
  • get_analyst_insights(): Fetches analyst ratings and consensus
  • validate_data(): Validates data structure and completeness
  • generate_portfolio(): Creates portfolio allocation based on budget and preferences

๐Ÿ“‹ Prerequisites

  • Python 3.10-3.13
  • uv package manager (recommended)

๐Ÿ› ๏ธ Installation

  1. Clone the repository

    git clone <repository-url>
    cd portfolio_poc
  2. Install dependencies

    uv sync

    Or using pip:

    pip install -r requirements.txt

๐Ÿš€ Usage

Basic Usage

Run the portfolio planning system with default settings:

uv run portfolio_poc

Or using the Python module:

python -m portfolio_poc.main

Advanced Usage

The project provides several command-line interfaces:

Run the Crew

uv run run_crew

Train the Crew

uv run train <iterations> <filename>

Replay Execution

uv run replay <task_id>

Test the Crew

uv run test <iterations> <eval_llm>

๐Ÿ“Š How It Works

  1. Initialization: The PlannerAgent selects a set of commonly recommended stocks (AAPL, MSFT, JNJ, PFE)

  2. Data Collection:

    • StockPerformanceAgent retrieves 1-year returns and current prices
    • AnalystOpinionAgent gathers buy/hold/sell ratings and consensus
  3. Validation: ValidatorAgent ensures data completeness and consistency

  4. Portfolio Generation: PortfolioAdvisorAgent allocates a $5000 budget across validated stocks, prioritizing those with positive analyst ratings

  5. Output: Returns a detailed portfolio with share allocations, total cost, and leftover cash

๐Ÿ—‚๏ธ Project Structure

portfolio_poc/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ portfolio_poc/
โ”‚   โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ agents.yaml      # Agent configurations
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ tasks.yaml       # Task definitions
โ”‚   โ”‚   โ”œโ”€โ”€ crew.py              # Main crew implementation
โ”‚   โ”‚   โ”œโ”€โ”€ main.py              # Entry points and CLI
โ”‚   โ”‚   โ””โ”€โ”€ tools/
โ”‚   โ”‚       โ””โ”€โ”€ custom_tool.py   # Custom tools
โ”‚   โ””โ”€โ”€ servers/
โ”‚       โ””โ”€โ”€ portfolio_server.py  # MCP server with portfolio tools
โ”œโ”€โ”€ knowledge/
โ”‚   โ””โ”€โ”€ user_preference.txt      # User preferences and context
โ”œโ”€โ”€ tests/                       # Test files
โ”œโ”€โ”€ pyproject.toml              # Project configuration
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ””โ”€โ”€ uv.lock                    # Lock file for dependencies

โš™๏ธ Configuration

Agents Configuration (src/portfolio_poc/config/agents.yaml)

Each agent is configured with:

  • Role: The agent's primary function
  • Goal: What the agent aims to achieve
  • Backstory: Context and expertise description

Tasks Configuration (src/portfolio_poc/config/tasks.yaml)

Tasks define the workflow with:

  • Description: What the task does
  • Expected Output: Expected result format
  • Agent: Which agent performs the task

๐Ÿ”ง Customization

Adding New Stocks

To analyze different stocks, modify the get_market_data() and get_analyst_insights() functions in src/servers/portfolio_server.py.

Changing Budget

Update the budget parameter in the GeneratePortfolio task or modify the default value in the MCP server.

Adding New Agents

  1. Define the agent in agents.yaml
  2. Add the agent method in crew.py
  3. Create corresponding tasks in tasks.yaml

๐Ÿงช Testing

Run tests using:

uv run test <iterations> <eval_llm>

๐Ÿ“ Dependencies

  • crewai[tools]: Multi-agent framework
  • mcp: Model Context Protocol for tool integration
  • pydantic: Data validation
  • fastmcp: Fast MCP server implementation

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

For issues and questions:

  1. Check the CrewAI documentation
  2. Review the configuration files
  3. Open an issue in the repository

๐Ÿ”ฎ Future Enhancements

  • Real-time market data integration
  • Risk assessment algorithms
  • Portfolio rebalancing recommendations
  • Historical performance tracking
  • User preference learning
  • Multi-asset class support (bonds, ETFs, etc.)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages