由于64位系统不能直接使用pip install ta-lib,所以直接下载轮子文件,地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib
安装完成后突然发现直接使用talib调用方法有问题,PyCharm会报错。
原代码如下:
import tushare as ts
import pandas as pd
import matplotlib.pyplot as plt
sh = ts.get_hist_data('sh')
sh = sh.sort_index()
import talib
ma = talib.MA(sh['close'].values,20) #20日均线
ma1 = pd.DataFrame(ma)
ma1.index = sh.index
sh['mma5'] = ma1
sh[['close','mma5']].plot(figsize = (15,8),grid = True)
plt.show()
import tushare as ts
import pandas as pd
import matplotlib.pyplot as plt
sh = ts.get_hist_data('sh')
sh = sh.sort_index()
# import talib
# ma = talib.MA(sh['close'].values,20) #20日均线
from talib import abstract
ma = abstract._ta_lib.MA(sh['close'].values,20) #20日均线
ma1 = pd.DataFrame(ma)
ma1.index = sh.index
sh['mma5'] = ma1
sh[['close','mma5']].plot(figsize = (15,8),grid = True)
plt.show()