Skip to content

Predict positive or negative sentiment from financial news headlines.

License

Notifications You must be signed in to change notification settings

MatthewW05/FinanceSentimentAnalyzer

Repository files navigation

Finance Sentiment Analyzer

This project aims to predict the sentiment (positive or negative) from financial news headlines using machine learning techniques.

Installation

Install FinanceSentimentAnalyzer using pip:

pip install git+https://github.com/MatthewW05/FinanceSentimentAnalyzer.git

Required dependencies , All dependencies.

Usage

Predicting a headline's sentiment using the pre-trained model

from FinanceSentimentAnalyzer import predict_headline_sentiment

headline = "Nvidia Stock Rises. How Earnings From Microsoft and Apple Could Drive It Higher."

# by default a pre-trained model is pre-loaded when imported
# the function will return float between 0 and 1
prediction = predict_headline_sentiment(headline)
prediction = "Positive" if round(prediction) == 1 else "Negative"
   
print(f"Prediction for \'{headline}\': {prediction}")

Loading your own model

When loading your own model, you must include both the model and and the used vocabulary

from FinanceSentimentAnalyzer import load_model_and_vocab, predict_headline_sentiment

headline = "Nvidia Stock Rises. How Earnings From Microsoft and Apple Could Drive It Higher."
model, vocab = load_model_and_vocab('path/to/your/model', 'path/to/your/vocab')
prediction = predict_headline_sentiment(headline, model, vocab)
prediction = "Positive" if round(prediction) == 1 else "Negative"

print(f"Prediction for \'{headline}\': {prediction}")

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Data Sources

This project uses data from several third-party sources. We acknowledge and thank the creators of these datasets:

License

This project is licensed under the MIT License. See the LICENSE file for details.


Matthew Wong

About

Predict positive or negative sentiment from financial news headlines.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages