安装指令如下:

pip install stockstats
conda install -c conda-forge ta-lib

能够在mbalib 网站上查询各个政策的意义。例如:
wiki.mbalib.com/wik变量的指针其意义是指该变量的i/三app下载重指数滑润…

缩写 描绘变量泵
K KDJ中的K值
D KDJ中的D值
J KDJ中的J值
MACD 异同移动均匀线
MOM 动量线
BIAS 乖离率
CMO 钱德动量摇晃政策
TRIX 变量与函数重指数滑润均匀线
OBV 能量潮
ROC 变化率政策
AMA 移动均匀平行线差政策
VR 成交量变异率
PSY 心理线政策
Force Index 强力指数政策
DapplicationPO 区间轰动线
VHF 十字过滤线政策
RVI 相对生机指数

完结

先导入几个包,除了talib变量的指针其意义是指该变量的、numpy和pandas以外还有stockstats、pandas_talib

import pandas as pd
import numpy as np
import talib
import stoc变量是什么意思kstats
import pandas_talib
'''
这里虽然没有界说df这个变量,但这很明显就是dateframe格局的某只股票基础数据
包含开盘价、收盘价、最高价、最低价和成交量
主张用tushare来获取数据(当然仅限日数据)
'''
stockStat = stockstats.StockDataFrame.retype(df)
close = df.close
highPrice = df.high
lowPrice = df.low
volume = df.volume

然后把一些人家库现已完结好的政策放出来

df.rename(columns={'clo变量名的命名规矩se': 'Close', 'volume': 'Volume'}, inplace=True)application
sig_k , sig_d  = talib.STOCH(np.array(highPrice), np.array(lowPrice),
np.array(close), fastk_period=9,slowk_period=3,
slowk_matype=0, slowd_perapplicationiod=3, slowd_matype=0)
sig_j = sig_k * 3 - sig_d  * 2
sig = pd.concat([sig_k, sig_d, sig_j], axis=1, keyappointments=['K', 'D', 'J'])
sig['MACD']变量名, MACDsignappreciateal, MACDhist = talibapple.MACD(np.array(close), fastperiod=application6,
slowperiod=12, signalperiod=9)
sig['MOM'] = talib.MOM(np.array(clo变量之间的联系se), timeperiod=5)
s变量泵ig['CMAPPO'] = talib.CMO(close, timeperiod=10)
sig['TRIapplicationX'] = tal变量值ib.TRIX(close, timeperiod=14)
sig['OBV'] = talib.OBV(close, voappstorelume)
sig['ROC'] = talib.ROC(close, timeperio变量类型有哪些d=apple10)
sig['VR'] = stockStat['vr']
sig['Force_Index'] = pandas_t变量值alib.FORCE(df, 12)['Force_12']变量的指针其意义是指该变量的

BIAS

def BIAS(close, timeperiod=20):
if isinstancapp是什么意思e(close,np.ndarray):
pass
else:
close = np.array(close)
MA = talib.MA(close,time变量是什么意思period=timeperiod)
return (close-MA)/MA

AMA

def AMA(stockSt变量值atapplication):
retapplicationurn talib.MA(stockStatapproach['dma'],  timeperiod=10)

PSY


def PSY(priceData, period):
difference =app下载 priceDa变量与函数ta[1:] - priceDa变量名的命名规矩ta[:-1]
difference = np.append(0, difference)
difapplicationference_dir = np.where变量的界说(difference > 0, 1, 0)
psy变量 = np.zeros((len(priceData),))
psy[:period] *= np.nan
for i in range(period, len(price变量与函数Data)approach):
psy[i] = (diffeappreciaterence_di变量名的命名规矩r[i-period+1:i+1].sum()) / period
return psy*100

D变量泵PO

defDPappleO(close):
p=变量talib.MA(close,timeperiod=11)
p.shift()
re变量的界说turnclose-p

VHF

def VHF(close):
LCP = talib.MIN(close, timeperiod=28)
HCP = tali变量之间的联系b.MAX(close, timeperiod=28)
NUM = HCP - LCP
pre = close.copy()
pre = pre.shift()
DEN = abs(close-close.shift())
DEN = talib.MA(DEN, tiapp是什么意思meperiod=28)*28
return NUM.d变量值iv(DEN)
def RVI(df):
close = df.appointmentclose
open = df.open
high = df.high
low = df.low
X = cl变量之间的联系ose-ope变量之间的联系n+2*(close.shift()-open.shift())+
2*(close.shift(periods=2)-open.shift(periods=2))*(close.shift(periods=3)-
open.shift(periods=3))/6
Y = high-low+2*(applicationhigh.shift()-low.shift())+
2*(hi变量的界说gh.shift(period变量值s=2)-low.shi变量值ft(periods=2))*(h变量之间的联系igh.shift(periods=3)-
low.shift(periods=3))/6
Z = talib.MA(X, tAPPimeperiod=10)*appointment10
D = talib.MA(Y, time变量的指针其意义是指该变量的period=10)*10
return Z/D

参看博客

pypi.org/proappstoreject/sto…

anaconda.org/conda-forge…

www.geek-share.com/detail/2749…