Skip to content

Commit

Permalink
#779 #625 #775 BUG ENH pvi update with numba MAINT use to_numpy()
Browse files Browse the repository at this point in the history
  • Loading branch information
twopirllc committed Jun 11, 2024
1 parent 930d7df commit 930fa15
Show file tree
Hide file tree
Showing 37 changed files with 121 additions and 88 deletions.
2 changes: 1 addition & 1 deletion pandas_ta/candles/cdl_inside.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def cdl_inside(
offset = v_offset(offset)

# Calculate
np_high, np_low = high.values, low.values
np_high, np_low = high.to_numpy(), low.to_numpy()
np_inside = np_cdl_inside(np_high, np_low)
inside = Series(np_inside, index=close.index, dtype=bool)

Expand Down
4 changes: 2 additions & 2 deletions pandas_ta/candles/ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def ha(
return

# Calculate
np_open, np_high = open_.values, high.values
np_low, np_close = low.values, close.values
np_open, np_high = open_.to_numpy(), high.to_numpy()
np_low, np_close = low.to_numpy(), close.to_numpy()
ha_open, ha_high, ha_low, ha_close = np_ha(np_open, np_high, np_low, np_close)
df = DataFrame({
"HA_open": ha_open,
Expand Down
4 changes: 2 additions & 2 deletions pandas_ta/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1806,10 +1806,10 @@ def obv(self, offset=None, **kwargs: DictLike):
result = obv(close=close, volume=volume, offset=offset, **kwargs)
return self._post_process(result, **kwargs)

def pvi(self, length=None, initial=None, mamode=None, offset=None, **kwargs: DictLike):
def pvi(self, length=None, initial=None, mamode=None, overlay=None, offset=None, **kwargs: DictLike):
close = self._get_column(kwargs.pop("close", "close"))
volume = self._get_column(kwargs.pop("volume", "volume"))
result = pvi(close=close, volume=volume, length=length, initial=initial, mamode=mamode, offset=offset, **kwargs)
result = pvi(close=close, volume=volume, length=length, initial=initial, mamode=mamode, overlay=overlay, offset=offset, **kwargs)
return self._post_process(result, **kwargs)

def pvo(self, fast=None, slow=None, signal=None, scalar=None, offset=None, **kwargs: DictLike):
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/cycles/reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def reflex(
offset = v_offset(offset)

# Calculate
np_close = close.values
np_close = close.to_numpy()
result = np_reflex(np_close, length, smooth, alpha, pi, sqrt2)
result[:length] = nan
result = Series(result, index=close.index)
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/momentum/crsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def crsi(
offset = v_offset(offset)

# Calculate
np_close = close.values
np_close = close.to_numpy()
streak = Series(consecutive_streak(np_close), index=close.index)

if Imports["talib"] and mode_tal:
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/momentum/rvgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def rvgi(
rvgi = numerator / denominator
signal = swma(rvgi, length=swma_length)

if all(isnan(signal.values)):
if all(isnan(signal.to_numpy())):
return # Emergency Break

# Offset
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/alma.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def alma(
offset = v_offset(offset)

# Calculate
np_close = close.values
np_close = close.to_numpy()
x = arange(length)
k = floor(offset_ * (length - 1))
weights = exp(-0.5 * ((sigma / length) * (x - k)) ** 2)
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/dema.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def dema(
ema2 = ema(close=ema1, length=length, talib=mode_tal)
dema = 2 * ema1 - ema2

if all(isnan(dema.values)):
if all(isnan(dema.to_numpy())):
return # Emergency Break

# Offset
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/hl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def hl2(
return

# Calculate
avg = 0.5 * (high.values + low.values)
avg = 0.5 * (high.to_numpy() + low.to_numpy())
hl2 = Series(avg, index=high.index)

# Offset
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/hlc3.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def hlc3(
from talib import TYPPRICE
hlc3 = TYPPRICE(high, low, close)
else:
avg = (high.values + low.values + close.values) / 3.0
avg = (high.to_numpy() + low.to_numpy() + close.to_numpy()) / 3.0
hlc3 = Series(avg, index=close.index)

# Offset
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/linreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def linreg(
tsf = kwargs.pop("tsf", False)

# Calculate
np_close = close.values
np_close = close.to_numpy()

if Imports["talib"] and mode_tal and not r:
from talib import LINEARREG, LINEARREG_ANGLE, LINEARREG_INTERCEPT, LINEARREG_SLOPE, TSF
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/mama.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def mama(
offset = v_offset(offset)

# Calculate
np_close = close.values
np_close = close.to_numpy()
if Imports["talib"] and mode_tal:
from talib import MAMA
mama, fama = MAMA(np_close, fastlimit, slowlimit)
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/ohlc4.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def ohlc4(
offset = v_offset(offset)

# Calculate
avg = 0.25 * (open_.values + high.values + low.values + close.values)
avg = 0.25 * (open_.to_numpy() + high.to_numpy() + low.to_numpy() + close.to_numpy())
ohlc4 = Series(avg, index=close.index)

# Offset
Expand Down
8 changes: 4 additions & 4 deletions pandas_ta/overlap/pivots.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ def pivots(
index=dt_index
)

np_open = df.open.values
np_high = df.high.values
np_low = df.low.values
np_close = df.close.values
np_open = df.open.to_numpy()
np_high = df.high.to_numpy()
np_low = df.low.to_numpy()
np_close = df.close.to_numpy()

# Create nan arrays for "demark" and "fibonacci" pivots
_nan_array = zeros_like(np_close)
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/sma.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def sma(
from talib import SMA
sma = SMA(close, length)
else:
np_close = close.values
np_close = close.to_numpy()
sma = np_sma(np_close, length)
sma = Series(sma, index=close.index)

Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/ssf.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def ssf(
offset = v_offset(offset)

# Calculate
np_close = close.values
np_close = close.to_numpy()
if everget:
ssf = np_ssf_everget(np_close, length, pi, sqrt2)
else:
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/ssf3.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def ssf3(
offset = v_offset(offset)

# Calculate
np_close = close.values
np_close = close.to_numpy()
ssf = np_ssf3(np_close, length, pi, sqrt3)
ssf = Series(ssf, index=close.index)

Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/wcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def wcp(
from talib import WCLPRICE
wcp = WCLPRICE(high, low, close)
else:
weight = high.values + low.values + 2 * close.values
weight = high.to_numpy() + low.to_numpy() + 2 * close.to_numpy()
wcp = Series(weight, index=close.index)

# Offset
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/overlap/wma.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def wma(
from talib import WMA
wma = WMA(close, length)
else:
np_close = close.values
np_close = close.to_numpy()
wma_ = np_wma(np_close, length, asc, True)
wma = Series(wma_, index=close.index)

Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/performance/log_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def log_return(
offset = v_offset(offset)

# Calculate
np_close = close.values
np_close = close.to_numpy()
if cumulative:
r = np_close / np_close[0]
else:
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/performance/percent_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def percent_return(
offset = v_offset(offset)

# Calculate
np_close = close.values
np_close = close.to_numpy()
if cumulative:
pr = (np_close / np_close[0]) - 1
else:
Expand Down
6 changes: 3 additions & 3 deletions pandas_ta/transform/ifisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def ifisher(
offset = v_offset(offset)

# Calculate
np_close = close.values
np_close = close.to_numpy()
is_remapped = logical_and(np_close >= -1, np_close <= 1)
if not all(is_remapped):
np_max, np_min = max(np_close), min(np_close)
close_map = remap(close, from_min=np_min, from_max=np_max, to_min=-1, to_max=1)
if close_map is None or all(isnan(close_map.values)):
if close_map is None or all(isnan(close_map.to_numpy())):
return # Emergency Break
np_close = close_map.values
np_close = close_map.to_numpy()
amped = exp(amp * np_close)
result = (amped - 1) / (amped + 1)

Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/transform/remap.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def remap(
frange, trange = from_max - from_min, to_max - to_min
if frange <= 0 or trange <= 0:
return
result = to_min + (trange / frange) * (close.values - from_min)
result = to_min + (trange / frange) * (close.to_numpy() - from_min)
result = Series(result, index=close.index)

# Offset
Expand Down
4 changes: 2 additions & 2 deletions pandas_ta/trend/alphatrend.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def alphatrend(
if momo is None:
return

np_upper_atr, np_lower_atr = upper_atr.values, lower_atr.values
np_upper_atr, np_lower_atr = upper_atr.to_numpy(), lower_atr.to_numpy()

at = np_alpha(np_lower_atr, np_upper_atr, momo.values >= threshold)
at = np_alpha(np_lower_atr, np_upper_atr, momo.to_numpy() >= threshold)
at = Series(at, index=close.index)

atl = at.shift(lag)
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/trend/decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def decay(
offset = v_offset(offset)

# Calculate
_mode, np_close = "L", close.values
_mode, np_close = "L", close.to_numpy()

if mode in ["exp", "exponential"]:
_mode = "EXP"
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/trend/ht_trendline.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def ht_trendline(
from talib import HT_TRENDLINE
tl = HT_TRENDLINE(close)
else:
np_close = close.values
np_close = close.to_numpy()
np_tl = np_ht_trendline(np_close)

if prenan > 0:
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/trend/trendflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def trendflex(
offset = v_offset(offset)

# Calculate
np_close = close.values
np_close = close.to_numpy()
result = np_trendflex(np_close, length, smooth, alpha, pi, sqrt2)
result[:length] = nan
result = Series(result, index=close.index)
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/trend/xsignals.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def xsignals(

# Modify trades to fill gaps for trends
trades.replace({0: nan}, inplace=True)
trades.interpolate(method="pad", inplace=True)
trades.ffill(limit_area="inside", inplace=True) # or trades.bfill(limit_area="inside", inplace=True)
trades.fillna(0, inplace=True)

trends = (trades > 0).astype(int)
Expand Down
4 changes: 2 additions & 2 deletions pandas_ta/trend/zigzag.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def zigzag(

if close is not None:
close = v_series(close, _length + 1)
np_close = close.values
np_close = close.to_numpy()
if close is None:
return

Expand All @@ -70,7 +70,7 @@ def zigzag(
offset = v_offset(offset)

# Calculation
np_high, np_low = high.values, low.values
np_high, np_low = high.to_numpy(), low.to_numpy()
highest_high = high.rolling(window=pivot_leg, center=True, min_periods=0).max()
lowest_low = low.rolling(window=pivot_leg, center=True, min_periods=0).min()

Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/utils/_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def geometric_mean(series: Series) -> Float:
if n < 1:
return series.iloc[0]

has_zeros = 0 in series.values
has_zeros = 0 in series.to_numpy()
if has_zeros:
series = series.fillna(0) + 1
if all(series > 0):
Expand Down
2 changes: 1 addition & 1 deletion pandas_ta/volatility/atrts.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def atrts(
atr_ *= multiplier
ma_ = _ma(mamode, close, length=ma_length, talib=mode_tal)

np_close, np_ma, np_atr = close.values, ma_.values, atr_.values
np_close, np_ma, np_atr = close.to_numpy(), ma_.to_numpy(), atr_.to_numpy()
np_atrts_, _, _ = np_atrts(np_close, np_ma, np_atr, length, ma_length)

percent = kwargs.pop("percent", False)
Expand Down
4 changes: 2 additions & 2 deletions pandas_ta/volume/kvo.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def kvo(
sv = signed_volume.loc[signed_volume.first_valid_index():, ]

kvo = ma(mamode, sv, length=fast) - ma(mamode, sv, length=slow)
if kvo is None or all(isnan(kvo.values)):
if kvo is None or all(isnan(kvo.to_numpy())):
return # Emergency Break

kvo_signal = ma(mamode, kvo.loc[kvo.first_valid_index():, ], length=signal)
if kvo_signal is None or all(isnan(kvo_signal.values)):
if kvo_signal is None or all(isnan(kvo_signal.to_numpy())):
return # Emergency Break

# Offset
Expand Down
4 changes: 2 additions & 2 deletions pandas_ta/volume/mfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def mfi(
else:
m, _ones = close.size, ones(length)

tp = (high.values + low.values + close.values) / 3.0
smf = tp * volume.values * where(tp > roll(tp, shift=drift), 1, -1)
tp = (high.to_numpy() + low.to_numpy() + close.to_numpy()) / 3.0
smf = tp * volume.to_numpy() * where(tp > roll(tp, shift=drift), 1, -1)

pos, neg = maximum(smf, 0), maximum(-smf, 0)
avg_gain, avg_loss = convolve(pos, _ones)[:m], convolve(neg, _ones)[:m]
Expand Down
Loading

0 comments on commit 930fa15

Please sign in to comment.