Introducing

Sentiment Analysis with Ticker News API Insights

Sep 6, 2024

In this tutorial, we explore the Ticker News API, enhanced through our internal research and the insights from our recently published paper on sentiment analysis using Large Language Models (LLMs). This API now captures structured data from unstructured financial news, enabling precise sentiment analysis tagging directly tied to specific tickers.

We'll demonstrate the practical application of these capabilities by examining sentiment trends for tickers such as

CRWD
(CrowdStrike) and
NVDA
(NVIDIA), showing you firsthand how the upgraded API functions as a sophisticated tool for market analysis.

Research Background

The research from Polygon.io introduces a groundbreaking approach using Large Language Models (LLMs) to extract structured data from unstructured financial news. By combining the generative capabilities of LLMs with advanced prompting techniques and a robust validation framework, the system can accurately identify relevant company tickers and perform sentiment analysis at the company level from raw news content.

  • Ticker Identification Accuracy: The new approach demonstrated a significant improvement in accurately identifying company tickers directly from news content. It achieved a 90% accuracy rate in capturing all tickers that matched those identified by publishers, and it identified additional relevant tickers in 22% of articles.
  • Granular Sentiment Analysis: The methodology is unique in providing granular, per-company sentiment analysis extracted from news articles. This allows for a more nuanced understanding of the impact of news on specific companies.
  • Real-time API Updates: The insights extracted are made available through a live API, which is updated in real-time with the latest news, enabling timely and relevant financial analysis.

The evaluation showed high effectiveness, with the new methodology surpassing traditional data providers in both coverage and relevance, providing a granular, real-time analysis via an accessible API.

Exploring the Ticker News API

The Ticker News API has long been a cornerstone for accessing financial news associated with specific tickers. However, we have now enhanced this API by integrating insights that provide structured data from this unstructured news content. This feature adds valuable layers of sentiment analysis tagging, ticker identification, and summarization directly into the news data, enriching the information available to investors and analysts.

Before you start, make sure to obtain an API key by signing up at Polygon.io. In the following example, you can retrieve news articles for a specific ticker using the Polygon.io Python client library:

from polygon import RESTClient

client = RESTClient()

# Fetch news articles for 'AAPL' with insights
news_articles = client.list_ticker_news(
	"AAPL", 
	params={"published_utc.gte": "2024-09-03"}, 
	order="desc", 
	limit=1000
	)

# Display the title and insights for each article
for article in news_articles:
    print(f"{article.title} [Insights: {article.insights}]")

The response from the Ticker News API now includes detailed

insights
object that offers a deeper understanding of the sentiment and context surrounding the news articles. Here's an example of a
TickerNews
object that showcases these enhancements:

Title: Apple, Nvidia Key Supplier TSMC Leads Taiwanese Chip Giants To Localize Neon Gas Production By 2025

Insights = [
    Insight(
        sentiment="positive",
        sentiment_reasoning="TSMC is leading the initiative to localize neon gas production, which is a significant step towards enhancing supply chain reliability for the Taiwanese semiconductor industry.",
        ticker="TSM",
    ),
    Insight(
        sentiment="positive",
        sentiment_reasoning="UMC is considering purchasing locally produced neon gas from Linde LienHwa, further supporting the initiative to localize neon gas production.",
        ticker="UMC",
    ),
    Insight(
        sentiment="positive",
        sentiment_reasoning="TSMC, a key supplier for Nvidia, is leading the effort to localize neon gas production, which will benefit Nvidia's supply chain.",
        ticker="NVDA",
    ),
    Insight(
        sentiment="positive",
        sentiment_reasoning="TSMC, a key supplier for Apple, is leading the effort to localize neon gas production, which will benefit Apple's supply chain.",
        ticker="AAPL",
    ),
]

This updated API functionality not only provides traditional news retrieval but now offers enriched data that can significantly enhance financial analysis and decision-making processes.

Visualizing Ticker News Insights

Now, let's dive into a hands-on example of actually using the Ticker News API. The script we'll explore is designed to systematically analyze market sentiments by focusing on specific tickers, such as

CRWD
(CrowdStrike) and
NVDA
(NVIDIA). Here’s a breakdown of the workflow:

The script begins by fetching news with insights for a specific ticker using the Polygon.io Python client, spanning a chosen date range. It then organizes this data using the

pandas
library to make it ready for analysis. Finally, it uses
matplotlib
to graphically display the sentiment trends over time, helping to visually identify how different news events affect stock behavior. This simple process allows for easy examination of market sentiments related to news articles.

from polygon import RESTClient
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

client = RESTClient()

# Set the date range
start_date = "2024-06-01"
end_date = "2024-09-04"

# Fetch news and extract sentiment for 'CRWD'
sentiment_count = []
for day in pd.date_range(start=start_date, end=end_date):
    daily_news = list(client.list_ticker_news("CRWD", published_utc=day.strftime("%Y-%m-%d"), limit=100))
    daily_sentiment = {
        'date': day.strftime("%Y-%m-%d"),
        'positive': 0,
        'negative': 0,
        'neutral': 0
    }
    for article in daily_news:
        if hasattr(article, 'insights') and article.insights:
            for insight in article.insights:
                if insight.sentiment == 'positive':
                    daily_sentiment['positive'] += 1
                elif insight.sentiment == 'negative':
                    daily_sentiment['negative'] += 1
                elif insight.sentiment == 'neutral':
                    daily_sentiment['neutral'] += 1
    sentiment_count.append(daily_sentiment)

# Convert to DataFramesentiment_count
df_sentiment = pd.DataFrame(sentiment_count)

# Convert 'date' column to datetime
df_sentiment['date'] = pd.to_datetime(df_sentiment['date'])

# Set the date as the index
df_sentiment.set_index('date', inplace=True)

# Plotting the data
plt.figure(figsize=(20, 10))
plt.plot(df_sentiment['positive'], label='Positive', color='green')
plt.plot(df_sentiment['negative'], label='Negative', color='red')
plt.plot(df_sentiment['neutral'], label='Neutral', color='grey', linestyle='--')
plt.title('Sentiment Over Time')
plt.xlabel('Date')
plt.ylabel('Count')
plt.legend()
plt.grid(True)

# Format the x-axis to display dates better
plt.gca().xaxis.set_major_locator(mdates.WeekdayLocator(interval=1))  # Adjust interval as needed
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
plt.gcf().autofmt_xdate()  # Rotation

# Saving the plot as an image file
plt.savefig('sentiment_over_time.png')
plt.show()

I've executed the script twice, selecting both

CRWD
(CrowdStrike) and
NVDA
(NVIDIA) as our focus tickers. The results showcased distinct sentiment trajectories for each company, reflecting the different news events they each experienced.

For CrowdStrike, the graph displays a significant spike in negative sentiment following the global outage caused by a software update. This visual highlights the immediate and substantial increase in negative press, reflecting the severity of the impact across multiple industries.

In contrast, the graph for NVIDIA illustrates a sustained increase in positive sentiment over an extended period, coinciding with the company's advancements in AI technology. This trend underscores the favorable media coverage that NVIDIA has received, bolstered by its pivotal role in driving AI innovations.

These visualizations underscore the distinct sentiment dynamics that can emerge from different industry events, providing a factual, data-driven basis for strategic decision-making in financial markets.

Next Steps

In this tutorial, we explored the enhanced Ticker News API, now with insights, that offers advanced sentiment tagging capabilities. We also explored how sentiment analysis works using the

CRWD
and
NVDA
tickers, illustrating the API's potential to reveal trends and impacts from news coverage.

Happy exploring!

From the blog

See what's happening at polygon.io

integration quantconnect Feature Image
featured

Integration: QuantConnect

We are excited to announce our integration with QuantConnect! This offering empowers users with state-of-the-art research, backtesting, parameter optimization, and live trading capabilities, all fueled by the robust market data APIs and WebSocket Streams of Polygon.io.