安装talib库:pip install talib
1 # 取个数据验证一下 2 set_token('') 3 data = history(symbol = 'SHSE.600519',frequency = '1d',start_time = '2015-01-01',end_time = '2019-12-31', \ 4 fields = 'open, high, low, close,amount,volume,eob',df = True) 5 6 # 一、重叠研究(overlap studies) 7 # 1.简单移动平均指标SMA 8 # 参数说明:talib.SMA(a,b) 9 # a:要计算平均数的序列;b:计算平均线的周期。表示计算a的b日移动平均 10 close = data['close'].values 11 SMA = talib.SMA(close,5) 12 13 # 2.布林线BBANDS 14 # 参数说明:talib.BBANDS(close, timeperiod, matype) 15 # close:收盘价;timeperiod:周期;matype:平均方法(bolling线的middle线 = MA,用于设定哪种类型的MA) 16 # MA_Type: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TEMA, 5=TRIMA, 6=KAMA, 7=MAMA, 8=T3 (Default=SMA) 17 upper, middle, lower = talib.BBANDS(close,5,matype = talib.MA_Type.EMA) 18 19 # 3. DEMA 双移动平均线:DEMA = 2*EMA-EMA(EMA) 20 # 参数说明:talib.DEMA(close, timeperiod = 30) 21 DEMA = talib.DEMA(close, timeperiod = 30) 22 23 # 4. MA 24 # 参数说明:MA(close, timeperiod = 30, matype=0) 25 # close:收盘价;timeperiod:周期;matype:计算平均线方法 26 MA = talib.MA(close, timeperiod = 30, matype = 0) 27 28 # 5. EMA 29 # 参数说明:EMA = talib.EMA(np.array(close), timeperiod=6) 30 # close:收盘价;timeperiod:周期;matype:计算平均线方法 31 EMA = talib.EMA(np.array(close), timeperiod = 6) 32 33 # 6.KAMA:考夫曼的自适应移动平均线 34 # 参数说明:KAMA = talib.KAMA(close, timeperiod = 30) 35 KAMA = talib.KAMA(close, timeperiod = 30) 36 37 # 7. MIDPRICE:阶段中点价格 38 # talib.MIDPOINT(close, timeperiod) 39 # 参数说明:close:收盘价;timeperiod:周期; 40 MIDPOINT = talib.MIDPOINT(close, timeperiod=14) 41 42 # 8.SAR:抛物线指标 43 # SAR(high, low, acceleration=0, maximum=0) 44 # 参数说明:high:最高价;low:最低价;acceleration:加速因子;maximum:极点价 45 SAR = talib.SAR(data['high'].values, data['low'].values, acceleration=0, maximum=0) 46 47 # 9.MIDPRICE:阶段中点价格(Midpoint Price over period) 48 # talib.MIDPOINT(close, timeperiod=14) 49 # 参数说明:close:收盘价;timeperiod:周期; 50 MIDPOINT = talib.MIDPOINT(close, timeperiod=14) 51 52 # 10. T3:三重移动平均线 53 # talib.T3(close, timeperiod=5, vfactor=0) 54 # 参数说明:close:收盘价;timeperiod:周期;vfactor: va 系数,当va=0时,T3就是三重移动平均线;va=1时,就是DEMA 55 T3 = talib.T3(close, timeperiod = 5, vfactor = 0) 56 57 # 11.TEMA:三重指数移动平均线 58 # talib.TEMA(close, timeperiod = 30) 59 # 参数说明:close:收盘价;timeperiod:周期; 60 TEMA = talib.TEMA(close, timeperiod=30) 61 62 # 12.SAREXT:SAR的抛物面扩展 63 # talib.SAREXT(high_p, low_p, startvalue=0, offsetonreverse=0, accelerationinitlong=0, accelerationlong=0, accelerationmaxlong=0, accelerationinitshort=0, accelerationshort=0, accelerationmaxshort=0) 64 SAREXT = talib.SAREXT(data['high'].values, data['low'].values, startvalue=0, offsetonreverse=0, accelerationinitlong=0, accelerationlong=0, accelerationmaxlong=0, accelerationinitshort=0, accelerationshort=0, accelerationmaxshort=0) 65 66 # 13.WMA:移动加权平均法 67 # talib.WMA(close, timeperiod = 30) 68 # 参数说明:close:收盘价;timeperiod:周期; 69 WMA = talib.WMA(close, timeperiod = 30) 70 71 72 # 二、 波动量指标 73 # 1.ATR:真实波动幅度均值 74 # ATR(high, low, close, timeperiod=14) 75 # 参数说明:high:最高价;low:最低价;close:收盘价,timeperiod:周期 76 ATR = talib.ATR(data['high'].values, data['low'].values, close, timeperiod=14) 77 78 # 2.NATR:归一化波动幅度均值 79 # NATR(high, low, close, timeperiod=14) 80 # 参数说明:high:最高价;low:最低价;close:收盘价,timeperiod:周期 81 NATR = talib.NATR(data['high'].values, data['low'].values, close, timeperiod=14) 82 83 # 3.TRANGE:真正的范围 84 # TRANGE(high, low, close) 85 # 参数说明:high:最高价;low:最低价;close:收盘价 86 TRANGE = talib.TRANGE(data['high'].values, data['low'].values, close) 87 88 89 # 三、 量价指标 90 # 1. AD:量价指标 91 # AD(high, low, close, volume) 92 # 参数说明:high:最高价;low:最低价;close:收盘价,volume:成交量 93 AD = talib.AD(data['high'], data['low'], close,data['volume']) 94 95 # 2.ADOSC:震荡指标 96 # ADOSC(high, low, close, volume, fastperiod=3, slowperiod=10) 97 # 参数说明:high:最高价;low:最低价;close:收盘价,volume:成交量; fastperiod:快周期; slowperiod:慢周期 98 ADOSC = talib.ADOSC(data['high'], data['low'], close,data['volume'], fastperiod=3, slowperiod=10) 99 100 # 3.OBV:能量潮 101 # OBV(close, volume) 102 # 参数说明:close:收盘价,volume:成交量 103 OBV = talib.OBV(close, data['volume']) 104 105 # 三、 周期指标 106 # 1.HT_DCPERIOD:希尔伯特变换-主导周期 107 # HT_DCPERIOD(close) 108 # 参数说明:close:收盘价 109 HT_DCPERIOD = talib.HT_DCPERIOD(close) 110 111 # 2.HT_DCPHASE:希尔伯特变换-主导循环阶段 112 # HT_DCPHASE(close) 113 # 参数说明:close:收盘价 114 HT_DCPHASE = talib.HT_DCPHASE(close) 115 116 # 3.HT_PHASOR:希尔伯特变换-希尔伯特变换相量分量 117 # inphase, quadrature = HT_PHASOR(close) 118 # 参数说明:close:收盘价 119 HT_PHASOR_inphase,HT_PHASOR_quadrature = talib.HT_PHASOR(close) 120 121 # 4.HT_SINE:希尔伯特变换-正弦波 122 # sine, leadsine = HT_SINE(close) 123 # 参数说明:close:收盘价 124 HT_SINE_sine,HT_SINE_leadsine = talib.HT_SINE(close) 125 126 # 5.HT_TRENDMODE:希尔伯特变换-趋势与周期模式 127 # integer = HT_TRENDMODE(close) 128 # 参数说明:close:收盘价 129 HT_TRENDMODE = talib.HT_TRENDMODE(close) 130 131 132 # 四、价格变化函数 133 # 1. AVGPRICE:平均价格函数 134 # real = AVGPRICE(open, high, low, close) 135 AVGPRICE = talib.AVGPRICE(data['open'].values, data['high'].values, data['low'].values, close) 136 137 # 2. MEDPRICE:中位数价格 138 # real = MEDPRICE(high, low) 139 # 参数说明:high:最高价;low:最低价; 140 MEDPRICE = talib.MEDPRICE(data['high'].values, data['low'].values) 141 142 # 3. TYPPRICE :代表性价格 143 # real = TYPPRICE(high, low, close) 144 # 参数说明:high:最高价;low:最低价;close:收盘价 145 TYPPRICE = talib.TYPPRICE(data['high'].values, data['low'].values, close) 146 147 # 4. WCLPRICE :加权收盘价 148 # real = WCLPRICE(high, low, close) 149 # 参数说明:high:最高价;low:最低价;close:收盘价 150 WCLPRICE = talib.WCLPRICE(data['high'].values, data['low'].values, close) 151 152 # 五、 动量指标 153 # 1. ADX:平均趋向指数 154 # real = ADX(high, low, close, timeperiod=14) 155 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 156 ADX = talib.ADX(data['high'].values, data['low'].values, close, timeperiod=14) 157 158 # 2. ADXR:平均趋向指数的趋向指数 159 # real = ADXR(high, low, close, timeperiod=14) 160 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 161 ADXR = talib.ADXR(data['high'].values, data['low'].values, close, timeperiod=14) 162 163 # 3. APO :价格震荡指数 164 # real = APO(close, fastperiod=12, slowperiod=26, matype=0) 165 # 参数说明:close:收盘价;fastperiod:快周期; slowperiod:慢周期 166 APO = talib.APO(close, fastperiod=12, slowperiod=26, matype=0) 167 168 # 4. AROON :阿隆指标 169 # aroondown, aroonup = AROON(high, low, timeperiod=14) 170 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 171 AROON_aroondown,AROON_aroonup = talib.AROON(data['high'].values, data['low'].values, timeperiod=14) 172 173 # 5.AROONOSC :阿隆振荡 174 # real = AROONOSC(high, low, timeperiod=14) 175 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 176 AROONOSC = talib.AROONOSC(data['high'].values, data['low'].values, timeperiod=14) 177 178 # 6. BOP :均势指标 179 # real = BOP(open, high, low, close) 180 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 181 BOP= talib.BOP(data['open'].values, data['high'].values, data['low'].values, close) 182 183 # 7. CCI :顺势指标 184 # real = CCI(high, low, close, timeperiod=14) 185 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 186 CCI = talib.CCI(data['high'].values, data['low'].values,close, timeperiod=14) 187 188 # 8. CMO :钱德动量摆动指标 189 # real = CMO(close, timeperiod=14) 190 # 参数说明:close:收盘价;timeperiod:时间周期 191 CMO = talib.CMO(close, timeperiod=14) 192 193 # 9. DX :动向指标或趋向指标 194 # real = DX(high, low, close, timeperiod=14) 195 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 196 DX = talib.DX(data['high'].values, data['low'].values, close, timeperiod=14) 197 198 # 10. MACD:平滑异同移动平均线 199 # macd, macdsignal, macdhist = MACD(close, fastperiod=12, slowperiod=26, signalperiod=9) 200 # 参数说明:high:最高价;low:最低价;close:收盘价;fastperiod:快周期; slowperiod:慢周期 201 MACD_macd,MACD_macdsignal,MACD_macdhist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9) 202 203 # 11. MACDEXT :MACD延伸 204 # macd, macdsignal, macdhist = MACDEXT(close, fastperiod=12, fastmatype=0, slowperiod=26, slowmatype=0, signalperiod=9, signalmatype=0) 205 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 206 MACDEXT_macd,MACDEXT_macdsignal,MACDEXT_macdhist = talib.MACDEXT(close, fastperiod=12, fastmatype=0, slowperiod=26, slowmatype=0, signalperiod=9, signalmatype=0) 207 208 # 12. MFI :资金流量指标 209 # real = MFI(high, low, close, volume, timeperiod=14) 210 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 211 MFI = talib.MFI(data['high'].values, data['low'].values, close, data['volume'], timeperiod=14) 212 213 # 13. MINUS_DI:DMI 中的DI指标 负方向指标 214 # real = MINUS_DI(high, low, close, timeperiod=14) 215 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 216 MINUS_DI = talib.MINUS_DI(data['high'].values, data['low'].values, close, timeperiod=14) 217 218 # 14. MINUS_DM:上升动向值 219 # real = MINUS_DM(high, low, timeperiod=14) 220 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 221 MINUS_DM = talib.MINUS_DM(data['high'].values, data['low'].values, timeperiod=14) 222 223 224 # 六、波动率指标 225 # 1.MOM: 上升动向值 226 # real = MOM(close, timeperiod=10) 227 # 参数说明:close:收盘价;timeperiod:时间周期 228 MOM = talib.MOM(close, timeperiod=10) 229 230 # 2.PLUS_DI 231 # real = PLUS_DI(high, low, close, timeperiod=14) 232 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 233 PLUS_DI = talib.PLUS_DI(data['high'].values, data['low'].values, close, timeperiod=14) 234 235 # 3.PLUS_DM 236 # real = PLUS_DM(high, low, timeperiod=14) 237 # 参数说明:high:最高价;low:最低价;close:收盘价;timeperiod:时间周期 238 PLUS_DM = talib.PLUS_DM(data['high'].values, data['low'].values, timeperiod=14) 239 240 # 4. PPO: 价格震荡百分比指数 241 # real = PPO(close, fastperiod=12, slowperiod=26, matype=0) 242 # 参数说明:close:收盘价;timeperiod:时间周期,fastperiod:快周期; slowperiod:慢周期 243 PPO = talib.PPO(close, fastperiod=12, slowperiod=26, matype=0) 244 245 # 5.ROC:变动率指标 246 # real = ROC(close, timeperiod=10) 247 # 参数说明:close:收盘价;timeperiod:时间周期 248 ROC = talib.ROC(close, timeperiod=10) 249 250 # 6. ROCP:变动百分比 251 # real = ROCP(close, timeperiod=10) 252 # 参数说明:close:收盘价;timeperiod:时间周期 253 ROCP = talib.ROCP(close, timeperiod=10) 254 255 # 7.ROCR :变动百分率 256 # real = ROCR(close, timeperiod=10) 257 # 参数说明:close:收盘价;timeperiod:时间周期 258 ROCR = talib.ROCR(close, timeperiod=10) 259 260 # 8. ROCR100 :变动百分率(*100) 261 # real = ROCR100(close, timeperiod=10) 262 # 参数说明:close:收盘价;timeperiod:时间周期 263 ROCR100 = talib.ROCR100(close, timeperiod=10) 264 265 # 9. RSI:相对强弱指数 266 # real = RSI(close, timeperiod=14) 267 # 参数说明:close:收盘价;timeperiod:时间周期 268 RSI = talib.RSI(close, timeperiod=14) 269 270 # 10.STOCH :随机指标,俗称KD 271 # slowk, slowd = STOCH(high, low, close, fastk_period=5, slowk_period=3, slowk_matype=0, slowd_period=3, slowd_matype=0) 272 # 参数说明:high:最高价;low:最低价;close:收盘价;fastk_period:N参数, slowk_period:M1参数, slowk_matype:M1类型, slowd_period:M2参数, slowd_matype:M2类型 273 # #matype: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TEMA, 5=TRIMA, 6=KAMA, 7=MAMA, 8=T3 (Default=SMA) 274 STOCH_slowk,STOCH_slowd = talib.STOCH(data['high'].values, data['low'].values, close, fastk_period=9, slowk_period=3, slowk_matype=1, slowd_period=3, slowd_matype=1) 275 276 # 11. STOCHF :快速随机指标 277 # fastk, fastd = STOCHF(high, low, close, fastk_period=5, fastd_period=3, fastd_matype=0) 278 STOCHF_fastk,STOCHF_fastd = talib.STOCHF(data['high'].values, data['low'].values, close, fastk_period=5, fastd_period=3, fastd_matype=0) 279 280 # 12.STOCHRSI:随机相对强弱指数 281 # fastk, fastd = STOCHRSI(high, low, close, timeperiod=14, fastk_period=5, fastd_period=3, fastd_matype=0) 282 STOCHRSI_fastk,STOCHRSI_fastd = talib.STOCHF(data['high'].values, data['low'].values, close, fastk_period = 5, fastd_period = 3, fastd_matype = 0) 283 284 # 13.TRIX:1-day Rate-Of-Change (ROC) of a Triple Smooth EMA 285 # real = TRIX(close, timeperiod=30) 286 TRIX = talib.TRIX(close, timeperiod=30) 287 288 # 14.ULTOSC:终极波动指标 289 # real = ULTOSC(high, low, close, timeperiod1=7, timeperiod2=14, timeperiod3=28) 290 ULTOSC = talib.ULTOSC(data['high'].values, data['low'].values, close, timeperiod1=7, timeperiod2=14, timeperiod3=28) 291 292 # 15.WILLR :威廉指标 293 # real = WILLR(high, low, close, timeperiod=14) 294 WILLR = talib.WILLR(data['high'].values, data['low'].values, close, timeperiod = 14) 295 296 297 # 七、Statistic Functions 统计学指标 298 # 1. BETA:β系数也称为贝塔系数 299 # real = BETA(high, low, timeperiod=5) 300 BETA = talib.BETA(data['high'].values, data['low'].values, timeperiod = 5) 301 302 # 2. CORREL :皮尔逊相关系数 303 # real = CORREL(high, low, timeperiod=30) 304 CORREL = talib.CORREL(data['high'].values, data['low'].values, timeperiod = 30) 305 306 # 3.LINEARREG :线性回归 307 # real = LINEARREG(close, timeperiod=14) 308 LINEARREG = talib.LINEARREG(close, timeperiod=14) 309 310 # 4.LINEARREG_ANGLE :线性回归的角度 311 # real = LINEARREG_ANGLE(close, timeperiod=14) 312 LINEARREG_ANGLE = talib.LINEARREG_ANGLE(close, timeperiod=14) 313 314 # 5. LINEARREG_INTERCEPT :线性回归截距 315 # real = LINEARREG_INTERCEPT(close, timeperiod=14) 316 LINEARREG_INTERCEPT = talib.LINEARREG_INTERCEPT(close, timeperiod=14) 317 318 # 6.LINEARREG_SLOPE:线性回归斜率指标 319 # real = LINEARREG_SLOPE(close, timeperiod=14) 320 LINEARREG_SLOPE = talib.LINEARREG_SLOPE(close, timeperiod=14) 321 322 # 7.STDDEV :标准偏差 323 # real = STDDEV(close, timeperiod=5, nbdev=1) 324 STDDEV = talib.STDDEV(close, timeperiod=5, nbdev=1) 325 326 # 8.TSF:时间序列预测 327 # real = TSF(close, timeperiod=14) 328 TSF = talib.TSF(close, timeperiod=14) 329 330 # 9. VAR:方差 331 # real = VAR(close, timeperiod=5, nbdev=1) 332 VAR = talib.VAR(close, timeperiod=5, nbdev=1)
标签:python,talib,high,一览表,low,close,timeperiod,data From: https://www.cnblogs.com/long136/p/16888771.html