Skip to content

Commit

Permalink
Release 0.1.0.
Browse files Browse the repository at this point in the history
Generate the first beta release for the python stock indicator library
based on pandas DataFrame.
  • Loading branch information
Cedric Zhuang committed Jun 5, 2016
0 parents commit 19bf160
Show file tree
Hide file tree
Showing 13 changed files with 5,007 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .gitignore
@@ -0,0 +1,20 @@
# Binaries
*.pyc
.tox/
.env/
.cache/
~/
build/
dist/
*.egg-info/
.eggs/
docs/_build/doctrees/

# IDE related
.idea/

# tests
junit-result.xml
htmlcov/
.coverage
__pycache__/
17 changes: 17 additions & 0 deletions .travis.yml
@@ -0,0 +1,17 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
install:
- pip install coveralls
- pip install -r requirements.txt
- pip install -r test-requirements.txt
script:
- flake8 stockstats.py test.py
- py.test --cov=stockstats --junit-xml=junit-result.xml --cov-report term-missing test.py
after_success:
- coveralls
notifications:
email:
- jealous@163.com
3,660 changes: 3,660 additions & 0 deletions 987654.csv

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,24 @@
Copyright (c) 2016, Cedric Zhuang
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of disclaimer nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 3 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,3 @@
include *.rst
include *.cfg
include *.txt
145 changes: 145 additions & 0 deletions README.rst
@@ -0,0 +1,145 @@
Stock Statistics/Indicators Calculation Helper
==============================================

.. image:: https://travis-ci.org/jealous/stockstats.svg
:target: https://travis-ci.org/jealous/stockstats

.. image:: https://coveralls.io/repos/jealous/stockstats/badge.svg
:target: https://coveralls.io/github/jealous/stockstats

.. image:: https://img.shields.io/pypi/v/stockstats.svg
:target: https://pypi.python.org/pypi/stockstats


VERSION: 0.1.0

Introduction
------------

Supply a wrapper ``StockDataFrame`` based on the ``pandas.DataFrame`` with
inline stock statistics/indicators support.

Supported statistics/indicators are:

- change (in percent)
- delta
- permutation (zero based)
- log return
- max in range
- min in range
- middle = (close + high + low) / 3
- SMA: simple moving average
- EMA: exponential moving average
- MSTD: moving standard deviation
- MVAR: moving variance
- RSV: raw stochastic value
- KDJ: Stochastic oscillator
- Bolling: including upper band and lower band.
- MACD: moving average convergence divergence. Including signal and histogram.
- CR:
- line cross check, cross up or cross down.


Installation
------------

``pip install stockstats``


License
-------

`BSD`_

Tutorial
--------

- Initialize the ``StockDataFrame`` with the ``retype`` function which
convert a ``pandas.DataFrame`` to a ``StockDataFrame``.

.. code-block:: python
stock = StockDataFrame.retype(pd.read_csv('stock.csv'))
- There are some shortcuts for frequent used statistics/indicators like
``kdjk``, ``boll_hb``, ``macd``, etc.

- The indicators/statistics are generated on the fly when they are accessed.
If you are accessing through ``Series``, it may return not found error.
The fix is to explicitly initialize it by accessing it like below:

.. code-block:: python
_ = stock['macd']
# or
stock.get('macd')
- Using get item to access the indicators. The item name following the
pattern: ``{columnName_window_statistics}``.
Some statistics/indicators has their short cut. See examples below:

.. code-block:: python
# volume delta against previous day
stock['volume_delta']
# open delta against next 2 day
stock['open_2_d']
# open price change (in percent) between today and the day before yesterday
# 'r' stands for rate.
stock['open_-2_r']
# CR indicator, including 5, 10, 20 days moving average
stock['cr']
stock['cr-ma1']
stock['cr-ma2']
stock['cr-ma3']
# volume max of three days ago, yesterday and two days later
stock['volume_-3,2,-1_max']
# volume min between 3 days ago and tomorrow
stock['volume_-3~1_min']
# KDJ, default to 9 days
stock['kdjk']
stock['kdjd']
stock['kdjj']
# three days KDJK cross up 3 days KDJD
stock['kdj_3_xu_kdjd_3']
# 2 days simple moving average on open price
stock['open_2_sma']
# MACD
stock['macd']
# MACD signal line
stock['macds']
# MACD histogram
stock['macdh']
# bolling, including upper band and lower band
stock['boll']
stock['boll_ub']
stock['boll_lb']
# close price less than 10.0 in 5 days count
stock['close_10.0_le_5_c']
# CR MA2 cross up CR MA1 in 20 days count
stock['cr-ma2_xu_cr-ma1_20_c']
To file issue, please visit:

https://github.com/jealous/stockstats


Contact author:

- Cedric Zhuang <jealous@163.com>

.. _BSD: LICENSE.txt
.. _test.py: test.py
3 changes: 3 additions & 0 deletions requirements.txt
@@ -0,0 +1,3 @@
numpy>=1.9.2
pandas>=0.15.2
int_date>=0.1.7
2 changes: 2 additions & 0 deletions setup.cfg
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
96 changes: 96 additions & 0 deletions setup.py
@@ -0,0 +1,96 @@
# coding=utf-8
# Copyright (c) 2016, Cedric Zhuang
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of disclaimer nor the names of its contributors may
# be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from setuptools import setup
import io
import re
import os

__author__ = 'Cedric Zhuang'


def version():
desc = get_long_description()
ret = re.findall(r'VERSION: (.*)', desc)[0]
return ret.strip()


def here(filename=None):
ret = os.path.abspath(os.path.dirname(__file__))
if filename is not None:
ret = os.path.join(ret, filename)
return ret


def read(*filenames, **kwargs):
encoding = kwargs.get('encoding', 'utf-8')
sep = kwargs.get('sep', '\n\n')
buf = []
for filename in filenames:
with io.open(here(filename), encoding=encoding) as f:
buf.append(f.read())
return sep.join(buf)


def read_requirements(filename):
with open(filename) as f:
return f.read().splitlines()


def get_long_description():
filename = 'README.rst'
return read(filename)


setup(
name="stockstats",
version=version(),
author="Cedric Zhuang",
author_email="jealous@163.com",
description="DataFrame with inline stock statistics support.",
license="BSD",
keywords="stock statistics indicator",
url="http://github.com/jealous/stockstats",
py_modules=['stockstats'],
platforms=['any'],
long_description=get_long_description(),
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: Implementation :: CPython",
"Natural Language :: English",
"Intended Audience :: Developers",
"Intended Audience :: Financial and Insurance Industry",
"Operating System :: OS Independent",
"Development Status :: 4 - Beta",
"Topic :: Utilities",
"License :: OSI Approved :: Apache Software License",
],
install_requires=read_requirements('requirements.txt'),
tests_require=read_requirements('test-requirements.txt')
)

0 comments on commit 19bf160

Please sign in to comment.