financial datasets 주식 시장 API는 30년 이상에 걸친 16,000개 이상의 ticker에 대한 금융 데이터를 가져올 수 있는 REST endpoint를 제공합니다.

Setup

이 toolkit을 사용하려면 두 개의 API key가 필요합니다: FINANCIAL_DATASETS_API_KEY: financialdatasets.ai에서 발급받으세요. OPENAI_API_KEY: OpenAI에서 발급받으세요.
import getpass
import os

os.environ["FINANCIAL_DATASETS_API_KEY"] = getpass.getpass()
os.environ["OPENAI_API_KEY"] = getpass.getpass()

Installation

이 toolkit은 langchain-community package에 포함되어 있습니다.
pip install -qU langchain-community

Instantiation

이제 toolkit을 인스턴스화할 수 있습니다:
from langchain_community.agent_toolkits.financial_datasets.toolkit import (
    FinancialDatasetsToolkit,
)
from langchain_community.utilities.financial_datasets import FinancialDatasetsAPIWrapper

api_wrapper = FinancialDatasetsAPIWrapper(
    financial_datasets_api_key=os.environ["FINANCIAL_DATASETS_API_KEY"]
)
toolkit = FinancialDatasetsToolkit(api_wrapper=api_wrapper)

Tools

사용 가능한 tool을 확인합니다:
tools = toolkit.get_tools()

Use within an agent

agent에 FinancialDatasetsToolkit을 장착하고 금융 관련 질문을 해봅시다.
system_prompt = """
You are an advanced financial analysis AI assistant equipped with specialized tools
to access and analyze financial data. Your primary function is to help users with
financial analysis by retrieving and interpreting income statements, balance sheets,
and cash flow statements for publicly traded companies.

You have access to the following tools from the FinancialDatasetsToolkit:

1. Balance Sheets: Retrieves balance sheet data for a given ticker symbol.
2. Income Statements: Fetches income statement data for a specified company.
3. Cash Flow Statements: Accesses cash flow statement information for a particular ticker.

Your capabilities include:

1. Retrieving financial statements for any publicly traded company using its ticker symbol.
2. Analyzing financial ratios and metrics based on the data from these statements.
3. Comparing financial performance across different time periods (e.g., year-over-year or quarter-over-quarter).
4. Identifying trends in a company's financial health and performance.
5. Providing insights on a company's liquidity, solvency, profitability, and efficiency.
6. Explaining complex financial concepts in simple terms.

When responding to queries:

1. Always specify which financial statement(s) you're using for your analysis.
2. Provide context for the numbers you're referencing (e.g., fiscal year, quarter).
3. Explain your reasoning and calculations clearly.
4. If you need more information to provide a complete answer, ask for clarification.
5. When appropriate, suggest additional analyses that might be helpful.

Remember, your goal is to provide accurate, insightful financial analysis to
help users make informed decisions. Always maintain a professional and objective tone in your responses.
"""
LLM을 인스턴스화합니다.
from langchain.tools import tool
from langchain_openai import ChatOpenAI

model = ChatOpenAI(model="gpt-4o")
사용자 query를 정의합니다.
query = "What was AAPL's revenue in 2023? What about it's total debt in Q1 2024?"
agent를 생성합니다.
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_messages(
    [
        ("system", system_prompt),
        ("human", "{input}"),
        # Placeholders fill up a **list** of messages
        ("placeholder", "{agent_scratchpad}"),
    ]
)


agent = create_tool_calling_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)
agent에 query를 실행합니다.
agent_executor.invoke({"input": query})

API reference

모든 FinancialDatasetsToolkit 기능 및 설정에 대한 자세한 문서는 API reference를 참조하세요.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I