TA-Lib

简介:

Talib一直缺乏有效的中文文档,自己又有空闲时间,且在研究量化对冲系统,就发点时间,做一下翻译。
原文地址: TA-LIB document
翻译地址:

这是一个Python 金融指数处理库TA-LIB,他是基于 Cython
而不是 SWIG。

TA-Lib is widely used by trading software developers requiring to perform
technical analysis of financial market data.
TA-Lib广泛应用与交易软件,和金融市场数据进行技术分析。

  • Includes 150+ indicators such as ADX, MACD, RSI, Stochastic, Bollinger
    Bands, etc.
  • Candlestick pattern recognition
  • Open-source API for C/C++, Java, Perl, Python and 100% Managed .NET
  • 包含了150多个指标,包括:ADX, MACD, RSI, Stochastic, Bollinger Bands, 等.
  • K线形态识别
  • 完全开源,支持 C/C++, Java, Perl, Python and 100% Managed .NET

安装TA-Lib

案例(快速开始)

Similar to TA-Lib, the function interface provides a lightweight wrapper of
the exposed TA-Lib indicators.
类似于TA-Lib,函数接口提供了一个暴漏TA-Lib指标的轻量级封装。

Each function returns an output array and have default values for their
parameters, unless specified as keyword arguments. Typically, these functions
will have an initial “lookback” period (a required number of observations
before an output is generated) set to NaN.
每个函数都默认需要输入数组,并为它们提供默认值。
参数,除非指定为关键字参数。通常,这些函数
会有一个初步的“lookback”时期(观测所需数量
在生成一个输出之前),设置为“NaN”。

All of the following examples use the function API:
所有的API函数的使用,都需引入库文件:

  1. import numpy
  2. import talib
  3. close = numpy.random.random(100)

计算收盘价的一个简单移动平均数SMA:

  1. output = talib.SMA(close)

计算布林线,三指数移动平均:

  1. from talib import MA_Type
  2. upper, middle, lower = talib.BBANDS(close, matype=MA_Type.T3)

计算收盘价的动量,时间为5:

  1. output = talib.MOM(close, timeperiod=5)

Abstract API Quick Start 抽象 API 快速入门

If you’re already familiar with using the function API, you should feel right
at home using the abstract API. Every function takes the same input, passed
as a dictionary of Numpy arrays:
如果您已经熟悉使用函数API,那么您就应该精通使用抽象API。
每个函数有相同的输入,作为一个字典通过NumPy数组:

  1. import numpy as np
  2. # note that all ndarrays must be the same length!
  3. inputs = {
  4. 'open': np.random.random(100),
  5. 'high': np.random.random(100),
  6. 'low': np.random.random(100),
  7. 'close': np.random.random(100),
  8. 'volume': np.random.random(100)
  9. }

函数可以直接导入,也可以用名称实例化:

  1. from talib import abstract
  2. sma = abstract.SMA
  3. sma = abstract.Function('sma')

调用函数基本上与函数API相同:

  1. from talib.abstract import *
  2. output = SMA(input_arrays, timeperiod=25) # SMA均线价格计算收盘价
  3. output = SMA(input_arrays, timeperiod=25, price='open') # SMA均线价格计算收盘价
  4. upper, middle, lower = BBANDS(input_arrays, 20, 2, 2)
  5. slowk, slowd = STOCH(input_arrays, 5, 3, 0, 3, 0) # uses high, low, close by default
  6. slowk, slowd = STOCH(input_arrays, 5, 3, 0, 3, 0, prices=['high', 'low', 'open'])

了解更多高级使用TA库 here.

Supported Indicators 支持的指标

We can show all the TA functions supported by TA-Lib, either as a list or
as a dict sorted by group (e.g. “Overlap Studies”, “Momentum Indicators”,
etc):
我们可以显示Ta lib的所有TA函数,返回一个 list 或者 dict

  1. import talib
  2. print talib.get_functions()
  3. print talib.get_function_groups()

Function Groups

Overlap Studies

  1. BBANDS Bollinger Bands #布林带
  2. DEMA Double Exponential Moving Average #双指数移动平均线
  3. EMA Exponential Moving Average #指数滑动平均
  4. HT_TRENDLINE Hilbert Transform - Instantaneous Trendline #希尔伯特变换瞬时趋势
  5. KAMA Kaufman Adaptive Moving Average #卡玛考夫曼自适应移动平均
  6. MA Moving average #均线
  7. MAMA MESA Adaptive Moving Average #自适应移动平均
  8. MAVP Moving average with variable period #变周期移动平均
  9. MIDPOINT MidPoint over period #在周期的中点
  10. MIDPRICE Midpoint Price over period #中间时段价格
  11. SAR Parabolic SAR #抛物线转向指标
  12. SAREXT Parabolic SAR - Extended #抛物线转向指标 - 扩展
  13. SMA Simple Moving Average# 简单移动平均线
  14. T3 Triple Exponential Moving Average (T3)
  15. TEMA Triple Exponential Moving Average
  16. TRIMA Triangular Moving Average
  17. WMA Weighted Moving Average#加权移动平均线

Momentum Indicators

  1. ADX Average Directional Movement Index
  2. ADXR Average Directional Movement Index Rating
  3. APO Absolute Price Oscillator
  4. AROON Aroon
  5. AROONOSC Aroon Oscillator
  6. BOP Balance Of Power
  7. CCI Commodity Channel Index
  8. CMO Chande Momentum Oscillator
  9. DX Directional Movement Index
  10. MACD Moving Average Convergence/Divergence
  11. MACDEXT MACD with controllable MA type
  12. MACDFIX Moving Average Convergence/Divergence Fix 12/26
  13. MFI Money Flow Index
  14. MINUS_DI Minus Directional Indicator
  15. MINUS_DM Minus Directional Movement
  16. MOM Momentum
  17. PLUS_DI Plus Directional Indicator
  18. PLUS_DM Plus Directional Movement
  19. PPO Percentage Price Oscillator
  20. ROC Rate of change : ((price/prevPrice)-1)*100
  21. ROCP Rate of change Percentage: (price-prevPrice)/prevPrice
  22. ROCR Rate of change ratio: (price/prevPrice)
  23. ROCR100 Rate of change ratio 100 scale: (price/prevPrice)*100
  24. RSI Relative Strength Index
  25. STOCH Stochastic
  26. STOCHF Stochastic Fast
  27. STOCHRSI Stochastic Relative Strength Index
  28. TRIX 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA
  29. ULTOSC Ultimate Oscillator
  30. WILLR Williams' %R

Volume Indicators

  1. AD Chaikin A/D Line
  2. ADOSC Chaikin A/D Oscillator
  3. OBV On Balance Volume

Volatility Indicators

  1. ATR Average True Range
  2. NATR Normalized Average True Range
  3. TRANGE True Range

Price Transform

  1. AVGPRICE Average Price
  2. MEDPRICE Median Price
  3. TYPPRICE Typical Price
  4. WCLPRICE Weighted Close Price

Cycle Indicators

  1. HT_DCPERIOD Hilbert Transform - Dominant Cycle Period
  2. HT_DCPHASE Hilbert Transform - Dominant Cycle Phase
  3. HT_PHASOR Hilbert Transform - Phasor Components
  4. HT_SINE Hilbert Transform - SineWave
  5. HT_TRENDMODE Hilbert Transform - Trend vs Cycle Mode

Pattern Recognition

  1. CDL2CROWS Two Crows
  2. CDL3BLACKCROWS Three Black Crows
  3. CDL3INSIDE Three Inside Up/Down
  4. CDL3LINESTRIKE Three-Line Strike
  5. CDL3OUTSIDE Three Outside Up/Down
  6. CDL3STARSINSOUTH Three Stars In The South
  7. CDL3WHITESOLDIERS Three Advancing White Soldiers
  8. CDLABANDONEDBABY Abandoned Baby
  9. CDLADVANCEBLOCK Advance Block
  10. CDLBELTHOLD Belt-hold
  11. CDLBREAKAWAY Breakaway
  12. CDLCLOSINGMARUBOZU Closing Marubozu
  13. CDLCONCEALBABYSWALL Concealing Baby Swallow
  14. CDLCOUNTERATTACK Counterattack
  15. CDLDARKCLOUDCOVER Dark Cloud Cover
  16. CDLDOJI Doji
  17. CDLDOJISTAR Doji Star
  18. CDLDRAGONFLYDOJI Dragonfly Doji
  19. CDLENGULFING Engulfing Pattern
  20. CDLEVENINGDOJISTAR Evening Doji Star
  21. CDLEVENINGSTAR Evening Star
  22. CDLGAPSIDESIDEWHITE Up/Down-gap side-by-side white lines
  23. CDLGRAVESTONEDOJI Gravestone Doji
  24. CDLHAMMER Hammer
  25. CDLHANGINGMAN Hanging Man
  26. CDLHARAMI Harami Pattern
  27. CDLHARAMICROSS Harami Cross Pattern
  28. CDLHIGHWAVE High-Wave Candle
  29. CDLHIKKAKE Hikkake Pattern
  30. CDLHIKKAKEMOD Modified Hikkake Pattern
  31. CDLHOMINGPIGEON Homing Pigeon
  32. CDLIDENTICAL3CROWS Identical Three Crows
  33. CDLINNECK In-Neck Pattern
  34. CDLINVERTEDHAMMER Inverted Hammer
  35. CDLKICKING Kicking
  36. CDLKICKINGBYLENGTH Kicking - bull/bear determined by the longer marubozu
  37. CDLLADDERBOTTOM Ladder Bottom
  38. CDLLONGLEGGEDDOJI Long Legged Doji
  39. CDLLONGLINE Long Line Candle
  40. CDLMARUBOZU Marubozu
  41. CDLMATCHINGLOW Matching Low
  42. CDLMATHOLD Mat Hold
  43. CDLMORNINGDOJISTAR Morning Doji Star
  44. CDLMORNINGSTAR Morning Star
  45. CDLONNECK On-Neck Pattern
  46. CDLPIERCING Piercing Pattern
  47. CDLRICKSHAWMAN Rickshaw Man
  48. CDLRISEFALL3METHODS Rising/Falling Three Methods
  49. CDLSEPARATINGLINES Separating Lines
  50. CDLSHOOTINGSTAR Shooting Star
  51. CDLSHORTLINE Short Line Candle
  52. CDLSPINNINGTOP Spinning Top
  53. CDLSTALLEDPATTERN Stalled Pattern
  54. CDLSTICKSANDWICH Stick Sandwich
  55. CDLTAKURI Takuri (Dragonfly Doji with very long lower shadow)
  56. CDLTASUKIGAP Tasuki Gap
  57. CDLTHRUSTING Thrusting Pattern
  58. CDLTRISTAR Tristar Pattern
  59. CDLUNIQUE3RIVER Unique 3 River
  60. CDLUPSIDEGAP2CROWS Upside Gap Two Crows
  61. CDLXSIDEGAP3METHODS Upside/Downside Gap Three Methods

Statistic Functions

  1. BETA Beta
  2. CORREL Pearson's Correlation Coefficient (r)
  3. LINEARREG Linear Regression
  4. LINEARREG_ANGLE Linear Regression Angle
  5. LINEARREG_INTERCEPT Linear Regression Intercept
  6. LINEARREG_SLOPE Linear Regression Slope
  7. STDDEV Standard Deviation
  8. TSF Time Series Forecast
  9. VAR Variance

我想成为一名依靠乞讨的程序员。

164938069.png