Giter VIP home page Giter VIP logo

achillesrasquinha / bulbea Goto Github PK

View Code? Open in Web Editor NEW
2.0K 128.0 473.0 2.7 MB

:boar: :bear: Deep Learning based Python Library for Stock Market Prediction and Modelling

Home Page: http://bulbea.readthedocs.io

License: Other

Makefile 1.02% Python 98.98%
deep-learning stock-market machine-learning finance sentiment-analysis quantitative-finance quantitative-trading stock-market-prediction stock-prediction python-library

bulbea's Introduction

bulbea

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

Gitter Documentation Status

Table of Contents

Installation

Clone the git repository:

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

Install necessary dependencies

$ pip install -r requirements.txt

Go ahead and install as follows:

$ python setup.py install

You may have to install TensorFlow:

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

Usage

1. Prediction

a. Loading

Create a share object.

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

Split your data set into training and testing sets.

>>> from bulbea.learn.evaluation import split
>>> Xtrain, Xtest, ytrain, ytest = split(share, 'Close', normalize = True)
c. Modelling
>>> import numpy as np
>>> Xtrain = np.reshape(Xtrain, (Xtrain.shape[0], Xtrain.shape[1], 1))
>>> Xtest  = np.reshape( Xtest, ( Xtest.shape[0],  Xtest.shape[1], 1))

>>> from bulbea.learn.models import RNN
>>> rnn = RNN([1, 100, 100, 1]) # number of neurons in each layer
>>> rnn.fit(Xtrain, ytrain)
# Epoch 1/10
# 1877/1877 [==============================] - 6s - loss: 0.0039
# Epoch 2/10
# 1877/1877 [==============================] - 6s - loss: 0.0019
...
d. Testing
>>> from sklearn.metrics import mean_squared_error
>>> p = rnn.predict(Xtest)
>>> mean_squared_error(ytest, p)
0.00042927869370525931
>>> import matplotlib.pyplot as pplt
>>> pplt.plot(ytest)
>>> pplt.plot(p)
>>> pplt.show()

2. Sentiment Analysis

Add your Twitter credentials to your environment variables.

export BULBEA_TWITTER_API_KEY="<YOUR_TWITTER_API_KEY>"
export BULBEA_TWITTER_API_SECRET="<YOUR_TWITTER_API_SECRET>"

export BULBEA_TWITTER_ACCESS_TOKEN="<YOUR_TWITTER_ACCESS_TOKEN>"
export BULBEA_TWITTER_ACCESS_TOKEN_SECRET="<YOUR_TWITTER_ACCESS_TOKEN_SECRET>"

And then,

>>> bb.sentiment(share)
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.

bulbea's People

Contributors

achillesrasquinha 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  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

bulbea's Issues

what can i do with the following issue?

when i run the code: share = bb.Share('YAHOO', 'GOOGL')
then i get the following result? Do you have the same problem?

TypeError Traceback (most recent call last)
in ()
----> 1 share = bb.Share('YAHOO', 'GOOGL')

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/bulbea-0.1.0-py2.7.egg/bulbea/entity/share.pyc in init(self, source, ticker, start, end, latest, cache)
164
165 if not _check_environment_variable_set(envvar):
--> 166 message = Color.warn("Environment variable {envvar} for Quandl hasn't been set. A maximum of {max_calls} calls per day can be made. Visit {url} to get your API key.".format(envvar = envvar, max_calls = QUANDL_MAX_DAILY_CALLS, url = ABSURL_QUANDL))
167
168 warnings.warn(message)

TypeError: unbound method warn() must be called with Color instance as first argument (got str instance instead)

not enough values to unpack (expected 5, got 4)

scaler, Xtrain, Xtest, ytrain, ytest = split(share, 'Close', normalize = True)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-6857080bc17c> in <module>()
----> 1 scaler, Xtrain, Xtest, ytrain, ytest = split(share, 'Close', normalize = True)

ValueError: not enough values to unpack (expected 5, got 4)

Share price - issue

I receive the below issue when running

import bulbea as bb
share = bb.Share('YAHOO', 'GOOGL')
share.data

module 'bulbea' has no attribute 'Share'

Something about Stock's Volume value

I found that majority implementations of stock prediction toke only one parameter as input, either 'Open' or 'Close' price. While I wonder if it is possible to combine 'Open' price and 'Volume' value together as input to the network to learn the relationship in between?

Change quandl example from WIKI to EOD.

quandl already not update WIKI source anymore.

Please change exmaple to EOD, which can fetch the latest prices.

Received this from Quandl Support April 11, 2018:

I'm emailing you because you've downloaded US stock price data from the WIKI data feed in the past.

As you know, WIKI is a community-maintained data feed based on public sources. Unfortunately, one of the main sources of that data is no longer available, and our community volunteers have been unable to find a suitable alternative source.

As a result, the WIKI data feed is likely to be a lot less reliable in the future, with potentially missing or incorrect data or delayed updates.

We will continue to host this data feed on Quandl, but we no longer recommend using it for investment or analysis.

Unfortunately, we don't have any free stock price data feeds that can replace WIKI at this time. The closest alternative we have is EOD, which is a value-priced end-of-day US stock price data feed.

Thank you for your understanding.

Calling out for Maintainers!

I'll be honest. This repo happens to be a Bachelor's Project Thesis for a pal of mine that I built in a week's time. Never expected sudden interest for it. Apologies for not looking into issues. I'm just expecting to find dedicated time for this too. I really appreciate your interest in bulbea and I'm looking for more improvements - right from data extraction to a UI (long-term goal). Hopefully, I find time to dedicate within a month or two.

Calling out for Maintainers!

Issue with Quandl??

When I do
`>>>share = bb.Share('YAHOO', 'GOOGL')'

I get
File "<stdin>", line 1, in <module> File "bulbea/entity/share.py", line 166, in __init__ message = Color.warn("Environment variable {envvar} for Quandl hasn't been set. A maximum of {max_calls} calls per day can be made. Visit {url} to get your API key.".format(envvar = envvar, max_calls = QUANDL_MAX_DAILY_CALLS, url = ABSURL_QUANDL)) TypeError: unbound method warn() must be called with Color instance as first argument (got str instance instead)

Since QuandL free tier doesn't exist, how do we switch?

QuandL does not provide any more free tier stock or ETF pricing & their premiums are insane. I assume share.py is the main file needed to be modified but I'm wondering if it's possible (if QuandL is absolutely necessary).

Any thoughts?

Production level

Is the Repo is still maintained ? Is it production level ? Which deep learning Framework is used Tensorflow / Pytorch ?

Import issue

When I import bulbea
import bulbea as bb

I got an error below.

OSError: 'seaborn' not found in the style library and input is not a valid URL or path. See style.available for list of available styles.

Could give me an advice? I installed all dependency.

CAN I USE THIS PROJECT TO PREDICT STOCK?

can you tell me how can i use all this line of code to make predictions about the stock cause i cant actually find anything about that please. i need your help . :)

import RNN does not work

When I tried to import RNN as shown in the example, I got the following error message. I use Anaconda with Python 3.7 on Windows 10. I installed all components as described in the manual. Does anyone has a similar issue?

from bulbea.learn.models import RNN

Using TensorFlow backend.
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.

ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.

Error in Share object creation

Hi, Im getting this eror, I installed all the requirements, tensorflow. Installed form latest master as instructed in docs

In [1]: import bulbea as bb

In [2]: share = bb.Share(source = 'YAHOO', ticker = 'GOOGL')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-bcc4c21f9124> in <module>()
----> 1 share = bb.Share(source = 'YAHOO', ticker = 'GOOGL')

/home/mahendra/workspace/dev/envs/bulbea/bulbea/bulbea/entity/share.py in __init__(self, source, ticker, start, end, latest, cache)
    164 
    165         if not _check_environment_variable_set(envvar):
--> 166             message = Color.warn("Environment variable {envvar} for Quandl hasn't been set. A maximum of {max_calls} calls per day can be made. Visit {url} to get your API key.".format(envvar = envvar, max_calls = QUANDL_MAX_DAILY_CALLS, url = ABSURL_QUANDL))
    167 
    168             warnings.warn(message)

TypeError: unbound method warn() must be called with Color instance as first argument (got str instance instead)

In [3]: 

How to use the predictor?

I would like to understand how to use the trained predictor with the latest data.
I am not sure about how I should normalize/denormalize the data and at what stage this has to be done.
Could you just give a few hints, please?

All the best,

No handling of NaN in data

Hi, I am having a problem where the data has a few NaN entries and it causes the code to crash. I may be mistaken, but it does not appear to be any handling of NaN in data. I tried to replace all NaN entries with 0, but it still got treated as NaN.

TypeError: 'module' object is not iterable

if someone could help me with this issue, I would very much appreciate:

C:\WINDOWS\system32>C:\Users\kanzl\Downloads\bulbea-master\bulbea-master\setup.py install
Traceback (most recent call last):
File "C:\Users\kanzl\Downloads\bulbea-master\bulbea-master\setup.py", line 107, in
main()
File "C:\Users\kanzl\Downloads\bulbea-master\bulbea-master\setup.py", line 104, in main
setup(**metadata)
File "C:\Users\kanzl\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools_init_.py", line 144, in setup
return distutils.core.setup(**attrs)
File "C:\Users\kanzl\AppData\Local\Programs\Python\Python38\lib\distutils\core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "C:\Users\kanzl\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools\dist.py", line 425, in init
_Distribution.init(self, {
File "C:\Users\kanzl\AppData\Local\Programs\Python\Python38\lib\distutils\dist.py", line 292, in init
self.finalize_options()
File "C:\Users\kanzl\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools\dist.py", line 717, in finalize_options
ep(self)
File "C:\Users\kanzl\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools\dist.py", line 724, in _finalize_setup_keywords
ep.load()(self, ep.name, value)
File "C:\Users\kanzl\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools\dist.py", line 327, in check_packages
for pkgname in value:
TypeError: 'module' object is not iterable

support create share from existing Pandas DataFrame directly

Right now the Share could be created only by source and ticket. Could bulbea add support to create Share from existing DataFrame?, something like:

pre_existing_dataframe = load_some_data()
share = bb.Share(data=pre_existing_dataframe)

It could help bb to work with 3rd party data sources

SyntaxWarning and FileNotFoundError

I'm getting these errors when trying to run the setup:

C:\Windows\System32>C:\Users\kanzl\Downloads\bulbea-master\bulbea-master\setup.py install
C:\Users\kanzl\Downloads\bulbea-master\bulbea-master\setup.py:65: SyntaxWarning: "is" with a literal. Did you mean "=="?
content += '{prepend}{content}'.format(prepend = '' if i is 0 else '\n\n', content = raw)
Traceback (most recent call last):
File "C:\Users\kanzl\Downloads\bulbea-master\bulbea-master\setup.py", line 107, in
main()
File "C:\Users\kanzl\Downloads\bulbea-master\bulbea-master\setup.py", line 89, in main
long_description = get_long_description(package.long_description),
File "C:\Users\kanzl\Downloads\bulbea-master\bulbea-master\setup.py", line 71, in get_long_description
raise FileNotFoundError('No such file found: {filepath}'.format(filepath = filepath))
FileNotFoundError: No such file found: README.md

If you could help I would appreciate, thanks

Use of the project

Excuse me, can this project be used to predict the economic prosperity index? My data is: X-axis refers to time, and Y-axis refers to a type of economic data. Can it be used to predict?

Help Needed: (Quandl Error QECx02) You have submitted an incorrect Quandl code. Please check your Quandl codes and try again

Hi,

When I try to follow the example, I have the following errors. Please help.

share = bb.Share('YAHOO', 'GOOGL')
Traceback (most recent call last):
File "", line 1, in
File "/home/edison/bulbea/bulbea/entity/share.py", line 175, in init
self.update(start = start, end = end, latest = latest, cache = cache)
File "/home/edison/bulbea/bulbea/entity/share.py", line 189, in update
code = self.ticker
File "/home/edison/.local/lib/python3.5/site-packages/quandl/get.py", line 48, in get
data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True)
File "/home/edison/.local/lib/python3.5/site-packages/quandl/model/dataset.py", line 47, in data
return Data.all(**updated_options)
File "/home/edison/.local/lib/python3.5/site-packages/quandl/operations/list.py", line 14, in all
r = Connection.request('get', path, **options)
File "/home/edison/.local/lib/python3.5/site-packages/quandl/connection.py", line 36, in request
return cls.execute_request(http_verb, abs_url, **options)
File "/home/edison/.local/lib/python3.5/site-packages/quandl/connection.py", line 44, in execute_request
cls.handle_api_error(response)
File "/home/edison/.local/lib/python3.5/site-packages/quandl/connection.py", line 85, in handle_api_error
raise klass(message, resp.status_code, resp.text, resp.headers, code)
quandl.errors.quandl_error.NotFoundError: (Status 404) (Quandl Error QECx02) You have submitted an incorrect Quandl code. Please check your Quandl codes and try again.

Thanks.
Best Regards,
Edison

bulbea crashes when executing "share = bb.Share('YAHOO', 'GOOGL')" in python2.7

Hello, today I attempted to install the library and run into an issue.
after importing bulbea with >>> import bulbea as bb everything seamed normal but when trying to run
>>> share = bb.Share('YAHOO', 'GOOGL')
I get this following error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "bulbea/entity/share.py", line 166, in __init__ message = Color.warn("Environment variable {envvar} for Quandl hasn't been set. A maximum of {max_calls} calls per day can be made. Visit {url} to get your API key.".format(envvar = envvar, max_calls = QUANDL_MAX_DAILY_CALLS, url = ABSURL_QUANDL)) TypeError: unbound method warn() must be called with Color instance as first argument (got str instance instead)
Now I have no clue what exactly went wrong or why it isn't working, can someone help me with this?

NotFoundError: (Status 404) (Quandl Error QECx02)

UserWarning: Environment variable BULBEA_QUANDL_API_KEY for Quandl hasn't been set. A maximum of 50000 calls per day can be made. Visit https://www.quandl.com to get your API key.
warnings.warn(message)

NotFoundError: (Status 404) (Quandl Error QECx02) You have submitted an incorrect Dataset code. Please check your Dataset codes and try again.

need help

import bulbea as bb
share = bb.Share('Wiki','GOOGL')
share.data

with this code i get this error

Warning (from warnings module):
File "C:\Users\Caste\AppData\Local\Programs\Python\Python37\lib\site-packages\bulbea-0.1.0-py3.7.egg\bulbea\entity\share.py", line 168
UserWarning: �[01m�[33mEnvironment variable BULBEA_QUANDL_API_KEY for Quandl hasn't been set. A maximum of 50000 calls per day can be made. Visit https://www.quandl.com to get your API key.�[0m

what i can do helpppppp meeeeeeee!

How to get the original close price from normalized price after prediction?

The normalized Close data is very different from the original close price, because we are using cumulative returns.
google_stock
pred

The first picture is Google stock price. The second picture is the keras RNN prediction on the normalized data. It looks very different
how do I convert the prediction back to the original price?

use log returns instead of cummulative returns for split() normalization

In split() when setting normalize to true, bulbea will use cummulative returns to normalize the data first and then split the data. How about use log returns instead of cummulative returns for normalization?

Log returns are more useful in quant world than cummulative returns.

Cummulative returns hides the short term relative returns. How today's price comparing with yestoday or last month is more important than comparing with the very first inital price (maybe several years before), IMOH.

missing 1 required positional argument: 'units' ann.py rnn

Hi, I have been trying to set this up and I receive this error after running the script in the readme. Please let me know how to fix; I am not very familiar with python. Thanks!

File "main.py", line 16, in
rnn = RNN([1, 100, 100, 1]) # number of neurons in each layer
File "/usr/local/lib/python3.7/site-packages/bulbea-0.1.0-py3.7.egg/bulbea/learn/models/ann.py", line 29, in init
TypeError: init() missing 1 required positional argument: 'units'

The whole script:

import bulbea as bb
share = bb.Share('WIKI', 'GOOGL')
share.data

from bulbea.learn.evaluation import split
Xtrain, Xtest, ytrain, ytest = split(share, 'Close', normalize = True)

import numpy as np
Xtrain = np.reshape(Xtrain, (Xtrain.shape[0], Xtrain.shape[1], 1))
Xtest = np.reshape(Xtest, (Xtest.shape[0], Xtest.shape[1], 1))

from bulbea.learn.models import RNN
rnn = RNN([1, 100, 100, 1]) # number of neurons in each layer
rnn.fit(Xtrain, ytrain)

from sklearn.metrics import mean_squared_error
p = rnn.predict(Xtest)
mean_squared_error(ytest, p)

import matplotlib.pyplot as pplt
pplt.plot(ytest)
pplt.plot(p)
pplt.show()

Fix simple typo: seperated -> separated

Issue Type

[x] Bug (Typo)

Steps to Replicate

  1. Examine docs/blog/data-data-everywhere.rst.
  2. Search for seperated.

Expected Behaviour

  1. Should read separated.

Semi-automated issue generated by
https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

To avoid wasting CI processing resources a branch with the fix has been
prepared but a pull request has not yet been created. A pull request fixing
the issue can be prepared from the link below, feel free to create it or
request @timgates42 create the PR.

https://github.com/timgates42/bulbea/pull/new/bugfix_typo_separated

Thanks.

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.