Tool

Access Financial Data and News

Gather stock news, earnings, and fundamental analysis from four finance APIs in one tool.

Works with polygonfinnhubalphavantagenewsapiopenai

76
Spark score
out of 100
Updated 2 days ago
Version 0.14.23
Models

Add to Favorites

Why it matters

Integrate with leading financial APIs to gather real-time news, earnings data, and perform fundamental analysis on stocks.

Outcomes

What it gets done

01

Connect to Polygon.io, Finnhub, Alpha Vantage, and NewsAPI.

02

Retrieve stock news and earnings information.

03

Perform fundamental analysis on financial data.

04

Query historical stock performance.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/li-tool-tools-finance | bash

Overview

Finance Agent Tool

A LlamaIndex tool that combines Polygon.io, Finnhub, Alpha Vantage, and NewsAPI to answer stock news, earnings, and fundamental-analysis questions. Use when an agent needs stock-specific answers drawing on multiple finance data providers, given all four required API keys.

What it does

The Finance Agent Tool connects a LlamaIndex agent to several open finance APIs and libraries to gather news, earnings information, and perform fundamental analysis. FinanceAgentToolSpec is initialized with four separate API keys, each backing a different data source: a Polygon.io key, a Finnhub key, an Alpha Vantage key, and a NewsAPI key - so the tool draws on multiple providers rather than a single data feed.

The source's own worked example wraps this initialization in a create_agent helper that takes all four API keys plus an OpenAI key, builds the FinanceAgentToolSpec, and attaches it to a FunctionAgent. The example query - "What happened to AAPL stock on February 19th, 2024?" - shows the tool answering a specific, dated question about a named stock, which requires pulling together news and market data around that particular date rather than just a current snapshot.

When to use - and when NOT to

Use it when a LlamaIndex agent needs to answer questions about specific stocks - news, earnings, or fundamentals - potentially for a specific past date, and you're able to obtain API keys from all four required providers (Polygon, Finnhub, Alpha Vantage, NewsAPI). Do not use it if you can only obtain a subset of those keys; the tool spec as documented is initialized with all four together.

Capabilities

Gathers stock-related news, earnings information, and fundamental analysis data by combining Polygon.io, Finnhub, Alpha Vantage, and NewsAPI into one tool spec for a LlamaIndex agent to query.

How to install

pip install llama-index-tools-finance

Requires four API keys: POLYGON_API_KEY, FINNHUB_API_KEY, ALPHA_VANTAGE_API_KEY, and NEWSAPI_API_KEY, obtained from Polygon.io, Finnhub, Alpha Vantage, and NewsAPI respectively.

Who it's for

Developers building LlamaIndex agents that need to answer questions about specific stocks - news, earnings, or historical events - by combining several finance data providers into one tool.

Source README

Finance Agent Tool

This tool connects to various open finance apis and libraries to gather news, earnings information and doing fundamental analysis.

To use this tool, you'll need a few API keys:

Installation

pip install llama-index-tools-finance

Usage

from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
from llama_index.tools.finance import FinanceAgentToolSpec

POLYGON_API_KEY = ""
FINNHUB_API_KEY = ""
ALPHA_VANTAGE_API_KEY = ""
NEWSAPI_API_KEY = ""
OPENAI_API_KEY = ""

GPT_MODEL_NAME = "gpt-4-0613"


def create_agent(
    polygon_api_key: str,
    finnhub_api_key: str,
    alpha_vantage_api_key: str,
    newsapi_api_key: str,
    openai_api_key: str,
) -> FunctionAgent:
    tool_spec = FinanceAgentToolSpec(
        polygon_api_key,
        finnhub_api_key,
        alpha_vantage_api_key,
        newsapi_api_key,
    )
    llm = OpenAI(temperature=0, model=GPT_MODEL_NAME, api_key=openai_api_key)
    return FunctionAgent(
        tools=tool_spec.to_tool_list(),
        llm=llm,
    )


agent = create_agent(
    POLYGON_API_KEY,
    FINNHUB_API_KEY,
    ALPHA_VANTAGE_API_KEY,
    NEWSAPI_API_KEY,
    OPENAI_API_KEY,
)

response = await agent.run(
    "What happened to AAPL stock on February 19th, 2024?"
)

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.