一、创建目录

在目录 /opt/ 下创建两个文件夹 softwares 和 modules,分别用于存放软件安装包和软件安装后的程序文件,命令如下:

 mkdir /opt/softwares
 mkdir /opt/modules

二、获取源码

cd /opt/softwares
wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz

三、解压缩

tar -zxvf ta-lib-0.4.0-src.tar.gz  -C /opt/modules/

四、编译安装

cd  /opt/modules/ta-lib/
# 编译安装
./configure --prefix=/usr
make && make install

如果在安装时出现这样的错误,请安装编译器先:
configure: error: no acceptable C compiler found in $PATH 错误主要是没有C编译器.

安装C编译器:

[root@localhost sipp-3.5.1]# yum -y install gcc

重新安装文件,问题解决

五、重新安装TA-Lib库

重新安装python的TA-Lib库

pip install TA-Lib

可以看到,已经安装成功了:

[root@quant ta-lib]# pip install TA-Lib
Collecting TA-Lib
  Using cached TA-Lib-0.4.19.tar.gz (267 kB)
Requirement already satisfied: numpy in /root/anaconda3/lib/python3.6/site-packages (from TA-Lib) (1.14.3)
Building wheels for collected packages: TA-Lib
  Building wheel for TA-Lib (setup.py) ... done
  Created wheel for TA-Lib: filename=TA_Lib-0.4.19-cp36-cp36m-linux_x86_64.whl size=1738915 sha256=89524f0fd25e4a6d0c123194a4ee32a8fe50457957f4df279c7372e3856dc1ec
  Stored in directory: /root/.cache/pip/wheels/56/11/d0/bd214f9bc59dae5004f8f3614139b523882c1ffa3cae90aebd
Successfully built TA-Lib
Installing collected packages: TA-Lib
Successfully installed TA-Lib-0.4.19
[root@quant ta-lib]# 

系统配置

ldconfig

六、实战

# 使用Talib库来计算
import talib

# 最高价
high_arr = np.array(kline_data['High'])

# 最低价
low_arr = np.array(kline_data['Low'])

# 收盘价
close_arr = np.array(kline_data['Close'])

atr_talib = talib.ATR(high_arr, low_arr, close_arr, timeperiod=ATR_WIN_SIZE)
print(atr_talib)
print(atr_talib[-1])

打印:

[          nan           nan           nan           nan           nan
           nan           nan           nan           nan           nan
           nan           nan           nan           nan 3366.53357143]
3366.5335714285716

Corwien
6.3k 声望1.6k 粉丝

为者常成,行者常至。