Home

Awesome

Asset News Sentiment Analyzer

This application provides two sophisticated tools catering to sentiment analysis of financial assets and securities by using ChatGPT on Google search results and online news articles. You will just need an OpenAI API Key to get started and utilize the power of all the functionalities provided by this package, namely to fetch news articles, analyze their content, and produce insightful reports for investment and trading decisions.

A simple trading strategy involving daily sentiment analysis signals from this package may provide basic market traction of the target asset (We did a sample backtest on commodities over the past 100 market days):

<table> <tr> <td align="center"> <strong>Crude Oil 100 Days</strong><br> <img src="images/Crude Oil.jpg" alt="Crude Oil Sample" width="500" height="300"> </td> <td align="center"> <strong>Gold 100 Days</strong><br> <img src="images/Gold.jpg" alt="Gold Sample" width="500" height="300"> </td> </tr> </table>

Disclaimer: All investments and trading involve risk. This package is intended for research/academic purposes, and coding projects. It aids algorithmic/quantitative traders and researchers in their work. The reports and signals generated by this package does not constitute financial advice, and users should perform their own due diligence before making any trading decisions.

Contents

Two Main Classes

1. SentimentAnalyzer Tool

The SentimentAnalyzer class allows users to perform sentiment analysis on news articles related to a specific financial asset for any given date. It fetches news links, retrieves the content, and if desired, uses GPT models to generate reports and assess market sentiment.

Usage

from asset_sentiment_analyzer import SentimentAnalyzer

# Initialize the analyzer
analyzer = SentimentAnalyzer(asset='Crude Oil', openai_key='your-openai-key')

# Get sentiment analysis as string for today or any date in the past (returns "bullish", "bearish", or "neutral")
sentiment = analyzer.get_sentiment(date='06-02-2024')
print(f"The sentiment for the asset is: {sentiment}")

# Fetch news links for any date with news_date argument in MM-dd-YYYY format.
news_links = analyzer.fetch_news_links(news_date='06-02-2024')

# Display news content
for url in news_links:
    print(analyzer.show_news_content(url))

# Generate a report
report = analyzer.produce_daily_report(date='06-02-2024', max_words=300)
print(report)

API Reference

Available Methods:

Note: All dates must be in MM-dd-YYYY format or must be passed as a datetime.datetime object into the methods.

2. WebInteractor Tool

The WebInteractor class provides functionalities to interact with web content, perform Google searches, and retrieve content, which can then be fed into a GPT client for further interaction.

Usage

from asset_sentiment_analyzer import WebInteractor

# Initialize the WebInteractor
web_interactor = WebInteractor()

# Perform a Google search and retrieve result links as list
search_results = web_interactor.search_google(query="Apple Stocks", nlinks=5)
print(search_results)

# Fetch the main content of a webpage
content = web_interactor.get_webpage_main_content(url="https://example.com")
print(content)

# Interact with a GPT model
my_prompt = f"""
How will this affect the latest Apple earnings report:
{content}
"""
response = web_interactor.get_llm_response(prompt=my_prompt, openai_api_key="your_openai_api_key")
print(response)

API Reference

Available Methods:

Installation

Project has been published on pip

pip install asset-sentiment-analyzer

Contributing

If you would like to contribute to this project, please follow the guidelines below:

License

This project is pioneered by SkyBlue Capital (Singapore), and is licensed under the Apache-2.0 License. See the LICENSE file for details.

<img src="images/HBlack.png" alt="SBC Logo" width="190" height="55">