GithubHelp home page GithubHelp logo

vedic-partap / event-driven-stock-prediction-using-deep-learning Goto Github PK

View Code? Open in Web Editor NEW
198.0 11.0 91.0 52.59 MB

A deep learning method for event driven stock market prediction. Deep learning is useful for event-driven stock price movement prediction by proposing a novel neural tensor network for learning event embedding, and using a deep convolutional neural network to model the combined influence of long-term events and short-term events on stock price movements

Python 100.00%

event-driven-stock-prediction-using-deep-learning's Introduction

Event-Driven Stock Prediction using Deep-Learning

A deep learning method for event driven stock market prediction. Deep learning is useful for event-driven stock price movement prediction by proposing a novel neural tensor network for learning event embedding, and using a deep convolutional neural network to model the combined influence of long-term events and short-term events on stock price movements

Important concept need to be learnt :

  1. NLP - http://web.stanford.edu/class/cs224n
  2. GloVe - GloVe- https://nlp.stanford.edu/pubs/glove.pdf
  3. NLT - www.nltk.org
  4. Convolutional Neural Network - http://www.aclweb.org/anthology/D14-1181

Sentiment Analysis for Event-Driven Stock Prediction

Also try to visualize the data on smaller dimension using PCA to get the good idea of the problem

Use NLP to predict stock price movement based on news from Reuters, we need the following 5 steps:

  1. Collection of Data ( essential and tricky task )

    1.1 get the whole ticker list

    1.2 crawl news

    1.3 crawl prices using urllib2 (Yahoo Finance API is outdated)

  2. Train the GloVe in corpus in NLTK

    2.1 build the word-word co-occurrence matrix

    2.2 factorizing the weighted log of the co-occurrence matrix

  3. Feature Engineering

    3.2 Unify word format: unify tense, singular & plural, remove punctuations & stop words

    3.2 Extract feature using feature hashing based on the trained word vector (step 2)

    3.3 Pad word senquence (essentially a matrix) to keep the same dimension

  4. Trained a ConvNet to predict the stock price movement based on a reasonable parameter selection

  5. The result shows a significant 1-2% improve on the test set

Use the following script to crawl it and format it to our local file Note : We can relate the news with company and date, this is more precise than Bloomberg News

1 Crawling of Data

python crawler_reuters.py 

Yahoo Finanace is also a great place to collect the data

2 Word Embedding

To use our customized word vector, apply GloVe to train word vector from Reuters corpus in NLTK

python embeddingWord.py

To use pre-trained GloVe word vectors

python embeddingWordPre.py

3. Feature Engineering

Projection of word to word vector Seperate test set away from training+validation test, otherwise we would get a too optimistic result.

python genFeatureMatrix.py

Here there is important point to note when we are separating the Cross Validation set and the Training Set. The shuffiling of data can create a very large mistake and untraceble. Consider we have news that are similar in contex but the language of news are slightly different and the got separated in training and the cross validation set. Then the error in cross validation set get biased as the model is already trained against that model so that example will be of no use and effective cross validation set reduces.

4. Training

To train a Stacked-Bidirectional GRU network to predict the stock price movement.

python model_sb_gru.py

To train a ConvoNet network to predict the stock price movement.

python model_cnn.py

5. Model

Model folder contains a trained model with 100K news on Stacked-Bidirectional GRU network. To use the model

cd model
python load.py

Accuracy of model is 96.79%. Furthur improvement like attention mechanism or cyclic learning rate is required.

Other Reading Materials

  1. H Lee, etc, On the Importance of Text Analysis for Stock Price Prediction, LREC, 20145. Xiao Ding, Deep Learning for Event-Driven Stock Prediction, IJCAI2015
  2. IMPLEMENTING A CNN FOR TEXT CLASSIFICATION IN TENSORFLOW
  3. Keras predict sentiment-movie-reviews using deep learning
  4. Keras sequence-classification-lstm-recurrent-neural-networks
  5. tf-idf + t-sne
  6. Implementation of CNN in sequence classification
  7. Getting Started with Word2Vec and GloVe in Python

event-driven-stock-prediction-using-deep-learning's People

Contributors

sahiljajodia01 avatar toshal-a avatar vedic-partap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

event-driven-stock-prediction-using-deep-learning's Issues

ImportError: No module named en

ub16hp@UB16HP:~/ub16_prj/Event-Driven-Stock-Prediction-using-Deep-Learning$ python embeddingWord.py
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
Traceback (most recent call last):
File "embeddingWord.py", line 8, in
import en
ImportError: No module named en

no news for any tickers

The following line 48 in crawler_reuters might need an update-
"has_Content = len(soup.find_all("div", {'class': ['topStory', 'feature']}))"

fields 'topstory' & 'feature' do not exist on the page. Might need replacement with "MARKET VIEWS"

ValueError: cannot reshape array of size 150000000 into shape (50000,20,50,1)

ub16hp@UB16HP:/ub16_prj/Event-Driven-Stock-Prediction-using-Deep-Learning$ python model_cnn.py
Using TensorFlow backend.
Traceback (most recent call last):
File "model_cnn.py", line 99, in
main()
File "model_cnn.py", line 94, in main
model_selection(clusters)
File "model_cnn.py", line 84, in model_selection
X_train, y_train, X_valid, y_valid, X_test, y_test = get_Feature_Label(clusters=clusters)
File "model_cnn.py", line 40, in get_Feature_Label
X = X.reshape(X.shape[0], 20, 50, 1).astype('float32')
ValueError: cannot reshape array of size 150000000 into shape (50000,20,50,1)
ub16hp@UB16HP:
/ub16_prj/Event-Driven-Stock-Prediction-using-Deep-Learning$ vim model_cnn.py
ub16hp@UB16HP:~/ub16_prj/Event-Driven-Stock-Prediction-using-Deep-Learning$ ll
total 576
drwxrwxr-x 4 ub16hp ub16hp 4096 12ๆœˆ 25 16:04 ./

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.