分类
联系方式
  1. 新浪微博
  2. E-mail

Stockstats

介绍

基于 pandas.DataFrame 封装出一个 StockDataFrame,包含了股票相关的统计、技术指标。

包含的技术指标如下:

指标 中文
change (in percent)
delta
permutation (zero based)
log return
max in range
min in range
middle = (close + high + low) / 3
compare: le, ge, lt, gt, eq, ne
count: both backward(c) and forward(fc)
SMA: simple moving average
EMA: exponential moving average
MSTD: moving standard deviation
MVAR: moving variance
RSV: raw stochastic value
RSI: relative strength index
KDJ: Stochastic oscillator
Bolling: including upper band and lower band.
MACD: moving average convergence divergence.

Including signal and histogram. (see note)

CR:
WR: Williams Overbought/Oversold index
CCI: Commodity Channel Index
TR: true range
ATR: average true range
line cross check, cross up or cross down.
DMA: Different of Moving Average (10, 50)
DMI: Directional Moving Index, including
  • +DI: Positive Directional Indicator
  • -DI: Negative Directional Indicator
  • ADX: Average Directional Movement Index
  • ADXR: Smoothed Moving Average of ADX
TRIX: Triple Exponential Moving Average
TEMA: Another Triple Exponential Moving Average
VR: Volatility Volume Ratio

使用方式

创建:

stock = StockDataFrame.retype(pd.read_csv('stock.csv'))

DataFrame 需要包含列名:

列名 说明 备注
open 开盘价
close 收盘价
high 最高价
low 最低价
volume 交易额 the volume of stocks traded during the interval
amount 交易量 the amount of the stocks during the interval

指标查看方式:

# 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']

# count forward(future) where close price is larger than 10
stock['close_10.0_ge_5_fc']

# 6 days RSI
stock['rsi_6']
# 12 days RSI
stock['rsi_12']

# 10 days WR
stock['wr_10']
# 6 days WR
stock['wr_6']

# CCI, default to 14 days
stock['cci']
# 20 days CCI
stock['cci_20']

# TR (true range)
stock['tr']
# ATR (Average True Range)
stock['atr']

# DMA, difference of 10 and 50 moving average
stock['dma']

# DMI
# +DI, default to 14 days
stock['pdi']
# -DI, default to 14 days
stock['mdi']
# DX, default to 14 days of +DI and -DI
stock['dx']
# ADX, 6 days SMA of DX, same as stock['dx_6_ema']
stock['adx']
# ADXR, 6 days SMA of ADX, same as stock['adx_6_ema']
stock['adxr']

# TRIX, default to 12 days
stock['trix']
    # TRIX based on the close price for a window of 3
stock['close_3_trix']
# MATRIX is the simple moving average of TRIX
stock['trix_9_sma']
# TEMA, another implementation for triple ema
stock['tema']
    # TEMA based on the close price for a window of 2
stock['close_2_tema']

# VR, default to 26 days
stock['vr']
# MAVR is the simple moving average of VR
stock['vr_6_sma']

网络资源