The wrapper of `pandas.DataFrame` with stock statistics and indicators support.
Project description
stock-pandas
A wrapper and a subtle class of pandas.DataFrame
which supports:
- stock statistics
- all kinds of stock indicators
stock-pandas
makes automatical trading much easier.
Install
pip install stock-pandas
Usage
from stock_pandas import StockDataFrame
We also have some examples with annotations in the example
directory, you could use JupyterLab or Jupyter notebook to play with them.
StockDataFrame
StockDataFrame
inherits from pandas.DataFrame
, so if you are familiar with pandas.DataFrame
, you are already ready to use stock-pandas
import pandas as pd
stock = StockDataFrame(pd.read_csv('stock.csv'))
As we know, we could use []
, which called pandas indexing (a.k.a. __getitem__
in python) to select out lower-dimensional slices. In addition to indexing with colname
(column name of the DataFrame
), we could also do indexing by directive
s.
stock[directive]
stock[[directive0, directive1]]
We have an example to show the most basic indexing using [directive]
stock = StockDataFrame({
'open' : ...,
'high' : ...,
'low' : ...,
'close': [5, 6, 7, 8, 9]
})
stock['sma:2']
# 0 NaN
# 3 5.5
# 4 6.5
# 5 7.5
# 0 8.5
# Name: sma:2,close, dtype: float64
Which prints the 2-period simple moving average on close column
stock.calc(directive: str, create_column: bool=False) -> Series
Calculates series according to the directive.
stock['sma:2']
# is equivalent to:
stock.calc('sma:2', create_column=True)
# This will only calculate without creating a new column in the dataframe
stock.calc('sma:20')
stock.alias(alias: str, name: str) -> None
Defines column alias or directive alias
- alias
str
the alias name - name
str
the name of an existing column or the directive string
# Some plot library such as `mplfinance` which
# requires a column named capitalized `Open`,
# So we could create an alias
stock.alias('Open', 'open')
stock.alias('buy_point', 'kdj.j < 0')
Syntax of directive
column_name := command_name | command_name operator expression
operator := '/' | '\' | '<' | '<=' | '==' | '>=' | '>' | '><'
expression := float | command_name
command_name := indicator | indicator : arguments
indicator := alphabets | alphabets.alphabets
arguments := string | arguments , string
directive
Example
Here lists several use cases of column names
# The 20-day(default) moving average
# which is the mid band of bollinger bands
stock['boll']
# kdjj less than 0
stock['kdj.j < 0']
# 9-day kdjk cross up 3-day kdjd
stock['kdj.k:9 / kdj.d:3']
# 5-day simple moving average
stock['sma:5']
# 10-day simple moving average on open prices
stock['sma:10,open']
Built-in Commands
sma
, simple moving averages
macd
# macd
stock['macd']
stock['macd.dif']
# macd signal band, which is a shortcut for stock['macd.signal']
stock['macd.s']
stock['macd.signal']
stock['macd.dea']
# macd histogram band, which is equivalent to stock['macd.h']
stock['macd.histogram']
stock['macd.h']
stock['macd.macd']
boll
, bollinger bands
# boll
stock['boll']
# bollinger upper band, a shortcut for stock['boll.upper']
stock['boll.u']
stock['boll.upper]
# bollinger lower band, which is equivalent to stock['boll.l']
stock['boll.lower']
stock['boll.l']
Operators
/
:\
:<
:<=
:==
:>=
:>
:><
:
Advanced Sections
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for stock_pandas-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64d07633bd0e7ad036bbb863e22b059e2fe00bbfdfe5ca71d76193640beb2244 |
|
MD5 | 745cf535fbbb448b1192a7ced6e0018a |
|
BLAKE2b-256 | f1c78c9ab299b0fd8bb6f1a2d86665e193db373f6e27c83e54c505f3163e8c24 |