mac安装方法如下所示:
$ brew install ta-lib
$ pip install TA-Lib
如果没用brew安装ta-lib,会报如下错误
func.c:256:28: fatal error: ta-lib/ta_libc.h: No such file or directory
compilation terminated.
If you get build errors like this, it typically means that it can't find the underlying TA-Lib library and needs to be installed:
windows、linux参考:https://mrjbq7.github.io/ta-lib/install.html
进python使用import talib
没有报错的话,表明安装成功。
import numpy as np
import talib
close = np.random.random(100)
output = talib.SMA(close) # 默认是SMA30
output = talib.SMA(close, timeperiod=5) # SMA5
inputs = {
'open': np.random.random(100),
'high': np.random.random(100),
'low': np.random.random(100),
'close': np.random.random(100),
'volume': np.random.random(100)
}
from talib.abstract import *
output = SMA(input_arrays, timeperiod=25) # 默认对close价格计算
output = SMA(input_arrays, timeperiod=25, price='open') # 对open价格计算
2. EMA:指数移动平均线(Exponential Moving Average)
talib.EMA(close)
talib.abstract.EMA(inputs)
3. MACD:平滑异同移动平均线(Moving Average Convergence / Divergence) 通过三种数据的信号(均线的组合 )可以判断趋势的力量和方向并确定趋势的转折点
talib.MACD(close)
talib.abstract.MACD(inputs)
4. 支持的指标列表
支持的功能及函数列表如下:
import talib
talib.get_functions()
print(len(talib.get_functions()))
talib.get_function_groups()
print(len(talib.get_function_groups()))
关注微信公众号查看&交流。微信公众号: 诸葛说talk
更多文章参考:量化小站