项目作者: achillesrasquinha

项目描述 :
:boar: :bear: Deep Learning based Python Library for Stock Market Prediction and Modelling
高级语言: Python
项目地址: git://github.com/achillesrasquinha/bulbea.git
创建时间: 2017-03-09T06:11:06Z
项目社区:https://github.com/achillesrasquinha/bulbea

开源协议:Other

下载


bulbea

“Deep Learning based Python Library for Stock Market Prediction and Modelling.”

Gitter Documentation Status

Table of Contents

Installation

Clone the git repository:

  1. $ git clone https://github.com/achillesrasquinha/bulbea.git && cd bulbea

Install necessary dependencies

  1. $ pip install -r requirements.txt

Go ahead and install as follows:

  1. $ python setup.py install

You may have to install TensorFlow:

  1. $ pip install tensorflow # CPU
  2. $ pip install tensorflow-gpu # GPU - Requires CUDA, CuDNN

Usage

1. Prediction

a. Loading

Create a share object.

  1. >>> import bulbea as bb
  2. >>> share = bb.Share('YAHOO', 'GOOGL')
  3. >>> share.data
  4. # Open High Low Close Volume \
  5. # Date
  6. # 2004-08-19 99.999999 104.059999 95.959998 100.339998 44659000.0
  7. # 2004-08-20 101.010005 109.079998 100.500002 108.310002 22834300.0
  8. # 2004-08-23 110.750003 113.479998 109.049999 109.399998 18256100.0
  9. # 2004-08-24 111.239999 111.599998 103.570003 104.870002 15247300.0
  10. # 2004-08-25 104.960000 108.000002 103.880003 106.000005 9188600.0
  11. ...
b. Preprocessing

Split your data set into training and testing sets.

  1. >>> from bulbea.learn.evaluation import split
  2. >>> Xtrain, Xtest, ytrain, ytest = split(share, 'Close', normalize = True)
c. Modelling
  1. >>> import numpy as np
  2. >>> Xtrain = np.reshape(Xtrain, (Xtrain.shape[0], Xtrain.shape[1], 1))
  3. >>> Xtest = np.reshape( Xtest, ( Xtest.shape[0], Xtest.shape[1], 1))
  4. >>> from bulbea.learn.models import RNN
  5. >>> rnn = RNN([1, 100, 100, 1]) # number of neurons in each layer
  6. >>> rnn.fit(Xtrain, ytrain)
  7. # Epoch 1/10
  8. # 1877/1877 [==============================] - 6s - loss: 0.0039
  9. # Epoch 2/10
  10. # 1877/1877 [==============================] - 6s - loss: 0.0019
  11. ...
d. Testing
  1. >>> from sklearn.metrics import mean_squared_error
  2. >>> p = rnn.predict(Xtest)
  3. >>> mean_squared_error(ytest, p)
  4. 0.00042927869370525931
  5. >>> import matplotlib.pyplot as pplt
  6. >>> pplt.plot(ytest)
  7. >>> pplt.plot(p)
  8. >>> pplt.show()

2. Sentiment Analysis

Add your Twitter credentials to your environment variables.

  1. export BULBEA_TWITTER_API_KEY="<YOUR_TWITTER_API_KEY>"
  2. export BULBEA_TWITTER_API_SECRET="<YOUR_TWITTER_API_SECRET>"
  3. export BULBEA_TWITTER_ACCESS_TOKEN="<YOUR_TWITTER_ACCESS_TOKEN>"
  4. export BULBEA_TWITTER_ACCESS_TOKEN_SECRET="<YOUR_TWITTER_ACCESS_TOKEN_SECRET>"

And then,

  1. >>> bb.sentiment(share)
  2. 0.07580128205128206

Documentation

Detailed documentation is available here.

Dependencies

  1. quandl
  2. keras
  3. tweepy
  4. textblob

License

This code has been released under the Apache 2.0 License.