Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into pr_issue_700
Browse files Browse the repository at this point in the history
  • Loading branch information
luisbarrancos committed Oct 13, 2023
2 parents 760dcd4 + 934ece7 commit e853cef
Show file tree
Hide file tree
Showing 54 changed files with 464 additions and 156 deletions.
9 changes: 5 additions & 4 deletions README.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pandas_ta/candles/cdl_z.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ def cdl_z(

_full = "a" if full else ""
_props = _full if full else f"_{length}_{ddof}"
df = DataFrame({
data = {
f"open_Z{_props}": z_open,
f"high_Z{_props}": z_high,
f"low_Z{_props}": z_low,
f"close_Z{_props}": z_close,
})
}
df = DataFrame(data, index=close.index)

if full:
df.fillna(method="backfill", axis=0, inplace=True)
Expand Down
27 changes: 27 additions & 0 deletions pandas_ta/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,21 @@ def adx(self, length=None, lensig=None, mamode=None, scalar=None, drift=None, of
drift=drift, offset=offset, **kwargs)
return self._post_process(result, **kwargs)

def alphatrend(self, volume=None, src=None, length=None, multiplier=None, threshold=None, lag=None, mamode=None, talib=None, offset=None, **kwargs: DictLike):
open_ = self._get_column(kwargs.pop("open", "open"))
high = self._get_column(kwargs.pop("high", "high"))
low = self._get_column(kwargs.pop("low", "low"))
close = self._get_column(kwargs.pop("close", "close"))
if volume is not None:
volume = self._get_column(kwargs.pop("volume", "volume"))
result = alphatrend(
open_=open_, high=high, low=low, close=close, volume=volume,
src=src, length=length, multiplier=multiplier,
threshold=threshold, lag=lag, mamode=mamode,
talib=talib, offset=offset, **kwargs
)
return self._post_process(result, **kwargs)

def amat(self, fast=None, slow=None, mamode=None, lookback=None, offset=None, **kwargs: DictLike):
close = self._get_column(kwargs.pop("close", "close"))
result = amat(close=close, fast=fast, slow=slow, mamode=mamode, lookback=lookback, offset=offset, **kwargs)
Expand Down Expand Up @@ -1575,6 +1590,18 @@ def xsignals(self, signal=None, xa=None, xb=None, above=None, long=None, asbool=
trend_offset=trend_offset, trend_reset=trend_reset, offset=offset, **kwargs)
return self._post_process(result, **kwargs)

# def zigzag(self, close=None, pivot_leg=None, price_deviation=None, retrace=None, last_extreme=None, offset=None, **kwargs: DictLike):
# high = self._get_column(kwargs.pop("high", "high"))
# low = self._get_column(kwargs.pop("low", "low"))
# if close is not None:
# close = self._get_column(kwargs.pop("close", "close"))
# result = zigzag(
# high=high, low=low, close=close,
# pivot_leg=pivot_leg, price_deviation=price_deviation,
# retrace=retrace, last_extreme=last_extreme,
# offset=offset, **kwargs)
# return self._post_process(result, **kwargs)

# Volatility
def aberration(self, length=None, atr_length=None, offset=None, **kwargs: DictLike):
high = self._get_column(kwargs.pop("high", "high"))
Expand Down
7 changes: 4 additions & 3 deletions pandas_ta/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@
"transform": ["cube", "ifisher", "remap"],
# Trend
"trend": [
"adx", "amat", "aroon", "chop", "cksp", "decay", "decreasing", "dpo",
"increasing", "long_run", "psar", "qstick", "rwi", "short_run",
"trendflex", "tsignals", "ttm_trend", "vhf", "vortex", "xsignals"
"adx", "alphatrend", "amat", "aroon", "chop", "cksp", "decay",
"decreasing", "dpo", "increasing", "long_run", "psar", "qstick",
"rwi", "short_run", "trendflex", "tsignals", "ttm_trend", "vhf",
"vortex", "xsignals"
],
# Volatility
"volatility": [
Expand Down
9 changes: 5 additions & 4 deletions pandas_ta/momentum/brar.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ def brar(
br.name = f"BR{_props}"
ar.category = br.category = "momentum"

brardf = DataFrame({ar.name: ar, br.name: br})
brardf.name = f"BRAR{_props}"
brardf.category = "momentum"
data = {ar.name: ar, br.name: br}
df = DataFrame(data, index=close.index)
df.name = f"BRAR{_props}"
df.category = "momentum"

return brardf
return df
13 changes: 6 additions & 7 deletions pandas_ta/momentum/dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ def dm(
neg.fillna(method=kwargs["fill_method"], inplace=True)

# Name and Category
_params = f"_{length}"
data = {f"DMP{_params}": pos, f"DMN{_params}": neg, }
_props = f"_{length}"
data = {f"DMP{_props}": pos, f"DMN{_props}": neg}
df = DataFrame(data, index=high.index)
df.name = f"DM{_props}"
df.category = "momentum"

dmdf = DataFrame(data)
dmdf.name = f"DM{_params}"
dmdf.category = "momentum"

return dmdf
return df
2 changes: 1 addition & 1 deletion pandas_ta/momentum/eri.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def eri(
bull.category = bear.category = "momentum"

data = {bull.name: bull, bear.name: bear}
df = DataFrame(data)
df = DataFrame(data, index=close.index)
df.name = f"ERI_{length}"
df.category = bull.category

Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/momentum/fisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def fisher(
fisher.category = signalma.category = "momentum"

data = {fisher.name: fisher, signalma.name: signalma}
df = DataFrame(data)
df = DataFrame(data, index=high.index)
df.name = f"FISHERT{_props}"
df.category = fisher.category

Expand Down
9 changes: 5 additions & 4 deletions pandas_ta/momentum/kdj.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ def kdj(
j.name = f"J{_params}"
k.category = d.category = j.category = "momentum"

kdjdf = DataFrame({k.name: k, d.name: d, j.name: j})
kdjdf.name = f"KDJ{_params}"
kdjdf.category = "momentum"
data = {k.name: k, d.name: d, j.name: j}
df = DataFrame(data, index=close.index)
df.name = f"KDJ{_params}"
df.category = "momentum"

return kdjdf
return df
8 changes: 4 additions & 4 deletions pandas_ta/momentum/kst.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def kst(
kst.category = kst_signal.category = "momentum"

data = {kst.name: kst, kst_signal.name: kst_signal}
kstdf = DataFrame(data)
kstdf.name = f"KST_{roc1}_{roc2}_{roc3}_{roc4}_{sma1}_{sma2}_{sma3}_{sma4}_{signal}"
kstdf.category = "momentum"
df = DataFrame(data, index=close.index)
df.name = f"KST_{roc1}_{roc2}_{roc3}_{roc4}_{sma1}_{sma2}_{sma3}_{sma4}_{signal}"
df.category = "momentum"

return kstdf
return df
5 changes: 3 additions & 2 deletions pandas_ta/momentum/macd.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ def macd(
data = {
macd.name: macd,
histogram.name: histogram,
signalma.name: signalma}
df = DataFrame(data)
signalma.name: signalma
}
df = DataFrame(data, index=close.index)
df.name = f"MACD{_asmode}{_props}"
df.category = macd.category

Expand Down
8 changes: 6 additions & 2 deletions pandas_ta/momentum/ppo.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ def ppo(
signalma.name = f"PPOs{_props}"
ppo.category = histogram.category = signalma.category = "momentum"

data = {ppo.name: ppo, histogram.name: histogram, signalma.name: signalma}
df = DataFrame(data)
data = {
ppo.name: ppo,
histogram.name: histogram,
signalma.name: signalma
}
df = DataFrame(data, index=close.index)
df.name = f"PPO{_props}"
df.category = ppo.category

Expand Down
11 changes: 7 additions & 4 deletions pandas_ta/momentum/qqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,14 @@ def qqe(
qqe_long.category = qqe_short.category = qqe.category

data = {
qqe.name: qqe, rsi_ma.name: rsi_ma,
# long.name: long, short.name: short
qqe_long.name: qqe_long, qqe_short.name: qqe_short
qqe.name: qqe,
rsi_ma.name: rsi_ma,
# long.name: long,
# short.name: short
qqe_long.name: qqe_long,
qqe_short.name: qqe_short
}
df = DataFrame(data)
df = DataFrame(data, index=close.index)
df.name = f"QQE{_props}"
df.category = qqe.category

Expand Down
3 changes: 2 additions & 1 deletion pandas_ta/momentum/rvgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def rvgi(
signal.name = f"RVGIs_{length}_{swma_length}"
rvgi.category = signal.category = "momentum"

df = DataFrame({rvgi.name: rvgi, signal.name: signal})
data = {rvgi.name: rvgi, signal.name: signal}
df = DataFrame(data, index=close.index)
df.name = f"RVGI_{length}_{swma_length}"
df.category = rvgi.category

Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/momentum/smi.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def smi(
smi.category = signalma.category = osc.category = "momentum"

data = {smi.name: smi, signalma.name: signalma, osc.name: osc}
df = DataFrame(data)
df = DataFrame(data, index=close.index)
df.name = f"SMI{_props}"
df.category = smi.category

Expand Down
4 changes: 2 additions & 2 deletions pandas_ta/momentum/squeeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ def squeeze(
squeeze.name: squeeze,
f"SQZ_ON": squeeze_on,
f"SQZ_OFF": squeeze_off,
f"SQZ_NO": no_squeeze,
f"SQZ_NO": no_squeeze
}
df = DataFrame(data)
df = DataFrame(data, index=close.index)
df.name = squeeze.name
df.category = squeeze.category = "momentum"

Expand Down
4 changes: 2 additions & 2 deletions pandas_ta/momentum/squeeze_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ def squeeze_pro(
f"SQZPRO_ON_NORMAL": squeeze_on_normal,
f"SQZPRO_ON_NARROW": squeeze_on_narrow,
f"SQZPRO_OFF": squeeze_off_wide,
f"SQZPRO_NO": no_squeeze,
f"SQZPRO_NO": no_squeeze
}
df = DataFrame(data)
df = DataFrame(data, index=close.index)
df.name = squeeze.name
df.category = squeeze.category = "momentum"

Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/momentum/stc.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def stc(
macd.name: macd,
stoch.name: stoch
}
df = DataFrame(data)
df = DataFrame(data, index=close.index)
df.name = f"STC{_props}"
df.category = stc.category

Expand Down
5 changes: 1 addition & 4 deletions pandas_ta/momentum/stochf.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ def stochf(
stochf_d.name = f"{_name}d{_props}"
stochf_k.category = stochf_d.category = "momentum"

data = {
stochf_k.name: stochf_k,
stochf_d.name: stochf_d
}
data = {stochf_k.name: stochf_k, stochf_d.name: stochf_d}
df = DataFrame(data, index=close.index)
df.name = f"{_name}{_props}"
df.category = stochf_k.category
Expand Down
7 changes: 2 additions & 5 deletions pandas_ta/momentum/stochrsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ def stochrsi(
stochrsi_d.name = f"{_name}d{_props}"
stochrsi_k.category = stochrsi_d.category = "momentum"

data = {
stochrsi_k.name: stochrsi_k,
stochrsi_d.name: stochrsi_d
}
df = DataFrame(data)
data = {stochrsi_k.name: stochrsi_k, stochrsi_d.name: stochrsi_d}
df = DataFrame(data, index=close.index)
df.name = f"{_name}{_props}"
df.category = stochrsi_k.category

Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/momentum/td_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def td_seq(
up_seq.category = down_seq.category = "momentum"

data = {up_seq.name: up_seq, down_seq.name: down_seq}
df = DataFrame(data)
df = DataFrame(data, index=close.index)
df.index = close.index # Only works here for some reason?
df.name = "TD_SEQ"
df.category = up_seq.category
Expand Down
3 changes: 2 additions & 1 deletion pandas_ta/momentum/tsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def tsi(
tsi_signal.name = f"TSIs_{fast}_{slow}_{signal}"
tsi.category = tsi_signal.category = "momentum"

df = DataFrame({tsi.name: tsi, tsi_signal.name: tsi_signal})
data = {tsi.name: tsi, tsi_signal.name: tsi_signal}
df = DataFrame(data, index=close.index)
df.name = f"TSI_{fast}_{slow}_{signal}"
df.category = "momentum"

Expand Down
3 changes: 2 additions & 1 deletion pandas_ta/overlap/hilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def hilo(
data = {
f"HILO{_props}": hilo,
f"HILOl{_props}": long,
f"HILOs{_props}": short}
f"HILOs{_props}": short
}
df = DataFrame(data, index=close.index)

df.name = f"HILO{_props}"
Expand Down
6 changes: 2 additions & 4 deletions pandas_ta/overlap/mama.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,8 @@ def mama(

# Name and Category
_props = f"_{fastlimit}_{slowlimit}"
df = DataFrame({
f"MAMA{_props}": mama,
f"FAMA{_props}": fama,
}, index=close.index)
data = {f"MAMA{_props}": mama, f"FAMA{_props}": fama}
df = DataFrame(data, index=close.index)

df.name = f"MAMA{_props}"
df.category = "overlap"
Expand Down
20 changes: 13 additions & 7 deletions pandas_ta/overlap/supertrend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.overlap import hl2
from pandas_ta.utils import v_offset, v_pos_default, v_series
from pandas_ta.utils import v_mamode, v_offset, v_pos_default, v_series
from pandas_ta.volatility import atr


def supertrend(
high: Series, low: Series, close: Series,
length: Int = None, atr_length: Int = None,
multiplier: IntFloat = None,
atr_mamode : str = None,
offset: Int = None, **kwargs: DictLike
) -> DataFrame:
"""Supertrend (supertrend)
Expand All @@ -31,6 +32,8 @@ def supertrend(
variable of control. Default: length
multiplier (float): Coefficient for upper and lower band distance to
midrange. Default: 3.0
atr_mamode (str) : MA type to be used for ATR calculation.
See ``help(ta.ma)``. Default: 'rma'
offset (int): How many periods to offset the result. Default: 0
Kwargs:
Expand All @@ -52,6 +55,7 @@ def supertrend(
return

multiplier = v_pos_default(multiplier, 3.0)
atr_mamode = v_mamode(atr_mamode, "rma")
offset = v_offset(offset)

# Calculate
Expand All @@ -60,9 +64,10 @@ def supertrend(
long, short = [nan] * m, [nan] * m

hl2_ = hl2(high, low)
matr = multiplier * atr(high, low, close, atr_length)
lb = hl2_ - matr # Lowerband
ub = hl2_ + matr # Upperband
matr = multiplier * atr(high, low, close, atr_length, mamode=atr_mamode)
lb = hl2_ - matr
ub = hl2_ + matr

for i in range(1, m):
if close.iat[i] > ub.iat[i - 1]:
dir_[i] = 1
Expand All @@ -84,12 +89,13 @@ def supertrend(
dir_[:length] = [nan] * length

_props = f"_{length}_{multiplier}"
df = DataFrame({
data = {
f"SUPERT{_props}": trend,
f"SUPERTd{_props}": dir_,
f"SUPERTl{_props}": long,
f"SUPERTs{_props}": short,
}, index=close.index)
f"SUPERTs{_props}": short
}
df = DataFrame(data, index=close.index)

df.name = f"SUPERT{_props}"
df.category = "overlap"
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/performance/drawdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def drawdown(
dd.category = dd_pct.category = dd_log.category = "performance"

data = {dd.name: dd, dd_pct.name: dd_pct, dd_log.name: dd_log}
df = DataFrame(data)
df = DataFrame(data, index=close.index)
df.name = dd.name
df.category = dd.category

Expand Down
3 changes: 2 additions & 1 deletion pandas_ta/transform/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def cube(
ct_signal.name = f"CUBEs{_props}"
ct.category = ct_signal.category = "transform"

df = DataFrame({ct.name: ct, ct_signal.name: ct_signal})
data = {ct.name: ct, ct_signal.name: ct_signal}
df = DataFrame(data, index=close.index)
df.name = f"CUBE{_props}"
df.category = ct.category

Expand Down
Loading

0 comments on commit e853cef

Please sign in to comment.