diff --git a/README.md b/README.md index 3e932b6..311f162 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ $ pip install pandas_ta Latest Version -------------- -Best choice! Version: *0.3.33b* +Best choice! Version: *0.3.34b* * Includes all fixes and updates between **pypi** and what is covered in this README. ```sh $ pip install -U git+https://github.com/twopirllc/pandas-ta diff --git a/pandas_ta/core.py b/pandas_ta/core.py index cd094ad..a9c37df 100644 --- a/pandas_ta/core.py +++ b/pandas_ta/core.py @@ -578,6 +578,7 @@ class AnalysisIndicators(BasePandasObject): "exchange", "last_run", "reverse", + "sample", "ticker", "time_range", "to_utc", @@ -615,6 +616,14 @@ class AnalysisIndicators(BasePandasObject): s += f"\nTotal Candles, Indicators and Utilities: {_count}" print(s) + + def sample(self, **kwargs): + """sample + See help(ta.sample) for parameters. + """ + return sample(**kwargs) + + def strategy(self, *args, **kwargs): """Strategy Method diff --git a/pandas_ta/overlap/kama.py b/pandas_ta/overlap/kama.py index bd5933e..009616d 100644 --- a/pandas_ta/overlap/kama.py +++ b/pandas_ta/overlap/kama.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- from numpy import nan as npNaN from pandas import Series +from pandas_ta.overlap.ma import ma from pandas_ta.utils import get_drift, get_offset, non_zero_range, verify_series -def kama(close, length=None, fast=None, slow=None, drift=None, offset=None, **kwargs): +def kama(close, length=None, fast=None, slow=None, mamode=None, drift=None, offset=None, **kwargs): """Kaufman's Adaptive Moving Average (KAMA) Developed by Perry Kaufman, Kaufman's Adaptive Moving Average (KAMA) is a moving average @@ -26,6 +27,9 @@ def kama(close, length=None, fast=None, slow=None, drift=None, offset=None, **kw length (int): It's period. Default: 10 fast (int): Fast MA period. Default: 2 slow (int): Slow MA period. Default: 30 + mamode (str): See ```help(ta.ma)```. Valid MAs that support initialize + the first value: 'ema', 'fwma', 'linreg', 'midpoint', 'pwma', 'rma', + 'sinwma', 'sma', 'swma', 'trima', 'wma'. Default: 'sma' drift (int): The difference period. Default: 1 offset (int): How many periods to offset the result. Default: 0 @@ -41,6 +45,14 @@ def kama(close, length=None, fast=None, slow=None, drift=None, offset=None, **kw fast = int(fast) if fast and fast > 0 else 2 slow = int(slow) if slow and slow > 0 else 30 close = verify_series(close, max(fast, slow, length)) + valid_ma = [ + "ema", "fwma", "linreg", "midpoint", "pwma", "rma", + "sinwma", "sma", "swma", "trima", "wma" + ] + if isinstance(mamode, str) and mamode.lower() in valid_ma: + mamode = mamode.lower() + else: + mamode = "sma" drift = get_drift(drift) offset = get_offset(offset) @@ -61,7 +73,8 @@ def kama(close, length=None, fast=None, slow=None, drift=None, offset=None, **kw sc = x * x m = close.size - result = [npNaN for _ in range(0, length - 1)] + [0] + ma0 = ma(mamode, close.iloc[:length], length=length, **kwargs).iloc[-1] + result = [npNaN for _ in range(0, length - 1)] + [ma0] for i in range(length, m): result.append(sc.iloc[i] * close.iloc[i] + (1 - sc.iloc[i]) * result[i - 1]) diff --git a/setup.py b/setup.py index 719ff11..31d0c47 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ setup( "pandas_ta.volatility", "pandas_ta.volume" ], - version=".".join(("0", "3", "33b")), + version=".".join(("0", "3", "34b")), description=long_description, long_description=long_description, author="Kevin Johnson", diff --git a/tests/config.py b/tests/config.py index 29b3f6c..6769089 100644 --- a/tests/config.py +++ b/tests/config.py @@ -18,7 +18,7 @@ sample_data = read_csv( ) sample_data.set_index(DatetimeIndex(sample_data["date"]), inplace=True, drop=True) sample_data.drop("date", axis=1, inplace=True) -# sample_data = sample_data[:200] +sample_data = sample_data[:200] def error_analysis(df, kind, msg, icon=INFO, newline=True):