mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-06-27 16:10:07 +08:00
62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
from .ema import ema
|
|
from ..utils import get_offset, verify_series
|
|
|
|
|
|
def tema(close, length=None, offset=None, **kwargs):
|
|
"""Indicator: Triple Exponential Moving Average (TEMA)"""
|
|
# Validate Arguments
|
|
close = verify_series(close)
|
|
length = int(length) if length and length > 0 else 10
|
|
min_periods = (int(kwargs["min_periods"]) if "min_periods" in kwargs and
|
|
kwargs["min_periods"] is not None else length)
|
|
offset = get_offset(offset)
|
|
|
|
# Calculate Result
|
|
ema1 = ema(close=close, length=length, **kwargs)
|
|
ema2 = ema(close=ema1, length=length, **kwargs)
|
|
ema3 = ema(close=ema2, length=length, **kwargs)
|
|
tema = 3 * (ema1 - ema2) + ema3
|
|
|
|
# Offset
|
|
if offset != 0:
|
|
tema = tema.shift(offset)
|
|
|
|
# Name & Category
|
|
tema.name = f"TEMA_{length}"
|
|
tema.category = "overlap"
|
|
|
|
return tema
|
|
|
|
|
|
tema.__doc__ = """Triple Exponential Moving Average (TEMA)
|
|
|
|
A less laggy Exponential Moving Average.
|
|
|
|
Sources:
|
|
https://www.tradingtechnologies.com/help/x-study/technical-indicator-definitions/triple-exponential-moving-average-tema/
|
|
|
|
Calculation:
|
|
Default Inputs:
|
|
length=10
|
|
EMA = Exponential Moving Average
|
|
ema1 = EMA(close, length)
|
|
ema2 = EMA(ema1, length)
|
|
ema3 = EMA(ema2, length)
|
|
TEMA = 3 * (ema1 - ema2) + ema3
|
|
|
|
Args:
|
|
close (pd.Series): Series of 'close's
|
|
length (int): It's period. Default: 10
|
|
offset (int): How many periods to offset the result. Default: 0
|
|
|
|
Kwargs:
|
|
adjust (bool): Default: True
|
|
presma (bool, optional): If True, uses SMA for initial value.
|
|
fillna (value, optional): pd.DataFrame.fillna(value)
|
|
fill_method (value, optional): Type of fill method
|
|
|
|
Returns:
|
|
pd.Series: New feature generated.
|
|
"""
|