Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .github/bulbea.png
Binary file not shown.
Binary file added .github/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 4 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# virtualenvs
# venv
.venv

# docs
docs/_build

# Jupyter Checkpoints
examples/.ipynb_checkpoints

# twitter
twitter.sh

# misc
snippet.py
# cache
notebooks/.ipynb_checkpoints
.DS_Store
19 changes: 16 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
.PHONY: docs

PYTHON = python
PYTHON ?= python
PYTHON3 ?= python3

BASEDIR = $(realpath .)
DOCSDIR = $(BASEDIR)/docs
GITHUBDIR = $(BASEDIR)/.github
LOGO = $(GITHUBDIR)/logo.png

PIP ?= pip3
VIRTUALENV ?= virtualenv

venv:
$(PIP) install virtualenv

$(VIRTUALENV) .venv/py3 --python $(PYTHON3)

install:
cat requirements/*.txt > requirements.txt
Expand All @@ -10,9 +24,8 @@ install:

$(PYTHON) setup.py install

bash twitter.sh

docs:
cp $(LOGO) $(DOCSDIR)/_static/img
cd docs && make html

tests:
Expand Down
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# bulbea
> *"Deep Learning based Python Library for Stock Market Prediction and Modelling."*

[![Gitter](https://img.shields.io/gitter/room/bulbea/bulbea.svg)](https://gitter.im/bulbea/bulbea) [![Documentation Status](https://readthedocs.org/projects/bulbea/badge/?version=latest)](http://bulbea.readthedocs.io/en/latest/?badge=latest)

![](.github/bulbea.png)
<div align="center">
<img src=".github/logo.png" height="256">
<h1>bulbea</h1>
<h5>Deep Learning based Python Library for Stock Market Prediction and Modelling</h5>
</div>

<div align="center">
<a href='http://bulbea.readthedocs.io/en/latest/?badge=latest'>
<img src='https://readthedocs.org/projects/bulbea/badge/?style=flat-square&version=latest'/>
</a>
<a href='https://gitter.im/bulbea/bulbea'>
<img src='https://img.shields.io/gitter/room/bulbea/bulbea.svg'/>
</a>
<a href="https://saythanks.io/to/achillesrasquinha">
<img src="https://img.shields.io/badge/Say%20Thanks-🦉-1EAEDB.svg?style=flat-square">
</a>
<a href="https://paypal.me/achillesrasquinha">
<img src="https://img.shields.io/badge/donate-💵-f44336.svg?style=flat-square">
</a>
</div>

### Table of Contents
* [Installation](#installation)
Expand All @@ -13,7 +27,7 @@
* [License](#license)

### Installation
Clone the git repository:
Download or clone the repository using `git`:
```console
$ git clone https://github.com/achillesrasquinha/bulbea.git && cd bulbea
```
Expand Down
1 change: 1 addition & 0 deletions bulbea/config/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AppConfig(BaseConfig):

ENVIRONMENT_VARIABLE = {
'quandl_api_key': 'BULBEA_QUANDL_API_KEY',
'tiingo_api_key': 'BULBEA_TIINGO_API_KEY',
'twitter_api_key': 'BULBEA_TWITTER_API_KEY',
'twitter_api_secret': 'BULBEA_TWITTER_API_SECRET',
'twitter_access_token': 'BULBEA_TWITTER_ACCESS_TOKEN',
Expand Down
71 changes: 62 additions & 9 deletions bulbea/entity/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
# imports - standard packages
import os
import warnings
import requests

# imports - third-party packages
import numpy as np
import matplotlib.pyplot as pplt
import pandas as pd
import quandl
# import quandl

# module imports
from bulbea.config.app import AppConfig
Expand Down Expand Up @@ -156,10 +157,12 @@ class Share(Entity):
Date
2003-05-15 18.6 18.849999 18.470001 18.73 71248800.0 1.213325
'''
def __init__(self, source, ticker, start = None, end = None, latest = None, cache = False):
_check_str(source, raise_err = True)
# def __init__(self, source, ticker, start = None, end = None, latest = None, cache = False):
def __init__(self, ticker, start=None, end=None, latest=None, cache=False):
# _check_str(source, raise_err = True)
_check_str(ticker, raise_err = True)

'''
envvar = AppConfig.ENVIRONMENT_VARIABLE['quandl_api_key']

if not _check_environment_variable_set(envvar):
Expand All @@ -168,8 +171,20 @@ def __init__(self, source, ticker, start = None, end = None, latest = None, cach
warnings.warn(message)
else:
quandl.ApiConfig.api_key = os.getenv(envvar)

self.source = source
'''

envvar = AppConfig.ENVIRONMENT_VARIABLE['tiingo_api_key']
config = {}
if not _check_environment_variable_set(envvar):
message = Color.warn("Environment variable {envvar} for Tiingo not configure correctly ")

warnings.warn(message)
else:
self.tiingo_token = os.getenv(envvar)


self.ticker = ticker

self.update(start = start, end = end, latest = latest, cache = cache)
Expand All @@ -184,10 +199,18 @@ def update(self, start = None, end = None, latest = None, cache = False):
>>> share = bb.Share(source = 'YAHOO', ticker = 'AAPL')
>>> share.update()
'''
self.data = quandl.get('{database}/{code}'.format(
database = self.source,
code = self.ticker
))
# self.data = quandl.get('{database}/{code}'.format(
# database = self.source,
# code = self.ticker
# ))
# url = "https://api.tiingo.com/tiingo/daily/{ticker}/prices?startDate={start_date}&endDate={end_date}&token={token}"
# self.data = pd.read_json(url.format(
# ticker=ticker,
# start_date=start,
# end_date=end,
# token=self.tiingo_token
# ))
self.data = self.getDataTiingo(self.ticker, start, end)
self.length = len(self.data)
self.attrs = list(self.data.columns)

Expand Down Expand Up @@ -316,4 +339,34 @@ def save(self, format_ = 'csv', filename = None):
filename = _get_share_filename(self, extension = format_)

if format_ is 'csv':
self.data.to_csv(filename)
self.data.to_csv(filename)

def getDataTiingo(self, ticker, d_start, d_end):
headers = {
'Content-Type': 'application/json',
'Authorization': 'Token ' + self.tiingo_token
}
url = "https://api.tiingo.com/tiingo/daily/" + ticker + "/prices?startDate=" + d_start + "&endDate=" + d_end

# print url
requestResponse = requests.get(url, headers=headers)
json_result = requestResponse.json()

df = pd.DataFrame.from_records(json_result)

if not 'adjClose' in df.columns:
if 'close' in df.columns:
df['adjClose'] = df['close']
else:
print("Error: No Close information")
return

# Convert ISO date format to Pandas DateTime
df['date'] = pd.to_datetime(df['date'])
# Align Column Names to previous DataReader names
df = df.rename(
columns={'date': 'Date', 'open': 'Open', 'adjClose': 'Adj Close', 'volume': 'Volume', 'high': 'High',
'low': 'Low', 'close': 'Close'})
a = df.set_index(['Date'])
# print a
return a
Binary file removed docs/_static/bulbea.png
Binary file not shown.
Binary file added docs/_static/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/_templates/sidebar-logo.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p class="logo">
<a href="{{ pathto(master_doc) }}">
<img class="logo" src="{{ pathto('_static/bulbea.png', 1) }}"/>
<img class="logo" src="{{ pathto('_static/img/logo.png', 1) }}"/>
</a>
</p>

Expand Down