Skip to main content

Used as an indicator to study the trend of the stock market.

Project description

技术指标

这是一个基于事件驱动设计模式的技术指标算法,可用股市预测行情趋势。

目前已实现MACD,KDJ,MA,RSI等重要指标。为了便捷的使用,简单封装成该接口,以便需要的人使用。

环境要求:

pyhon

pandas

doctest

tushare

调用方式

1:数据源要求:

数据结构:pandas.Dataframe

参数: ['date', 'open', 'high', 'low', 'close']

示例:

       date   open   high    low  close
0  20191106  33.80  34.15  33.33  33.46
1  20191105  33.95  34.13  33.45  33.81
2  20191104  33.69  34.45  33.48  33.85
3  20191101  33.36  33.64  33.11  33.50
4  20191031  33.72  34.20  33.37  33.42
5  20191030  34.34  34.34  33.52  33.78
6  20191029  35.25  35.25  34.33  34.34
7  20191028  35.30  35.50  34.44  35.35
8  20191025  34.08  34.11  33.59  34.00
9  20191024  33.93  34.14  33.35  33.84

调用代码:

from thctools import Technical
thc_obj = Technical(df)
thc_obj.ma
thc_obj.macd
thc_obj.kdj

测试案例:

from thctools import Technical
ts.set_token('24c7a5d5b40cd5db779cbc888ba4516d4be3384c0cf897caeaf2415b')
pro = ts.pro_api()
df = pro.query('daily', ts_code='603019.SH')
df = df.rename(columns={'trade_date': 'date'})[['date', 'open', 'high', 'low', 'close']]
print(df.head(10))
tech_obj = Technical(df)
print(tech_obj.ma.head(10))
print(tech_obj.macd.head(10))
print(tech_obj.kdj.head(10))

结果:

ma:

     MA10  MA20     MA5  MA60      date
0   0.000   0.0   0.000   0.0  20141106
1   0.000   0.0   0.000   0.0  20141107
2   0.000   0.0   0.000   0.0  20141110
3   0.000   0.0   0.000   0.0  20141111
4   0.000   0.0   9.302   0.0  20141112
5   0.000   0.0  10.232   0.0  20141113
6   0.000   0.0  11.256   0.0  20141114
7   0.000   0.0  12.382   0.0  20141117
8   0.000   0.0  13.622   0.0  20141118
9  12.144   0.0  14.986   0.0  20141119

macd

     DEA    DIF   EMA12   EMA26   MACD      date
0  0.000  0.000   7.620   7.620  0.000  20141106
1  0.012  0.061   7.737   7.676  0.098  20141107
2  0.045  0.174   7.965   7.791  0.258  20141110
3  0.103  0.335   8.300   7.965  0.464  20141111
4  0.190  0.537   8.738   8.201  0.694  20141112
5  0.308  0.780   9.282   8.502  0.944  20141113
6  0.458  1.059   9.931   8.872  1.202  20141114
7  0.641  1.372  10.687   9.315  1.462  20141117
8  0.857  1.722  11.557   9.835  1.730  20141118
9  1.107  2.106  12.544  10.438  1.998  20141119

kdj

        D        J       K    RSV      date
0   0.000    0.000   0.000    0.0  20141106
1   0.000    0.000   0.000    0.0  20141107
2   0.000    0.000   0.000    0.0  20141110
3   0.000    0.000   0.000    0.0  20141111
4   0.000    0.000   0.000    0.0  20141112
5   0.000    0.000   0.000    0.0  20141113
6   0.000    0.000   0.000    0.0  20141114
7   0.000    0.000   0.000    0.0  20141117
8  55.556   88.889  66.667  100.0  20141118
9  62.963  107.408  77.778  100.0  20141119

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thctools-1.0.3.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

thctools-1.0.3-py3-none-any.whl (14.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page