Back to Llama Index

Yahoo Finance

llama-index-integrations/tools/llama-index-tools-yahoo-finance/examples/yahoo_finance.ipynb

0.14.21991 B
Original Source

Building a Yahoo Finance Agent

This tutorial walks you through the process of building a Yahoo Finance Agent using the yahoo_finance tool. The agent will be able to retrieve stock data, financial statements, and other financial information from Yahoo Finance.

python
!pip install llama-index llama-index-tools-yahoo-finance
python
import os

os.environ["OPENAI_API_KEY"] = "sk-your-key"
python
from llama_index.tools.yahoo_finance.base import YahooFinanceToolSpec

finance_tool = YahooFinanceToolSpec()

finance_tool_list = finance_tool.to_tool_list()
for tool in finance_tool_list:
    print(tool.metadata.name)
python
print(finance_tool.balance_sheet("AAPL"))
python
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI

agent = FunctionAgent(
    tools=finance_tool_list,
    llm=OpenAI(model="gpt-4.1"),
)
python
print(await agent.run("What are the analyst recommendations for AAPL?"))