2

我对结果感到困惑。

对我来说,似乎有多个版本的 MACD 计算。

如果不是,为什么它们不同?

print(p_df.head())
                 c
timestamp         
2017-04-19  2852.0
2017-04-20  2889.0
2017-04-21  2928.0
2017-04-24  2928.0
2017-04-25  2949.0

p_arr = np.array(p)

from pandas_talib import pandas_talib as pdta

macd1 = pdta.MACD( p_df, 12, 26, price='c' )

print( macd1.tail( 10 ) )
                 c  MACD_12_26  MACDsign_12_26  MACDdiff_12_26
timestamp                                                     
2017-10-17  3738.0  -27.479893      -44.220449       16.740556
2017-10-18  3688.0  -27.154199      -40.807199       13.653000
2017-10-19  3604.0  -33.289945      -39.303748        6.013803
2017-10-20  3776.0  -23.997889      -36.242576       12.244687
2017-10-23  3699.0  -22.586382      -33.511337       10.924955
2017-10-24  3740.0  -17.952636      -30.399597       12.446961
2017-10-25  3705.0  -16.909496      -27.701577       10.792081
2017-10-26  3649.0  -20.366536      -26.234569        5.868032
2017-10-27  3577.0  -28.586273      -26.704910       -1.881363
2017-10-30  3571.0  -35.179075      -28.399743       -6.779332

import talib

macd2 = np.vstack( talib.MACD( p_arr, 12, 26, 9 ) )

macd2 = pd.DataFrame( macd2.T,
                      index   = p_df.index,
                      columns = ['macd','macdsignal','macdhist']
                      )
macd2 = p_df.join( macd2 )
print( macd2.tail( 10 ) )
                 c       macd  macdsignal   macdhist
timestamp                                           
2017-10-17  3738.0 -27.384079  -44.076077  16.691997
2017-10-18  3688.0 -27.065785  -40.674018  13.608233
2017-10-19  3604.0 -33.208822  -39.180979   5.972157
2017-10-20  3776.0 -23.922497  -36.129283  12.206786
2017-10-23  3699.0 -22.516715  -33.406769  10.890054
2017-10-24  3740.0 -17.888063  -30.303028  12.414965
2017-10-25  3705.0 -16.849797  -27.612382  10.762585
2017-10-26  3649.0 -20.311556  -26.152217   5.840661
2017-10-27  3577.0 -28.535880  -26.628949  -1.906930
2017-10-30  3571.0 -35.132875  -28.329735  -6.803141

比较图 在此处输入图像描述 我的 TA-Lib 是从 TA_Lib‑0.4.10‑cp36‑cp36m‑win_amd64.whl
( https://www.lfd.uci.edu/~gohlke/pythonlibs/ ) 安装的。

Name:         TA-Lib
Version:      0.4.10
Summary:      Python wrapper for TA-Lib
Home-page:    http://github.com/mrjbq7/ta-lib
Author:       John Benediktsson
Author-email: mrjbq7@gmail.com
License:      UNKNOWN
Location:     c:\users\trader\anaconda3\envs\py36\lib\site-packages
Requires:
4

0 回答 0