- AI for Fun & Profit
- Posts
- Building Your Personalized Stock Market Research Team
Building Your Personalized Stock Market Research Team
Collaborative AI Agents #ftw
The allure of the stock market is undeniable, but the sheer volume of data and complex analysis can be a daunting barrier to entry. Imagine having a team of tireless researchers working for you, sifting through news, crunching numbers, and unearthing valuable insights.
We will be using CrewAI, a powerful framework that allows you to build your squad of AI helpers specifically designed to analyze the world of stock market research. This newsletter dives deep into the CrewAI framework and equips you with the knowledge to construct your personalized research team.
Note:
If you are not interested in the technical details of how the AI Agents work and just want to use the tool you can access the tool here :
Building Blocks of Collaborative AI
CrewAI offers a comprehensive framework for crafting intelligent, collaborative AI solutions. Let's explore the core concepts that underpin this platform:
1. Agents: The Powerhouse of Your Research Team
Think of agents as the intelligent software programs at the heart of your CrewAI team. These customizable entities possess the ability to:
Perceive Their Surroundings: Agents can gather information from various sources, such as financial websites, news platforms, and social media.
Make Informed Decisions: Based on the gathered data and pre-defined rules, agents can make decisions that contribute to completing the assigned task.
Take Action: Agents can execute actions based on their decisions, such as scraping data from websites or compiling research reports.
CrewAI empowers you to:
Craft Custom Agents: Tailor agents to your specific needs. Need an agent to crawl through financial news websites for earnings reports? Or one to analyze historical stock price data? CrewAI allows you to define their functionalities from the ground up.
Leverage Pre-Built Agents: Don't reinvent the wheel! CrewAI offers a library of pre-built agents equipped with common functionalities. Need an agent for web scraping or natural language processing of financial news? CrewAI might already have you covered.
2. Tasks: Defining the Objectives for Your AI Researchers
Tasks represent the specific goals you assign to your AI agents. These can range from simple data collection to intricate multi-step processes:
Clear Task Definition: The clearer you define the steps involved in a task, the more efficient and accurate the execution by your AI agents will be.
Breaking Down Complexity: Complex tasks, such as analyzing a company's financial health, can be broken down into smaller, more manageable subtasks. This enhances clarity, and efficiency, and avoids overwhelming your agents.
3. Tools: Equipping Your AI Team for Success
CrewAI furnishes your agents with a diverse toolkit to tackle their designated tasks:
Web Scraping Tools: These tools empower agents to extract valuable data from financial websites, such as stock prices, earnings reports, and analyst ratings. This data forms the foundation for further analysis.
Natural Language Processing (NLP) Tools: These tools enable agents to understand and process financial news articles and social media discussions. This allows them to analyze sentiment surrounding a particular stock, identify potential risks or opportunities, and gauge investor confidence.
Financial Data Analysis Tools: Equip your agents with tools to analyze financial data like price-to-earnings ratios, debt-to-equity ratios, and historical price trends. This enables them to identify patterns and assess a company's financial health.
By providing the right tools, you ensure your agents have the capabilities to excel within your CrewAI stock market research project.
4. Processes: Orchestrating the Research Workflow
Processes in CrewAI define the sequence of steps and interactions between agents that lead to a comprehensive research report:
Structured Approach: Processes establish a structured approach, preventing conflicts between agents and ensuring they work seamlessly together.
Conductor of the AI Orchestra: CrewAI acts as the conductor, ensuring agents follow the defined process and collaborate effectively to complete the research task.
5. Crews: Building a Cohesive Research Team
Crews in CrewAI are a powerful way to organize your AI stock market research project:
Cohesive Units: A crew groups agents, tasks, tools, and processes relevant to a specific research topic, such as analyzing a particular stock or sector. This fosters a modular and well-structured development paradigm.
Modularizing Complexity: Complex research projects can be efficiently broken down into smaller, more manageable crew units. This promotes code reusability, simplifies maintenance, and facilitates collaboration if you're working with a team.
Reusability: Well-defined crews designed for specific research tasks can be incorporated into future projects, saving you time and effort.
Let’s take a look at a simpler version of the AI Research tool here.
The first role is a simple research agent which gathers information from the web, sec site, or api’s like Yahoo Finance to pull necessary information
researcher = Agent(
role="Senior Financial Analyst / Researcher",
goal=f"""Your goal is to research about company with ticker {ticker} financials like income statements, balance sheets and cash flow. Identify trends about core metrics like total revenue, net income, gross profit, free cash flow, net change in cash
EPS, EPS growth, PE ratio, PEG ratio and provide summary information along with all the necessary numbers. Make sure to include the overall financial and the trend of the above metrics across the last 5 quarters.
Important Investment guidelines: Include numbers that will be helpful for investment guidelines
1) Follow general guidance of value investing.
2) For growth stocks ensure that the growth is profitable or has path to profitability. If the debt is high provide possible reason as to why it could be high by looking at the numbers.""",
verbose=True,
memory=True,
backstory="""Known as the BEST research analyst, you\'re
skilled in sifting through news, company announcements, and market sentiments. Now you\'re working on a super
important customer. """,
tools=[yfinance_tool],
allow_delegation=True,
llm=anthropic_model,
)
Next, we have another agent whose role is financial advisor and stock recommendation.
financial_advisor = Agent(
role="Financial Advisor",
goal=f"""Provide guidance to the customer on whether they should buy the {ticker} or no. Make sure you provide a detailed report including tl;dr, summary, pros, cons, recommendation on buy/don't buy.
Important Investment guidelines: Include numbers that will be helpful for investment guidelines
1) While looking at the metrics make sure you follow value investing.
2) For growth stocks ensure that the growth is profitable or has path to profitability. If the debt is high provide possible reason as to why it could be high by looking at the numbers.
""",
verbose=True,
memory=True,
backstory="""The most seasoned financial advisor with lots of expertise in stock market analysis and investment
strategies that is working for a super important customer. You provide the final guidance to the customer on buying
or not buying the asset by looking at the Financials and company health. Provide trends in the quarterly results
to help user with information needed.""",
tools=[yfinance_tool],
allow_delegation=True,
)
Now that we have the Agents we will also describe how to write the tasks to achieve our final objective
research_task = Task(
description=f"""Gather financial information regarding the company with ticker: {ticker}.
Focus on extracting the correct data and providing key data points about the company that can be used
to make decision on whether to buy the asset or no. Include numbers from
quarterly reports to provide latest information.
Your final report should clearly articulate the key points, its market opportunities, and potential risks.""",
expected_output=f"""A Comprehensive report about the financial health of the company :{ticker} and all the key points about the trends
of the key metrics using the latest 5 quarterly statements""",
max_inter=1,
agent=researcher,
)
# Writing task with language model configuration
analysis_task = Task(
description=dedent(
f"""
Your goal is to recommend to the user if they should invest in the {ticker} or no.
This includes examining key financial metrics such as total revenue, net income, gross profit,
free cash flow, net change in cash, EPS, EPS growth, PE ratio, PEG ratio , Research And Development expenses and provide summary
information along with all the necessary numbers in human readable format. Also make sure you provide numbers and
narrative around based on how the stock is doing using the last 5 quarterly reports provided. Include numbers from
quarterly reports to provide latest information.
Include tl;dr, summary, pros/cons, along with the recommendation on whether to (buy,hold or don't invest).
Include key numbers in human readable format as necessary to support your recommendation and make it as comprehensive as possible.
Provide narrative around the short term and long term view.
"""
),
max_inter=1,
agent=financial_advisor,
expected_output=f"""A Comprehensive and a detailed report in markdown format for :{ticker}.
""",
)
Next when we have the agents and task assembled we kick off the crew to do the task intended.
crew = Crew(
agents=[researcher, financial_advisor],
tasks=[research_task, analysis_task],
process=Process.sequential,
)
result = crew.kickoff()
That’s it for today. I hope you find this information useful. If you would like to talk more about building custom AI Agents, get in touch with me.
Here is the tool