Yahoo Finance News
This notebook goes over how to use the yahoo_finance_news
tool with an
agent.
Setting up
First, you need to install yfinance
python package.
%pip install --upgrade --quiet yfinance
Example with Chain
import os
os.environ["OPENAI_API_KEY"] = "..."
from langchain.agents import AgentType, initialize_agent
from langchain_community.tools.yahoo_finance_news import YahooFinanceNewsTool
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(temperature=0.0)
tools = [YahooFinanceNewsTool()]
agent_chain = initialize_agent(
tools,
llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
)
API Reference:
agent_chain.run(
"What happens today with Microsoft stocks?",
)
> Entering new AgentExecutor chain...
I should check the latest financial news about Microsoft stocks.
Action: yahoo_finance_news
Action Input: MSFT
Observation: Microsoft (MSFT) Gains But Lags Market: What You Should Know
In the latest trading session, Microsoft (MSFT) closed at $328.79, marking a +0.12% move from the previous day.
Thought:I have the latest information on Microsoft stocks.
Final Answer: Microsoft (MSFT) closed at $328.79, with a +0.12% move from the previous day.
> Finished chain.
'Microsoft (MSFT) closed at $328.79, with a +0.12% move from the previous day.'
agent_chain.run(
"How does Microsoft feels today comparing with Nvidia?",
)
> Entering new AgentExecutor chain...
I should compare the current sentiment of Microsoft and Nvidia.
Action: yahoo_finance_news
Action Input: MSFT
Observation: Microsoft (MSFT) Gains But Lags Market: What You Should Know
In the latest trading session, Microsoft (MSFT) closed at $328.79, marking a +0.12% move from the previous day.
Thought:I need to find the current sentiment of Nvidia as well.
Action: yahoo_finance_news
Action Input: NVDA
Observation:
Thought:I now know the current sentiment of both Microsoft and Nvidia.
Final Answer: I cannot compare the sentiment of Microsoft and Nvidia as I only have information about Microsoft.
> Finished chain.
'I cannot compare the sentiment of Microsoft and Nvidia as I only have information about Microsoft.'
How YahooFinanceNewsTool works?
tool = YahooFinanceNewsTool()
tool.run("NVDA")
'No news found for company that searched with NVDA ticker.'
res = tool.run("AAPL")
print(res)
Top Research Reports for Apple, Broadcom & Caterpillar
Today's Research Daily features new research reports on 16 major stocks, including Apple Inc. (AAPL), Broadcom Inc. (AVGO) and Caterpillar Inc. (CAT).
Apple Stock on Pace for Worst Month of the Year
Apple (AAPL) shares are on pace for their worst month of the year, according to Dow Jones Market Data. The stock is down 4.8% so far in August, putting it on pace for its worst month since December 2022, when it fell 12%.