AI Personal Learning
and practical guidance
豆包Marscode1

Rapidly Build Stock Analysis Intelligence Body Intelligence with Phidata AI

使用 Phidata AI 快速构建股票分析智能体智能体-1

 

Information overload in equity research is real

A common challenge when evaluating the value of a stock is that of dealing with a large amount of information from multiple sources in order to make an informed investment decision.

Traditional methods include:

  • Collect financial data from various platforms.
  • Read multiple reports, news and other articles.
  • Build and maintain complex spreadsheet models.
  • Synthesize this information into actionable content.

Holding and managing all these inputs at once usually looks like this:


使用 Phidata AI 快速构建股票分析智能体智能体-1

AI is known to be the most viable solution to handle large data sets easily and efficiently.

However, most of the publicly available Large Language Models (LLMs) are still unable to perform detailed in-depth analysis of real-time stock data with great accuracy.

  • ChatGPT cap (a poem) Claude There is a contextual date cutoff.
  • Perplexity Great for real-time information, but limited in analyzing tasks.
  • ChatGPT searches are still unsatisfactory.

For detailed research and stock analysis, we need something that is more precise and works well with structured datasets.

In fact, what if we could combine everything? What if we could utilize AI intelligences to navigate news, Google searches, financial datasets, and coding tasks all in one system?

A superb, always-on stock analyst.

 

Go to AI Intelligent Body Solutions

To solve this problem, I developed a system that coordinates multiple specialized AI intelligences, each dealing with specific aspects of stock analysis.

使用 Phidata AI 快速构建股票分析智能体智能体-1

Intelligent Body Team

  1. Sentiment Analysis Intelligence (GPT-4o)
    • Handling news and market sentiment
    • Use Google search to gather recent developments
    • Provides sentiment scores and trend analysis
  2. Financial Analysis Intelligence (Claude 3.5)
    • Different intelligences for basic stock data and historical data
    • Analyzing company finances and indicators
    • Perform valuation calculations (DCF, publicly comparable companies, fundamental analysis)
    • Assessment of key performance indicators
  3. Quantitative Analytical Intelligence (Claude 3.5 Sonnet or Haiku)
    • Execute Python code for technical analysis
    • Processing large datasets and output from other intelligences
    • Generate visualizations and statistical insights
  4. Executive/Portfolio Manager Intelligence (Claude 3.5 Sonnet or Haiku)
    • Acts as a portfolio manager designed to synthesize data with optional routing.
    • Aggregate all information gathered by other instrumental intelligences and provide buy, sell or hold recommendations

Phidata: The Intelligent Body Builder

使用 Phidata AI 快速构建股票分析智能体智能体-1

Phidata is a framework for AI intelligences that enables developers to:

  • Building Intelligence with Memory, Knowledge and External Connections
  • Building teams of intelligences that can work together
  • Monitor, evaluate and optimize intelligences

They also provide an intuitive and user-friendly user interface for intelligences, and users can test intelligences in a sandbox environment.

Phidata allows us to integrate several powerful tools right out of the box:

  • Yahoo Finance API for real-time price data and historical financial data
  • Google Search for News and Sentiment Analysis
  • Python tools for AI-guided code execution and quantitative analysis (use with caution)
  • Custom quantitative functions for data processing and visualization (optional)
    • Note: Code execution intelligences require tight control and strict hint engineering
    • Code intelligences may encounter multiple errors, such as recursive functions or saving and reading files

introduction (a subject)

Want to try it yourself? The full code is available at Google Colab NotebookFound in.

You will need:

  • OpenAI and Anthropic API key (we use different models for different intelligences, but you can opt for a more unified workflow)
  • Phidata framework installed
  • Some basic Python knowledge for further study

Required Packages

!pip install phidata openai anthropic yfinance googlesearch-python pycountry -q

Instantiating Libraries and API Keys

## Libraries

from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.model.anthropic import Claude
from phi.tools.yfinance import YFinanceTools
from phi.tools.googlesearch import GoogleSearch

## API Keys

import requests

from google.colab import userdata
OPENAI_API_KEY = userdata.get('OPENAI_API_KEY')
ANTHROPIC_API_KEY = userdata.get('ANTHROPIC_API_KEY')

import os
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
os.environ["ANTHROPIC_API_KEY"] = ANTHROPIC_API_KEY

 

Defining an Intelligence - Sentiment Analysis Example

# Sentiment Analysis Agent

sentiment_agent = Agent(
name="Sentiment Analysis Agent",
role="Search and interpret news articles",
model=OpenAIChat(id="gpt-4o"),
## define the tools for the Agent's use
tools=[GoogleSearch(), YFinanceTools(company_news=True)],
instructions=[
"Find relevant news articles for each company and critically analyze the news sentiment.",
"Provide sentiment scores from 1 (negative) to 10 (positive) with reasoning and sources."
"Cite your sources. Be specific, crtical and provide relevant links."
],
show_tool_calls=True,
markdown=True,
)

 

Defining an Intelligence - Basic Stock Information Example

# Financial Analyst Agent

basic_stock_agent = Agent(
name="Basic Financial Data Agent",
role="Retrieve basic company financial data and expertly interpret trends and data using a rigourously analytical approach",
model=Claude(id="claude-3-5-sonnet-latest"), ## swapped claude for gpt-4o
## define the tools for the Agent's use
tools=[YFinanceTools(stock_price=True, company_info=True, stock_fundamentals=True, analyst_recommendations=True)],
instructions=[
"Retrieve stock prices, analyst recommendations, and key summary financial data.",
"Focus on company funamentals and trends, presenting the data in tables with key insights."
],
show_tool_calls=True,
markdown=True,
)

Users have the option to add more intelligences based on their unique needs, including visual intelligences and other formats

Building Your Intelligent Body Team

With just a few lines of code, we can build a powerful multi-intelligence system with specific roles that can collaboratively analyze stocks.

agent_team Acting as a conductor, selecting the right workflow of intelligences and ensuring that each intelligence contributes its insights and that the final output is well-structured, data-driven and easy to understand

agent_team = Agent(
model=Claude(id="claude-3-5-sonnet-latest"),
team=[sentiment_agent, basic_stock_agent], ## Add more Agents here if desired.
instructions=[
"Combine the expertise of all the agents part of your team to provide a cohesive, highly analytical and well-supported response",
"Always include references and dates for all data points and sources. Your context is current as of [insert date here]"
"Present data in structured tables for clarity, ensuring all conclusions are data-driven."
"Explain the methodlogy and always determine a BUY, SELL, or HOLD recommendation."
],
show_tool_calls=True,
markdown=True,
)

 

Start chatting with your team of intelligences 🤖

You are now ready to start querying your Smartbody team! Here's what the sample prompts and output look like:

Example Tip:

agent_team.print_response(
"Perform a public comparable companies analysis for CALM Cal Maine Foods. Identify it's main competitors and market positioning. Assess each comp in a structrued table format",
stream=True
)

 

Sample Output:

(formatted data)

### 公共可比公司分析:Cal-Maine Foods (CALM)

#### **公司概览**

| 公司名称 | 股票代码 | 市值 (美元) | 主要业务方向 | 鸡蛋生产重点 |
| ---------------------- | ---------- | ------------- | ---------------- | -------------- |
| Cal-Maine Foods | CALM | $4.96B | 专注于鸡蛋生产 | 核心业务 |
| Post Holdings | POST | $6.66B | 包装食品 | 次要业务 |
| Tyson Foods | TSN | $20.65B | 肉类和食品产品 | 边缘业务线 |
| Vital Farms | VITL | $1.64B | 放养鸡蛋 | 专注细分市场 |
| Seaboard Corporation | SEB | $2.34B | 多元化企业集团 | 边缘业务线 |

#### **财务指标对比**

| 指标 | CALM | POST | TSN | VITL | SEB |
| ----------------------- | -------- | -------- | -------- | -------- | -------- |
| 市盈率 (P/E Ratio) | 11.59 | 16.11 | 13.80 | 31.31 | N/A |
| 每股收益 (EPS) | $8.73 | $5.64 | $2.25 | $1.12 | -$5.30 |
| 收入增长率 (同比) | 71.1% | 波动 | 中等 | 高 | 波动 |
| 毛利率 (Gross Margin) | 28.02% | 15-20% | 12-15% | 25-30% | 波动 |

---

### **Cal-Maine Foods 的竞争地位**

#### **独特优势**

1. 鸡蛋生产市场的领导地位
2. 多元化的产品组合
3. 强大的区域分销网络
4. 专注于特色鸡蛋细分市场
5. 稳健的财务表现

#### **关键差异化特点**

* **品牌** :Egg-Land's Best, Land O' Lakes, Farmhouse Eggs
* **产品范围** :传统、有机、散养、放牧鸡蛋
* **地理覆盖** :西南、东南、中西部、东北和中大西洋地区

---

### **市场建议**

#### **综合评估**

* **Cal-Maine Foods** 是最专注于鸡蛋生产的公司
* 与多元化竞争对手相比,财务指标表现强劲
* 在特色鸡蛋市场细分中有持续增长的潜力

#### **投资建议:** **强烈买入**

* 稳健的基本面
* 市场领导地位
* 适应消费者趋势的能力
* 相较于同业估值具有吸引力

---

**注意** :以上分析基于当前市场数据,可能会随市场变化而调整。在做出投资决策之前,请始终进行个人尽职调查。

That's it. You are building your personal stock analyst to help you enhance your investment process.

Real-world results

Testing the system on various stocks has shown promising results:

  • Cost reduction: The need for multiple financial database subscriptions can be eliminated by automatically aggregating data
  • Research efficiency: Reduces stock research time and can handle multiple companies at once, thus expanding coverage without adding staff
  • competitive analysis: Quickly generate peer comparisons and industry positioning
  • financial analysis: Reduces reliance on junior analysts for data collection, allowing them to focus on higher-value analysis
  • Multi-model support: Plug in Claude, GPT, Groq, HF models, or whatever LLM provider best suits your needs!

⚠️ Limitations

Although powerful, the system still has some limitations:

  • Limited ability to analyze data beyond LLM training deadlines
  • Reliance on external APIs for data quality and availability
  • Higher computational costs when using other tools and intelligences
  • Need precise tips on engineering
  • Complex decisions still require human oversight

🛠️ Potential Enhancements

Future enhancements may include:

  • Other Data Sources and APIs
  • More complex inter-intelligence communication
  • Enhanced visualization and code execution capabilities
  • Machine Learning Models for Pattern Recognition

reach a verdict

This multi-intelligence system is an important step forward in automating financial analysis and is free for everyone to use. By combining the strengths of different AI models and tools, we can create more powerful and comprehensive analytical workflows.

Remember: while AI can greatly enhance our analytical capabilities, it should be used as a complement to, not a substitute for, human judgment in investment decisions.

Disclaimer: This post is for educational purposes only and should not be considered financial advice. Always do your own research before making investment decisions.

May not be reproduced without permission:Chief AI Sharing Circle " Rapidly Build Stock Analysis Intelligence Body Intelligence with Phidata AI
en_USEnglish