This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Stock market analysis library written in Python.

Features

  • Market data sourcing from Yahoo!, CNBC, and zipline bundles
  • S&P500 stock listing scraper
  • ADX, DI, and Stochastic technical indicators implemented using TA-lib
  • Average Directional Movement Index (ADX) ranking for portfolios
  • Trending and oscillating instrument trading algorithms for zipline

Installation

Install the latest package with:

$ pip install stockbot

The dependencies are not trivial and may not install properly on your system through pip. We recommend developing and deploying your projects that use stockbot in containers with the necessary packages pre-installed.

One way to do this is to first build the quantopian/zipline Docker image with the following command:

$ docker build -t quantopian/zipline https://github.com/quantopian/zipline.git#1.0.2

Using a docker-compose development configuration similar to the one contained in stockbot, you could then create a development container with:

$ docker-compose -f docker-compose-dev.yml up

Note that our docker configuration installs the latest zipline quantopian-quandl bundle in the project root. This is necessary for the default stockbot configuration when using functions such as get_zipline_dp and get_zipline_hist.

Usage

Stockbot can provide you with a list of S&P500 stocks from wikipedia:

>>> from stockbot.core import get_sp500_list
>>> get_sp500_list()
[u'MMM', u'ABT', u'ABBV', u'ACN', u'ATVI', u'AYI', u'ADBE', ... u'ZTS']

To get a delayed quote from Yahoo! use get_yahoo_quote:

>>> from stockbot.sources import get_yahoo_quote
>>> get_yahoo_quote('YHOO')
{'volume': 3405057, 'last': 41.0, 'symbol': 'YHOO', 'datetime': datetime.datetime(2016, 11, 22, 18, 0, tzinfo=<UTC>), 'high': 41.4, 'low': 40.83, 'open': 41.2, 'change': -0.11}

Or a real-time quote from CNBC using get_cnbc_quote:

>>> from stockbot.sources import get_cnbc_quote
>>> next(get_cnbc_quote('YHOO'))
{'volume': 3528566, 'last': 41.04, 'symbol': u'YHOO', 'datetime': datetime.datetime(2016, 11, 22, 21, 0, tzinfo=<UTC>), 'high': 41.395, 'low': 40.83, 'open': 41.2, 'change': -0.07}

Note:: get_cnbc_quote returns a generator

Stockbot returns quote data using a dict like object stockbot.marketdata.MarketData that performs certain data and datetime processing.

Historical data can be obtained from Yahoo! using get_yahoo_hist:

>>> from stockbot.sources import get_yahoo_hist
>>> get_yahoo_hist('YHOO')
{'high': 41.48, 'last': 41.110001, 'datetime': datetime.datetime(2016, 11, 21, 21, 0, tzinfo=<UTC>), 'volume': 11338000, 'low': 40.939999, 'close': 41.110001, 'open': 41.439999}

Historical data can also be obtained from zipline bundles using the get_zipline_hist function:

>>> from stockbot.sources import get_zipline_hist
>>> get_zipline_hist('YHOO', 'close',
2016-01-04 00:00:00+00:00    31.41
Freq: C, Name: Equity(3177 [YHOO]), dtype: float64

Look up symbols with stockbot.sources.get_symbol which searches Yahoo! finance for the passed term.

Zipline trading algorithms that utilize the Directional Movement technical indicator system are provided in stockbot.algo. For example, the following zipline trading algorithm would use ADX and DI to trade the top trending stocks and Stochastic Oscillators to trade the top oscillating stocks in the S&P 500 index:

from logbook import Logger
from stockbot.algo.core import (
    adx_init,
    trade_di,
    trade_so,
)
from stockbot.core import get_sp500_list

def initialize(context):
    return adx_init(
        context,
        name='adx_di_so',
        top_rank=5,
        bot_rank=5,
        di_window=14,
        symbols=get_sp500_list(),
        log=Logger('Stockbot'),
    )

def handle_data(context, data):
    # increment counter and log datetime
    context.i += 1
    context.adx['log'].info('processing %s' % context.get_datetime())

    # trade trending S&P500 stocks using the DI system
    trade_di(
        context,
        data,
        window=context.adx['di_window'],
        portfolio=[i for (i, adx) in context.adx['top']],
        capital_ppi=1.0/(len(context.adx['top'])+len(context.adx['bot'])),
        log=context.adx['log'],
    )

    # trade oscillating S&P500 stocks using the SO system
    trade_so(
        context,
        data,
        window=context.adx['di_window'],
        portfolio=[i for (i, adx) in context.adx['bot']],
        capital_ppi=1.0/(len(context.adx['top'])+len(context.adx['bot'])),
        log=context.adx['log'],
    )

To run this algorithm in a docker container, copy the code above into a file and issue the following:

$ zipline run -f <file> --start <date> --end <date>

Use the the <YYYY-M-D> format for dates. Use -o /path/file.pickle to capture pickled results that can be used in python.

History

0.1.0 (2015-09-23)

  • created basic market data sourcing from Yahoo! and CNBC

0.2.0 (2016-11-22)

  • created S&P500 stock listing scraper
  • implemented TA-lib for technical analysis (ADX, DI, STOCH)
  • added zipline bundles to data sourcing
  • created zipline trading algorithms for trending and oscillating instruments
Release History

Release History

0.2.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
stockbot-0.2.0-py2.py3-none-any.whl (13.7 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Nov 22, 2016
stockbot-0.2.0.tar.gz (94.5 kB) Copy SHA256 Checksum SHA256 Source Nov 22, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting