Multi-Agent AI Stock Analysis System (Open Source) – PrimoAgent

A free open-source multi-agent AI system for stock analysis. Get daily trading insights with technical indicators and news sentiment.

PrimoAgent is an open-source, multi-agent AI stock analysis system built on LangGraph, which orchestrates four specialized AI agents to provide daily trading insights and next-day price predictions.

It combines real-time market data collection, technical indicator analysis, financial news sentiment evaluation, and portfolio management recommendations into a single automated workflow.

PrimoAgent processes information through a sequential pipeline where each specialized agent builds upon the previous analysis to generate trading signals with confidence levels and position sizing recommendations.

Features

  • Portfolio Management Intelligence: Provides trading signals (BUY/SELL/HOLD) with confidence levels from 0.0 to 1.0, position sizing recommendations, and adaptive strategies based on historical decision context.
  • Four Specialized AI Agents: Data Collection Agent gathers real-time market data via yFinance and Finnhub APIs, Technical Analysis Agent calculates six key indicators (SMA, RSI, MACD, Bollinger Bands, ADX, CCI), News Intelligence Agent processes financial news through seven quantified NLP features, and Portfolio Manager Agent integrates all analysis into actionable trading signals.
  • Sequential Pipeline Architecture: Linear LangGraph workflow processes shared state through each agent, building comprehensive analysis from market data collection to final trading recommendations.
  • Advanced News Analysis: Seven quantified NLP features analyze financial news including news relevance, sentiment, price impact potential, trend direction, earnings impact, investor confidence, and risk profile changes (all scored on -2 to 2 scale).
  • Technical Indicator Integration: Calculates momentum and trend analysis using Simple Moving Average, Relative Strength Index, Moving Average Convergence Divergence, Bollinger Bands, Average Directional Index, and Commodity Channel Index.
  • Backtesting Engine: Complete backtesting system with performance metrics, volatility analysis, Sharpe ratio calculations, maximum drawdown tracking, and comparative analysis against buy-and-hold strategies.
Performance Comparison Charts
Performance Comparison Charts

Use Cases

  • Individual Retail Traders: Automate daily stock analysis and receive next-day price predictions with confidence levels to support trading decisions across multiple stocks simultaneously.
  • Portfolio Managers: Leverage multi-agent analysis to evaluate technical indicators, news sentiment, and market data for portfolio optimization and risk management across diverse holdings.
  • Financial Research Teams: Use comprehensive backtesting capabilities to validate trading strategies, compare performance against benchmark approaches, and analyze volatility patterns across different market conditions.
  • Algorithm Development: Build upon the open-source LangGraph architecture to create custom trading algorithms or extend the existing agent framework with additional analytical capabilities.
  • Educational Applications: Study multi-agent AI systems in financial markets, understand the integration of technical analysis with natural language processing, and explore automated trading system development.

Case Studies

Recent multi-stock backtest results demonstrate PrimoAgent’s effectiveness across diverse market conditions and stock types.

The system was tested against major technology and growth stocks over extended periods, comparing PrimoAgent strategies against traditional buy-and-hold approaches.

PrimoAgent Table

META Performance Analysis

PrimoAgent achieved a 31.97% return with $131,967 final value compared to buy-and-hold’s 22.16% return at $122,165. The system maintained lower volatility at 19.75% versus 34.04% for buy-and-hold, while achieving a superior Sharpe ratio of 2.899 compared to 1.124. Maximum drawdown was significantly reduced to 8.99% versus 34.04%, demonstrating effective risk management through 26 strategic trades.

NFLX Trading Results

The system generated 28.61% returns ($128,606 final value) with 20.25% volatility through 20 trades. While buy-and-hold achieved higher raw returns at 49.51%, PrimoAgent maintained substantially lower risk exposure with maximum drawdown of 12.13% compared to 19.01%. The Sharpe ratio of 2.570 exceeded buy-and-hold’s 2.399, indicating superior risk-adjusted performance.

Risk Management Effectiveness

Across AAPL and TSLA positions, PrimoAgent consistently reduced maximum drawdown compared to buy-and-hold strategies. For TSLA, the system limited losses to -3.35% versus -16.59% for passive strategies, with dramatically lower volatility at 6.52% compared to 75.75%. This demonstrates the system’s ability to navigate highly volatile markets through active position management.

How To Use It

1. Create a virtual environment for Python to keep the dependencies organized.

python3 -m venv venv
source venv/bin/activate

2. Install all the necessary libraries.

pip install -r requirements.txt

3. Get the needed API keys from OpenAI, Finnhub, Firecrawl, and Perplexity.

4. Copy the example .env.example file to .env and add your keys there.

OPENAI_API_KEY=
ANTHROPIC_API_KEY=
FINNHUB_API_KEY=
FIRECRAWL_API_KEY=
PERPLEXITY_API_KEY=

5. Start a new analysis by executing python main.py. The system will then ask you for the stock symbol (like ‘AAPL’), a start date, and an end date for the analysis.

6. After the analysis is complete, you can run python backtest.py to see the performance results for the selected period.

Pros

  • Advanced Analysis: It combines technical, fundamental, and news sentiment analysis for a well-rounded view.
  • Open-Source and Free: You have full access to the code and don’t have to pay for a subscription.
  • Customizable: You can extend the system by adding new agents or modifying existing ones to fit your own trading philosophy.
  • Risk Management Focus: The backtest results often show lower volatility and drawdowns compared to just buying and holding.

Cons

  • Requires Technical Skill: You need to be comfortable with Python and using the command line to set it up and run it.
  • API Keys Required: You need to sign up for and manage several API keys, some of which may have costs associated with them depending on your usage.
  • Not a “Fire and Forget” Solution: This is a tool for analysis, not an automated trading bot. You still need to interpret the results and make your own decisions.
  • Performance Varies: As seen in the backtests, the tool’s effectiveness can differ significantly between stocks.

Related Resources

  • LangGraph Documentation: Official documentation for the graph-based agent framework underlying PrimoAgent’s architecture.
  • yFinance Library Guide: Python library documentation for accessing Yahoo Finance market data used in the Data Collection Agent.
  • Finnhub API Reference: API documentation for financial market data integration and news analysis capabilities.
  • Technical Analysis with Python: Library documentation for implementing technical indicators like RSI, MACD, and Bollinger Bands.
  • Multi-Agent Systems in Finance: Academic research paper exploring multi-agent approaches to financial market analysis and automated trading systems.

FAQs

Q: Can I use PrimoAgent for real-time trading?
A: While it collects recent data, it’s designed for daily analysis and backtesting, not high-frequency or real-time automated trading. The developers explicitly state it’s for educational and research purposes.

Q: How accurate are the next-day price predictions?
A: The system provides trading signals with confidence levels rather than specific price predictions. Backtesting results show improved risk-adjusted performance compared to buy-and-hold strategies, but past performance doesn’t guarantee future results. The accuracy depends on market conditions, chosen language models, and configuration parameters.

Q: What happens if one of the required APIs goes down?
A: PrimoAgent depends on four external APIs (OpenAI, Finnhub, Firecrawl, Perplexity) and will fail if any become unavailable. The system doesn’t include fallback mechanisms for API failures. You should monitor API status and potentially implement backup data sources for production use.

Q: Are there any ongoing costs to run PrimoAgent?
A: Yes, the system requires API access to OpenAI (language model processing), Finnhub (market data), Firecrawl (web scraping), and Perplexity (search functionality). Costs depend on usage volume and API pricing structures.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest & top AI tools sent directly to your email.

Subscribe now to explore the latest & top AI tools and resources, all in one convenient newsletter. No spam, we promise!