BUG #458 stoch and stochf

This commit is contained in:
Kevin Johnson
2022-01-14 19:53:05 -08:00
parent a46cb87ccb
commit f13f764247
5 changed files with 20 additions and 20 deletions
+4 -4
View File
File diff suppressed because one or more lines are too long
+5 -5
View File
@@ -40,7 +40,7 @@ def stoch(high, low, close, k=None, d=None, smooth_k=None, mamode=None, talib=No
Returns:
pd.DataFrame: %K, %D columns.
"""
# Validate arguments
# Validate
k = k if k and k > 0 else 14
d = d if d and d > 0 else 3
smooth_k = smooth_k if smooth_k and smooth_k > 0 else 3
@@ -54,7 +54,7 @@ def stoch(high, low, close, k=None, d=None, smooth_k=None, mamode=None, talib=No
if high is None or low is None or close is None: return
# Calculate Result
# Calculate
if Imports["talib"] and mode_tal:
from talib import STOCH
stoch_ = STOCH(high, low, close, k, d, tal_ma(mamode), d, tal_ma(mamode))
@@ -74,7 +74,7 @@ def stoch(high, low, close, k=None, d=None, smooth_k=None, mamode=None, talib=No
stoch_k = stoch_k.shift(offset)
stoch_d = stoch_d.shift(offset)
# Handle fills
# Fill
if "fillna" in kwargs:
stoch_k.fillna(kwargs["fillna"], inplace=True)
stoch_d.fillna(kwargs["fillna"], inplace=True)
@@ -82,14 +82,14 @@ def stoch(high, low, close, k=None, d=None, smooth_k=None, mamode=None, talib=No
stoch_k.fillna(method=kwargs["fill_method"], inplace=True)
stoch_d.fillna(method=kwargs["fill_method"], inplace=True)
# Name and Categorize it
# Name and Category
_name = "STOCH"
_props = f"_{k}_{d}_{smooth_k}"
stoch_k.name = f"{_name}k{_props}"
stoch_d.name = f"{_name}d{_props}"
stoch_k.category = stoch_d.category = "momentum"
# Prepare DataFrame to return
# Return DataFrame
data = {stoch_k.name: stoch_k, stoch_d.name: stoch_d}
df = DataFrame(data, index=close.index)
df.name = f"{_name}{_props}"
+5 -5
View File
@@ -34,7 +34,7 @@ def stochf(high, low, close, k=None, d=None, mamode=None, talib=None, offset=Non
Returns:
pd.DataFrame: Fast %K, %D columns.
"""
# Validate arguments
# Validate
k = k if k and k > 0 else 14
d = d if d and d > 0 else 3
_length = max(k, d)
@@ -47,7 +47,7 @@ def stochf(high, low, close, k=None, d=None, mamode=None, talib=None, offset=Non
if high is None or low is None or close is None: return
# Calculate Result
# Calculate
if Imports["talib"] and mode_tal:
from talib import STOCHF
stochf_ = STOCHF(high, low, close, k, d, tal_ma(mamode))
@@ -65,7 +65,7 @@ def stochf(high, low, close, k=None, d=None, mamode=None, talib=None, offset=Non
stochf_k = stochf_k.shift(offset)
stochf_d = stochf_d.shift(offset)
# Handle fills
# Fill
if "fillna" in kwargs:
stochf_k.fillna(kwargs["fillna"], inplace=True)
stochf_d.fillna(kwargs["fillna"], inplace=True)
@@ -73,14 +73,14 @@ def stochf(high, low, close, k=None, d=None, mamode=None, talib=None, offset=Non
stochf_k.fillna(method=kwargs["fill_method"], inplace=True)
stochf_d.fillna(method=kwargs["fill_method"], inplace=True)
# Name and Categorize it
# Name and Category
_name = "STOCHF"
_props = f"_{k}_{d}"
stochf_k.name = f"{_name}k{_props}"
stochf_d.name = f"{_name}d{_props}"
stochf_k.category = stochf_d.category = "momentum"
# Prepare DataFrame to return
# Return DataFrame
data = {stochf_k.name: stochf_k, stochf_d.name: stochf_d}
df = DataFrame(data, index=close.index)
df.name = f"{_name}{_props}"
+5 -5
View File
@@ -36,7 +36,7 @@ def stochrsi(close, length=None, rsi_length=None, k=None, d=None, mamode=None, o
Returns:
pd.DataFrame: RSI %K, RSI %D columns.
"""
# Validate arguments
# Validate
length = length if length and length > 0 else 14
rsi_length = rsi_length if rsi_length and rsi_length > 0 else 14
k = k if k and k > 0 else 3
@@ -47,7 +47,7 @@ def stochrsi(close, length=None, rsi_length=None, k=None, d=None, mamode=None, o
if close is None: return
# Calculate Result
# Calculate
rsi_ = rsi(close, length=rsi_length)
lowest_rsi = rsi_.rolling(length).min()
highest_rsi = rsi_.rolling(length).max()
@@ -63,7 +63,7 @@ def stochrsi(close, length=None, rsi_length=None, k=None, d=None, mamode=None, o
stochrsi_k = stochrsi_k.shift(offset)
stochrsi_d = stochrsi_d.shift(offset)
# Handle fills
# Fill
if "fillna" in kwargs:
stochrsi_k.fillna(kwargs["fillna"], inplace=True)
stochrsi_d.fillna(kwargs["fillna"], inplace=True)
@@ -71,14 +71,14 @@ def stochrsi(close, length=None, rsi_length=None, k=None, d=None, mamode=None, o
stochrsi_k.fillna(method=kwargs["fill_method"], inplace=True)
stochrsi_d.fillna(method=kwargs["fill_method"], inplace=True)
# Name and Categorize it
# Name and Categorize
_name = "STOCHRSI"
_props = f"_{length}_{rsi_length}_{k}_{d}"
stochrsi_k.name = f"{_name}k{_props}"
stochrsi_d.name = f"{_name}d{_props}"
stochrsi_k.category = stochrsi_d.category = "momentum"
# Prepare DataFrame to return
# Return DataFrame
data = {stochrsi_k.name: stochrsi_k, stochrsi_d.name: stochrsi_d}
df = DataFrame(data)
df.name = f"{_name}{_props}"
+1 -1
View File
@@ -19,7 +19,7 @@ setup(
"pandas_ta.volatility",
"pandas_ta.volume"
],
version=".".join(("0", "3", "42b")),
version=".".join(("0", "3", "43b")),
description=long_description,
long_description=long_description,
author="Kevin Johnson",