您可以使用 talib 和 btalib 库中内置的函数来计算许多指标。逐个指标收集所有信息会很麻烦。有没有办法立即做到这一点?如果是这样,我应该如何在 python 中继续这样做?
http://mrjbq7.github.io/ta-lib/func_groups/pattern_recognition.html
码:
def macd(prices):
print "Running MACD"
prices = np.asarray(prices)
print prices
macd, macdsignal, macdhist = MACD(prices, fastperiod=12, slowperiod=26, signalperiod=9)
print "MACD "+macd
Run Code Online (Sandbox Code Playgroud)
说明:
我正在尝试对包含收盘价的Python列表进行一些分析。
我知道在将列表交给TA-Lib之前,我必须先对其进行转换,因为我已经看到了所有示例在做的事情。
但是,这可以通过 only length-1 arrays can be converted to Python scalars
我在运行我的代码时收到此错误。主要问题是 hplot 没有正确导入。
File "MACD.py", line 10, in <module>
from bokeh.plotting import figure, show, output_file, hplot
ImportError: cannot import name hplot
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
macds = macd, macdsignal, macdhist = MACD(hloc, fastperiod=12, slowperiod=26, signalperiod=9)
macdhist_f=[]
iter=0
for x in np.nditer(macdhist):
iter+=1
macdhist_f.append([iter,float(x)])
print(type(x))
print macdhist_f
macdhist_df = pd.DataFrame(macdhist_f)
defaults.width = 450
defaults.height = 350
hist = Histogram(macdhist_df, values='macd hist', bins=50,
title="MACD Histogram")
show(hplot(hist))
coin = "DASH_"
output_file(coin + "html", title="macd")
Run Code Online (Sandbox Code Playgroud) 用以下命令安装TA-lib,
pip install TA-lib
Run Code Online (Sandbox Code Playgroud)
但得到此错误"命令'gcc'失败,退出状态为1":
检查了故障排除,安装了gcc,python-devel,libffi-devel,openssl-devel,但仍然无法正常工作!
然后使用 conda install -c quantopian ta-lib=0.4.9
安装talib但显示错误"以下规格被发现存在冲突: - py-xgboost, - ta-lib 0.4.9*"然后conda info ta-lib, it return the"NoPackagesFoundError: Package missing in current linux-64 channels"
I'm trying to install TA-Lib package in google colab notebook but without success. I tried this guide and also Installing TA-Lib on python x64
I get this error:
import platform
print (platform.architecture())
import sys
print(sys.version)
!pip install C:/ta-lib/TA_Lib-0.4.17-cp36-cp36m-win_amd64.whl
#########
('64bit', '')
3.6.3 (default, Oct 3 2017, 21:45:48)
[GCC 7.2.0]
Requirement 'C:/ta-lib/TA_Lib-0.4.17-cp36-cp36m-win_amd64.whl' looks like a
filename, but the file does not exist
TA_Lib-0.4.17-cp36-cp36m-win_amd64.whl is not a supported wheel on this
platform.
Run Code Online (Sandbox Code Playgroud) pip install talib
Collecting talib
Using cached https://files.pythonhosted.org/packages/1a/80/3492aa3065d7d81a6c51db78920108f84fbe19c4e2740f6bbb83d42f77a4/talib-0.1.1.tar.gz
Building wheels for collected packages: talib
Building wheel for talib (setup.py) ... error
ERROR: Failed building wheel for talib
Running setup.py clean for talib
Failed to build talib
Installing collected packages: talib
Running setup.py install for talib ... error
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kj3hzgy2/talib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-kj3hzgy2/talib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-utpwvbtw/install-record.txt --single-version-externally-managed --compile Check the logs for …
Run Code Online (Sandbox Code Playgroud) 我尝试在我的Mac上安装Ta-lib作为全局包时出现gcc错误.
我在下面收到错误:
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I//anaconda/include -arch x86_64 -I//anaconda/include -arch x86_64 -I//anaconda/lib/python3.6/site-packages/numpy/core/include -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I//anaconda/include/python3.6m -c talib/common.c -o build/temp.macosx-10.7-x86_64-3.6/talib/common.o
talib/common.c:242:10: fatal error: 'ta-lib/ta_defs.h' file not found
#include "ta-lib/ta_defs.h"
^
1 error generated.
error: command 'gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
我不确定我明白这意味着什么?pip install Ta-lib包丢失了一个文件?它会有意义,但它安装好我的Ubuntu服务器,只是我的Mac有问题.Ubuntu也使用相同版本的Anaconda运行Python.
我的gcc版本如下:
? ~ which gcc
/usr/bin/gcc
? ~ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Run Code Online (Sandbox Code Playgroud)
我的Python安装信息如下:
? …
Run Code Online (Sandbox Code Playgroud)