本文整理匯總了Python中talib.MACDEXT屬性的典型用法代碼示例。如果您正苦於以下問題:Python talib.MACDEXT屬性的具體用法?Python talib.MACDEXT怎麽用?Python talib.MACDEXT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類talib
的用法示例。
在下文中一共展示了talib.MACDEXT屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: MACDEXT
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MACDEXT [as 別名]
def MACDEXT(Series, fastperiod=12, fastmatype=0, slowperiod=26, slowmatype=0, signalperiod=9, signalmatype=0):
macd, macdsignal, macdhist = talib.MACDEXT(
Series.values, fastperiod, fastmatype, slowperiod, slowmatype, signalperiod, signalmatype)
return pd.Series(macd, index=Series.index), pd.Series(macdsignal, index=Series.index), pd.Series(macdhist, index=Series.index)
示例2: macdext
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MACDEXT [as 別名]
def macdext(candles: np.ndarray, fastperiod=12, fastmatype=0, slowperiod=26, slowmatype=0, signalperiod=9,
signalmatype=0, source_type="close", sequential=False) -> MACDEXT:
"""
MACDEXT - MACD with controllable MA type
:param candles: np.ndarray
:param fastperiod: int - default: 12
:param fastmatype: int - default: 0
:param slow_period: int - default: 26
:param slowmatype: int - default: 0
:param signal_period: int - default: 9
:param signalmatype: int - default: 0
:param source_type: str - default: "close"
:param sequential: bool - default: False
:return: MACDEXT(macd, signal, hist)
"""
if not sequential and len(candles) > 240:
candles = candles[-240:]
source = get_candle_source(candles, source_type=source_type)
macd, macdsignal, macdhist = talib.MACDEXT(source, fastperiod=fastperiod, fastmatype=fastmatype,
slowperiod=slowperiod, slowmatype=slowmatype,
signalperiod=signalperiod, signalmatype=signalmatype)
if sequential:
return MACDEXT(macd, macdsignal, macdhist)
else:
return MACDEXT(macd[-1], macdsignal[-1], macdhist[-1])
示例3: MACDEXT
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MACDEXT [as 別名]
def MACDEXT(data, **kwargs):
_check_talib_presence()
prices = _extract_series(data)
return talib.MACDEXT(prices, **kwargs)
示例4: __recountMacd
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MACDEXT [as 別名]
def __recountMacd(self):
"""
Macd計算方法:
12日EMA的計算:EMA12 = 前一日EMA12 X 11/13 + 今日收盤 X 2/13
26日EMA的計算:EMA26 = 前一日EMA26 X 25/27 + 今日收盤 X 2/27
差離值(DIF)的計算: DIF = EMA12 - EMA26,即為talib-MACD返回值macd
根據差離值計算其9日的EMA,即離差平均值,是所求的DEA值。
今日DEA = (前一日DEA X 8/10 + 今日DIF X 2/10),即為talib-MACD返回值signal
DIF與它自己的移動平均之間差距的大小一般BAR=(DIF-DEA)*2,即為MACD柱狀圖。
但是talib中MACD的計算是bar = (dif-dea)*1
"""
if self.inputMacdFastPeriodLen <= EMPTY_INT: return
if self.inputMacdSlowPeriodLen <= EMPTY_INT: return
if self.inputMacdSignalPeriodLen <= EMPTY_INT: return
maxLen = max(self.inputMacdFastPeriodLen,self.inputMacdSlowPeriodLen)+self.inputMacdSignalPeriodLen+1
#maxLen = maxLen * 3 # 注:數據長度需要足夠,才能準確。測試過,3倍長度才可以與國內的文華等軟件一致
if len(self.lineBar) < maxLen:
self.debugCtaLog(u'數據未充分,當前Bar數據數量:{0},計算MACD需要:{1}'.format(len(self.lineBar), maxLen))
return
if self.mode == self.TICK_MODE:
listClose =[x.close for x in self.lineBar[-maxLen:-1]]
else:
listClose =[x.close for x in self.lineBar[-maxLen-1:]]
dif, dea, macd = ta.MACD(np.array(listClose, dtype=float), fastperiod=self.inputMacdFastPeriodLen,
slowperiod=self.inputMacdSlowPeriodLen, signalperiod=self.inputMacdSignalPeriodLen)
#dif, dea, macd = ta.MACDEXT(np.array(listClose, dtype=float),
# fastperiod=self.inputMacdFastPeriodLen, fastmatype=1,
# slowperiod=self.inputMacdSlowPeriodLen, slowmatype=1,
# signalperiod=self.inputMacdSignalPeriodLen, signalmatype=1)
if len(self.lineDif) > maxLen:
del self.lineDif[0]
self.lineDif.append(dif[-1])
if len(self.lineDea) > maxLen:
del self.lineDea[0]
self.lineDea.append(dea[-1])
if len(self.lineMacd) > maxLen:
del self.lineMacd[0]
self.lineMacd.append(macd[-1]*2) # 國內一般是2倍
示例5: add_MACDEXT
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MACDEXT [as 別名]
def add_MACDEXT(self, fastperiod=12, fastmatype=0,
slowperiod=26, slowmatype=0,
signalperiod=9, signalmatype=0,
types=['line', 'line', 'histogram'],
colors=['primary', 'tertiary', 'fill'],
**kwargs):
"""Moving Average Convergence Divergence with Controllable MA Type.
Note that the first argument of types and colors refers to MACD,
the second argument refers to MACD signal line and the third argument
refers to MACD histogram.
"""
if not self.has_close:
raise Exception()
utils.kwargs_check(kwargs, VALID_TA_KWARGS)
if 'kind' in kwargs:
kwargs['type'] = kwargs['kind']
if 'kinds' in kwargs:
types = kwargs['type']
if 'type' in kwargs:
types = [kwargs['type']] * 3
if 'color' in kwargs:
colors = [kwargs['color']] * 3
name = 'MACDEXT({},{},{})'.format(str(fastperiod),
str(slowperiod),
str(signalperiod))
macd = name
smacd = name + '[Sign]'
hmacd = name + '[Hist]'
self.sec[macd] = dict(type=types[0], color=colors[0])
self.sec[smacd] = dict(type=types[1], color=colors[1], on=macd)
self.sec[hmacd] = dict(type=types[2], color=colors[2], on=macd)
(self.ind[macd],
self.ind[smacd],
self.ind[hmacd]) = talib.MACDEXT(self.df[self.cl].values,
fastperiod, fastmatype,
slowperiod, slowmatype,
signalperiod, signalmatype)