Skip to content

About

Financial sentiment analysis and stock forecasting framework using LSTM neural networks. Processes market news, investor commentary, and earnings transcripts to generate sentiment signals for directional equity prediction, achieving 70% out-of-sample accuracy on 50K+ records.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

NLP Finance

Trains an LSTM neural network to classify the sentiment of financial sentences as negative, neutral, or positive. Everything lives in NLP_finance.py.

What it does

  • Loads finance_train.csv and finance_test.csv, each a set of financial sentences with a sentiment label.
  • Cleans the text: lowercases it, strips punctuation and symbols, and removes English stopwords using NLTK.
  • Tokenizes and pads the sentences with Keras utilities so they can feed into a neural network.
  • Builds an Embedding plus LSTM model in Keras, trains it with early stopping, and evaluates accuracy and loss on a held out test set.
  • Plots training versus validation loss and accuracy over epochs, and a confusion matrix for the final model's predictions.

Requirements

  • Python 3.9+
  • numpy
  • pandas
  • seaborn
  • matplotlib
  • nltk
  • beautifulsoup4
  • scikit-learn
  • gdown
  • tensorflow (includes keras)

Install with:

pip install numpy pandas seaborn matplotlib nltk beautifulsoup4 scikit-learn gdown tensorflow

The script also calls nltk.download() for punkt, stopwords, and wordnet on first run, so an internet connection is needed the first time.

Data

finance_train.csv and finance_test.csv are not included in this repo. The comments at the top of the script point to where they were originally pulled from (an Inspirit AI project data bucket); grab them from there, or use your own train and test CSVs with Sentence and Label columns, and place them in the same folder as the script.

Note

The final model in the script gets to about 69.7% test accuracy and starts overfitting after the second or third epoch (validation loss climbs while training loss keeps dropping), which the inline notes call out. The script also trains a model twice: once directly near the middle of the file, and again through run_model() near the end with slightly different hyperparameters. The second run is the one whose results (confusion matrix included) are treated as final.

About

Financial sentiment analysis and stock forecasting framework using LSTM neural networks. Processes market news, investor commentary, and earnings transcripts to generate sentiment signals for directional equity prediction, achieving 70% out-of-sample accuracy on 50K+ records.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages