MAINT ENH typing validation DEV rename performance to speed_test

This commit is contained in:
Kevin Johnson
2022-02-28 12:19:11 -08:00
parent bcf47ba486
commit 70c4ced1cc
175 changed files with 4491 additions and 4204 deletions
+8 -2
View File
@@ -98,7 +98,7 @@ Performance
* **TA Lib** computations are **enabled** by default. They can be disabled per indicator.
* The library includes a performance method, ```help(ta.performance)```, to check runtime indicator performance for a given _ohlcv_ DataFrame.
* Optionable **Multiprocessing** for a Pandas TA ```Study```.
* Check your Indicator Performance with the [Indicator Performance Notebook](https://github.com/twopirllc/pandas-ta/tree/main/examples/Performance_Check.ipynb).
* Check Indicator Speeds on your system with the [Indicator Speed Check Notebook](https://github.com/twopirllc/pandas-ta/tree/main/examples/Speed_Check.ipynb).
Bulk Processing
---------------
@@ -157,6 +157,12 @@ Pandas TA is used by Applications and Services like
<br/>
[Tune TA](https://github.com/jmrichardson/tuneta)
-------------------
> TuneTA optimizes technical indicators using a distance correlation measure to a user defined target feature such as next day return. Indicator parameter(s) are selected using clustering techniques to avoid "peak" or "lucky" values. The set of tuned indicators can be ...
<br/>
Back to [Contents](#contents)
<br/>
@@ -192,7 +198,7 @@ $ pip install pandas_ta[full]
Latest Version
--------------
Best choice! Version: *0.3.52b*
Best choice! Version: *0.3.53b*
* 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
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+251 -260
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+131 -113
View File
File diff suppressed because one or more lines are too long
+48 -44
View File
@@ -1,24 +1,59 @@
# -*- coding: utf-8 -*-
from pandas_ta.overlap import sma
from pandas_ta.utils import get_offset, verify_series
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.ma import ma
from pandas_ta.utils import v_mamode, v_offset, v_pos_default, v_series
# - Standard definition of your custom indicator function (including docs)-
def ni(
close: Series, length: Int = None,
centered: bool = False, mamode: str = None,
offset: Int = None, **kwargs: DictLike
):
"""Example indicator (NI)
def ni(close, length=None, centered=False, offset=None, **kwargs):
"""
Example indicator ni
"""
# Validate Arguments
length = int(length) if length and length > 0 else 20
close = verify_series(close, length)
offset = get_offset(offset)
Is an indicator provided solely as an example
if close is None: return
Sources:
https://github.com/twopirllc/pandas-ta/issues/264
Calculation:
Default Inputs:
length=20, centered=False
SMA = Simple Moving Average
t = int(0.5 * length) + 1
ni = close.shift(t) - SMA(close, length)
if centered:
ni = ni.shift(-t)
Args:
close (pd.Series): Series of 'close's
length (int): It's period. Default: 20
mamode (str): Chosen Moving Average. Default: "sma"
centered (bool): Shift the ni back by int(0.5 * length) + 1. Default: False
offset (int): How many periods to offset the result. Default: 0
Kwargs:
fillna (value, optional): pd.DataFrame.fillna(value)
fill_method (value, optional): Type of fill method
Returns:
pd.Series: New feature generated.
""" # Validate Arguments
length = v_pos_default(length, 20)
close = v_series(close, length)
if close is None:
return
mamode = v_mamode(mamode, "sma")
offset = v_offset(offset)
# Calculate Result
t = int(0.5 * length) + 1
ma = sma(close, length)
ma = ma(mamode, close, length=length, **kwargs)
t = int(0.5 * length) + 1
ni = close - ma.shift(t)
if centered:
ni = (close.shift(t) - ma).shift(-t)
@@ -39,37 +74,6 @@ def ni(close, length=None, centered=False, offset=None, **kwargs):
return ni
ni.__doc__ = \
"""Example indicator (NI)
Is an indicator provided solely as an example
Sources:
https://github.com/twopirllc/pandas-ta/issues/264
Calculation:
Default Inputs:
length=20, centered=False
SMA = Simple Moving Average
t = int(0.5 * length) + 1
ni = close.shift(t) - SMA(close, length)
if centered:
ni = ni.shift(-t)
Args:
close (pd.Series): Series of 'close's
length (int): It's period. Default: 20
centered (bool): Shift the ni back by int(0.5 * length) + 1. Default: False
offset (int): How many periods to offset the result. Default: 0
Kwargs:
fillna (value, optional): pd.DataFrame.fillna(value)
fill_method (value, optional): Type of fill method
Returns:
pd.Series: New feature generated.
"""
# - Define a matching class method --------------------------------------------
+13 -11
View File
@@ -2,8 +2,9 @@
from pandas import Series
from pandas_ta.overlap import sma
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.utils import get_offset, high_low_range, is_percent
from pandas_ta.utils import real_body, verify_series
from pandas_ta.utils import high_low_range, is_percent
from pandas_ta.utils import real_body, v_offset, v_pos_default
from pandas_ta.utils import v_scalar, v_series
def cdl_doji(
@@ -42,19 +43,20 @@ def cdl_doji(
pd.Series: CDL_DOJI column.
"""
# Validate
length = int(length) if length and length > 0 else 10
factor = float(factor) if is_percent(factor) else 10
scalar = float(scalar) if scalar else 100
open_ = verify_series(open_, length)
high = verify_series(high, length)
low = verify_series(low, length)
close = verify_series(close, length)
offset = get_offset(offset)
naive = kwargs.pop("naive", False)
length = v_pos_default(length, 10)
open_ = v_series(open_, length)
high = v_series(high, length)
low = v_series(low, length)
close = v_series(close, length)
if open_ is None or high is None or low is None or close is None:
return
factor = v_scalar(factor, 10) if is_percent(factor) else 10
scalar = v_scalar(scalar, 100)
offset = v_offset(offset)
naive = kwargs.pop("naive", False)
# Calculate
body = real_body(open_, close).abs()
hl_range = high_low_range(high, low).abs()
+6 -6
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import candle_color, get_offset, verify_series
from pandas_ta.utils import candle_color, v_offset, v_series
def cdl_inside(
@@ -39,11 +39,11 @@ def cdl_inside(
pd.Series: New feature
"""
# Validate
open_ = verify_series(open_)
high = verify_series(high)
low = verify_series(low)
close = verify_series(close)
offset = get_offset(offset)
open_ = v_series(open_)
high = v_series(high)
low = v_series(low)
close = v_series(close)
offset = v_offset(offset)
# Calculate
inside = (high.diff() < 0) & (low.diff() > 0)
+7 -7
View File
@@ -2,7 +2,7 @@
from pandas import Series, DataFrame
from pandas_ta._typing import DictLike, Int, IntFloat, List, Union
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_scalar, v_series
from pandas_ta.candles import cdl_doji, cdl_inside
@@ -62,12 +62,12 @@ def cdl_pattern(
pd.DataFrame: one column for each pattern.
"""
# Validate Arguments
open_ = verify_series(open_)
high = verify_series(high)
low = verify_series(low)
close = verify_series(close)
offset = get_offset(offset)
scalar = float(scalar) if scalar else 100
open_ = v_series(open_)
high = v_series(high)
low = v_series(low)
close = v_series(close)
offset = v_offset(offset)
scalar = v_scalar(scalar, 100)
# Patterns that implemented in pandas-ta
pta_patterns = {"doji": cdl_doji, "inside": cdl_inside}
+10 -9
View File
@@ -2,7 +2,7 @@
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.statistics import zscore
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_bool, v_offset, v_pos_default, v_series
def cdl_z(
@@ -36,18 +36,19 @@ def cdl_z(
pd.Series: CDL_DOJI column.
"""
# Validate
length = int(length) if length and length > 0 else 30
ddof = int(ddof) if ddof and ddof >= 0 and ddof < length else 1
open_ = verify_series(open_, length)
high = verify_series(high, length)
low = verify_series(low, length)
close = verify_series(close, length)
offset = get_offset(offset)
full = bool(full) if full is not None and full else False
length = v_pos_default(length, 30)
open_ = v_series(open_, length)
high = v_series(high, length)
low = v_series(low, length)
close = v_series(close, length)
if open_ is None or high is None or low is None or close is None:
return
full = v_bool(full, False) if isinstance(full, bool) else False
ddof = int(ddof) if isinstance(ddof, int) and 0 <= ddof < length else 1
offset = v_offset(offset)
# Calculate
if full:
length = close.size
+6 -6
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_series
def ha(
@@ -37,11 +37,11 @@ def ha(
pd.DataFrame: ha_open, ha_high,ha_low, ha_close columns.
"""
# Validate
open_ = verify_series(open_)
high = verify_series(high)
low = verify_series(low)
close = verify_series(close)
offset = get_offset(offset)
open_ = v_series(open_)
high = v_series(high)
low = v_series(low)
close = v_series(close)
offset = v_offset(offset)
# Calculate
m = close.size
+38 -34
View File
@@ -7,7 +7,6 @@ from warnings import simplefilter
from numpy import log10, ndarray
from pandas.api.extensions import register_dataframe_accessor
from pandas.core.base import PandasObject
from pandas.errors import PerformanceWarning
from pandas import DataFrame, Series
@@ -116,19 +115,15 @@ class AnalysisIndicators(object):
_time_range = "years"
def __init__(self, obj: SeriesFrame):
self._validate(obj)
v_dataframe(obj)
self._df = obj
self._last_run = get_time(self._exchange, to_string=True)
@staticmethod
def _validate(obj: SeriesFrame):
if not isinstance(obj, DataFrame) and not isinstance(obj, Series):
raise AttributeError("[X] Requires a Pandas Series or DataFrame.")
# DataFrame Behavioral Methods
def __call__(
self, kind: str = None,
timed: bool = False, version: bool = False, **kwargs: DictLike
self, kind: str = None, timed: bool = False,
version: bool = False, **kwargs: DictLike
):
if version: print(f"Pandas TA - Technical Analysis Indicators - v{self.version}")
try:
@@ -141,12 +136,12 @@ class AnalysisIndicators(object):
# Run the indicator
result = fn(**kwargs) # = getattr(self, kind)(**kwargs)
self._last_run = get_time(self.exchange, to_string=True) # Save when it completed it's run
if timed:
result.timed = final_time(stime)
print(f"[+] {kind}: {result.timed}")
self._last_run = get_time(self.exchange, to_string=True)
return result
else:
self.help()
@@ -232,10 +227,9 @@ class AnalysisIndicators(object):
@property
def datetime_ordered(self) -> bool:
"""Returns True if the index is a datetime and ordered."""
hasdf = hasattr(self, "_df")
if hasdf:
return is_datetime_ordered(self._df)
return hasdf
if hasattr(self, "_df"):
return v_datetime_ordered(self._df)
return False
@property
def reverse(self) -> DataFrame:
@@ -543,27 +537,25 @@ class AnalysisIndicators(object):
with possibly as json, yaml config file or an sqlite3 table.
Kwargs:
chunksize (bool): Adjust the chunksize for the Multiprocessing Pool.
Default: Number of cores of the OS
exclude (list): List of indicator names to exclude. Some are
excluded by default for various reasons; they require additional
sources, performance (td_seq), not a time series chart (vp) etc.
chunksize (bool): Adjust the chunksize for the Multiprocessing
Pool. Default: Number of cores of the OS
exclude (list): List of indicator names to exclude.
name (str): Select all indicators or indicators by
Category such as: "candles", "cycles", "momentum", "overlap",
"performance", "statistics", "trend", "volatility", "volume", or
"all". Default: "all"
Category such as: "candles", "cycles", "momentum",
"overlap", "performance", "statistics", "trend", "volatility",
"volume", or "all". Default: "all"
ordered (bool): Whether to run "all" in order. Default: True
timed (bool): Show the process time of the study().
Default: False
verbose (bool): Provide some additional insight on the progress of
the study() execution. Default: False
verbose (bool): Provide some additional insight on the progress
of the study() execution. Default: False
warning (bool): Disables depreciation message. Automatically
disabled when using it's replacement method: df.ta.study().
Default: True
"""
_dep_warning = kwargs.pop("warning", True)
all_ordered = kwargs.pop("ordered", True)
# Ensure indicators are appended to the DataFrame
# Append indicators to the DataFrame by default
kwargs.setdefault("append", True)
# If True, it returns the resultant DataFrame. Default: False
returns = kwargs.pop("returns", False)
@@ -576,7 +568,7 @@ class AnalysisIndicators(object):
print(f"\n[!] DEPRECIATION WARNING:\n Use study() instead of strategy().\n")
# Initialize
initial_column_count = len(self._df.columns)
initial_column_count = self._df.shape[1]
excluded = ["long_run", "short_run", "tsignals", "xsignals"]
# Get the Study Name and mode
@@ -608,7 +600,8 @@ class AnalysisIndicators(object):
removal = []
for kwds in ta:
_ = False
if "length" in kwds and kwds["length"] > self._df.shape[0]: _ = True
if "length" in kwds and kwds["length"] > self._df.shape[0]:
_ = True
if _: removal.append(kwds)
if len(removal) > 0: [ta.remove(x) for x in removal]
@@ -638,16 +631,19 @@ class AnalysisIndicators(object):
use_multiprocessing = False
if Imports["tqdm"]:
# from tqdm import tqdm
from tqdm import tqdm
if use_multiprocessing:
_total_ta = len(ta)
with Pool(self.cores) as pool:
# Some magic to optimize chunksize for speed based on total ta indicators
_chunksize = mp_chunksize - 1 if mp_chunksize > _total_ta else int(log10(_total_ta)) + 1
# Some magic to optimize chunksize for speed
# based on total ta indicators
if mp_chunksize > _total_ta:
_chunksize = mp_chunksize - 1
else:
_chunksize = int(log10(_total_ta)) + 1
if verbose:
print(f"[i] Multiprocessing {_total_ta} indicators with {_chunksize} chunks and {self.cores}/{cpu_count()} cpus.")
print(f"[i] Multiprocessing {_total_ta} indicators with chunksize {_chunksize} and {self.cores}/{cpu_count()} cpus.")
results = None
if mode["custom"]:
@@ -715,15 +711,23 @@ class AnalysisIndicators(object):
# Apply prefixes/suffixes and appends indicator results to the DataFrame
[self._post_process(r, **kwargs) for r in results]
final_column_count = self._df.shape[1]
_added_columns = final_column_count - initial_column_count
if verbose:
print(f"[i] Total indicators: {len(ta)}")
print(f"[i] Columns added: {len(self._df.columns) - initial_column_count}")
print(f"[i] Columns added: {_added_columns}")
print(f"[i] Last Run: {self._last_run}")
if timed:
print(f"[i] Analysis Time: {final_time(stime)}")
if returns: return self._df
ft = final_time(stime)
if _added_columns > 0:
avgtd = (perf_counter() - stime) / _added_columns
else:
avgtd = perf_counter() - stime
print(f"[i] Analysis Time: {ft} for {_added_columns} columns (avg {avgtd * 1000:2.4f} ms / col).")
if returns:
return self._df
def study(self, *args: Args, **kwargs: DictLike) -> dataclass:
"""Study Method
+8 -9
View File
@@ -2,7 +2,7 @@
from numpy import cos, exp, mean, nan, pi, roll, sin, sqrt, zeros
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
def ebsw(
@@ -16,7 +16,7 @@ def ebsw(
remove noise. Its output is bound signal between -1 and 1 and the
maximum length of a detected trend is limited by its length input.
Written by rengel8 for Pandas TA based on a publication at
Coded by rengel8 for Pandas TA based on a publication at
'prorealcode.com' and a book by J.F.Ehlers. According to the suggestion
by Squigglez2* and major differences between the initial version's
output close to the implementation from Ehler's, the default version is
@@ -51,21 +51,20 @@ def ebsw(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if isinstance(length, int) and length > 10 else 40
bars = int(bars) if isinstance(bars, int) and bars > 0 else 10
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 40)
close = v_series(close, length)
if close is None:
return
bars = v_pos_default(bars, 10)
offset = v_offset(offset)
# Calculate
# allow initial version to be used (more responsive/caution!)
m = close.size
initial_version = bool(initial_version) if isinstance(
initial_version, bool) else False
if initial_version:
if isinstance(initial_version, bool) and initial_version:
# not the default version that is active
alpha1 = hp = 0 # alpha and HighPass
a1 = b1 = c1 = c2 = c3 = 0
+14 -10
View File
@@ -2,7 +2,7 @@
from numpy import cos, exp, nan, sqrt, zeros_like
from pandas import Series
from pandas_ta._typing import Array, DictLike, Int, IntFloat
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
try:
@@ -56,8 +56,8 @@ def reflex(
(Reflex/Trendflex) are oscillators and complement each other with the
focus for cycle and trend.
Written for Pandas TA by rengel8 (2021-08-11) based on the implementation
on ProRealCode (see Sources). Beyond the mentioned source, this
Coded by rengel8 (2021-08-11) based on the implementation on
ProRealCode (see Sources). Beyond the mentioned source, this
implementation has a separate control parameter for the internal
applied SuperSmoother.
@@ -86,13 +86,17 @@ def reflex(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if isinstance(length, int) and length > 0 else 20
smooth = int(smooth) if isinstance(smooth, int) and smooth > 0 else 20
alpha = float(alpha) if isinstance(alpha, float) and alpha > 0 else 0.04
pi = float(pi) if isinstance(pi, float) and pi > 0 else 3.14159
sqrt2 = float(sqrt2) if isinstance(sqrt2, float) and sqrt2 > 0 else 1.414
close = verify_series(close, max(length, smooth))
offset = get_offset(offset)
length = v_pos_default(length, 20)
smooth = v_pos_default(smooth, 20)
close = v_series(close, max(length, smooth))
if close is None:
return
alpha = v_pos_default(alpha, 0.04)
pi = v_pos_default(pi, 3.14159)
sqrt2 = v_pos_default(sqrt2, 1.414)
offset = v_offset(offset)
# Calculate
np_close = close.values
+1 -2
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta._typing import DictLike
from pandas_ta.overlap.dema import dema
from pandas_ta.overlap.ema import ema
from pandas_ta.overlap.fwma import fwma
@@ -42,7 +42,6 @@ def ma(name: str = None, source: Series = None, **kwargs: DictLike) -> Series:
Returns:
pd.Series: New feature generated.
"""
_mas = [
"dema", "ema", "fwma", "hma", "linreg", "midpoint", "pwma", "rma",
"sinwma", "sma", "ssf", "swma", "t3", "tema", "trima", "vidya", "wma"
+7 -6
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.overlap import sma
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
def ao(
@@ -34,18 +34,19 @@ def ao(
pd.Series: New feature generated.
"""
# Validate
fast = int(fast) if fast and fast > 0 else 5
slow = int(slow) if slow and slow > 0 else 34
fast = v_pos_default(fast, 5)
slow = v_pos_default(slow, 34)
if slow < fast:
fast, slow = slow, fast
_length = max(fast, slow)
high = verify_series(high, _length)
low = verify_series(low, _length)
offset = get_offset(offset)
high = v_series(high, _length)
low = v_series(low, _length)
if high is None or low is None:
return
offset = v_offset(offset)
# Calculate
median_price = 0.5 * (high + low)
fast_sma = sma(median_price, fast)
+9 -7
View File
@@ -3,7 +3,8 @@ from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.ma import ma
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, tal_ma, verify_series
from pandas_ta.utils import tal_ma, v_mamode, v_offset
from pandas_ta.utils import v_pos_default, v_series, v_talib
def apo(
@@ -38,18 +39,19 @@ def apo(
pd.Series: New feature generated.
"""
# Validate
fast = int(fast) if fast and fast > 0 else 12
slow = int(slow) if slow and slow > 0 else 26
fast = v_pos_default(fast, 12)
slow = v_pos_default(slow, 26)
if slow < fast:
fast, slow = slow, fast
close = verify_series(close, max(fast, slow))
mamode = mamode if isinstance(mamode, str) else "sma"
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
close = v_series(close, max(fast, slow))
if close is None:
return
mamode = v_mamode(mamode, "sma")
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import APO
+6 -5
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.ma import ma
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_mamode, v_offset, v_pos_default, v_series
def bias(
@@ -31,14 +31,15 @@ def bias(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 26
mamode = mamode if isinstance(mamode, str) else "sma"
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 26)
close = v_series(close, length)
if close is None:
return
mamode = v_mamode(mamode, "sma")
offset = v_offset(offset)
# Calculate
bma = ma(mamode, close, length=length, **kwargs)
bias = (close / bma) - 1
+8 -8
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, non_zero_range, verify_series
from pandas_ta.utils import non_zero_range, v_offset, v_scalar, v_series, v_talib
def bop(
@@ -35,13 +35,13 @@ def bop(
pd.Series: New feature generated.
"""
# Validate
open_ = verify_series(open_)
high = verify_series(high)
low = verify_series(low)
close = verify_series(close)
scalar = float(scalar) if scalar else 1
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
open_ = v_series(open_)
high = v_series(high)
low = v_series(low)
close = v_series(close)
scalar = v_scalar(scalar, 1)
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
+13 -11
View File
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.utils import get_drift, get_offset, non_zero_range, verify_series
from pandas_ta.utils import non_zero_range, v_drift, v_offset
from pandas_ta.utils import v_pos_default, v_scalar, v_series
def brar(
@@ -35,21 +36,22 @@ def brar(
pd.DataFrame: ar, br columns.
"""
# Validate
length = int(length) if length and length > 0 else 26
scalar = float(scalar) if scalar else 100
high_open_range = non_zero_range(high, open_)
open_low_range = non_zero_range(open_, low)
open_ = verify_series(open_, length)
high = verify_series(high, length)
low = verify_series(low, length)
close = verify_series(close, length)
drift = get_drift(drift)
offset = get_offset(offset)
length = v_pos_default(length, 26)
open_ = v_series(open_, length)
high = v_series(high, length)
low = v_series(low, length)
close = v_series(close, length)
if open_ is None or high is None or low is None or close is None:
return
scalar = v_scalar(scalar, 100)
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
high_open_range = non_zero_range(high, open_)
open_low_range = non_zero_range(open_, low)
hcy = non_zero_range(high, close.shift(drift))
cyl = non_zero_range(close.shift(drift), low)
+9 -8
View File
@@ -4,7 +4,7 @@ from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.maps import Imports
from pandas_ta.overlap import hlc3, sma
from pandas_ta.statistics import mad
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
def cci(
@@ -38,17 +38,18 @@ def cci(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 14
c = float(c) if c and c > 0 else 0.015
high = verify_series(high, length)
low = verify_series(low, length)
close = verify_series(close, length)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 14)
high = v_series(high, length)
low = v_series(low, length)
close = v_series(close, length)
if high is None or low is None or close is None:
return
c = v_pos_default(c, 0.015)
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import CCI
+7 -6
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.overlap import linreg
from pandas_ta.utils import get_drift, get_offset, verify_series
from pandas_ta.utils import v_drift, v_offset, v_pos_default, v_scalar, v_series
def cfo(
@@ -34,15 +34,16 @@ def cfo(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 9
scalar = float(scalar) if scalar else 100
close = verify_series(close, length)
drift = get_drift(drift)
offset = get_offset(offset)
length = v_pos_default(length, 9)
close = v_series(close, length)
if close is None:
return
scalar = v_scalar(scalar, 100)
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
# Finding linear regression of Series
cfo = scalar * (close - linreg(close, length=length, tsf=True))
+5 -4
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series, weights
from pandas_ta.utils import v_offset, v_pos_default, v_series, weights
def cg(
@@ -29,13 +29,14 @@ def cg(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
offset = v_offset(offset)
# Calculate
coefficients = [length - i for i in range(0, length)]
numerator = -close.rolling(length).apply(weights(coefficients), raw=True)
+10 -7
View File
@@ -3,7 +3,9 @@ from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.maps import Imports
from pandas_ta.overlap import rma
from pandas_ta.utils import get_drift, get_offset, verify_series
from pandas_ta.utils import v_drift, v_offset, v_pos_default
from pandas_ta.utils import v_scalar, v_series, v_talib
def cmo(
@@ -39,16 +41,17 @@ def cmo(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 14
scalar = float(scalar) if scalar else 100
close = verify_series(close, length)
drift = get_drift(drift)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 14)
close = v_series(close, length)
if close is None:
return
scalar = v_scalar(scalar, 100)
mode_tal = v_talib(talib)
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import CMO
+7 -6
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.overlap import wma
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
from .roc import roc
@@ -36,15 +36,16 @@ def coppock(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
fast = int(fast) if fast and fast > 0 else 11
slow = int(slow) if slow and slow > 0 else 14
close = verify_series(close, max(length, fast, slow))
offset = get_offset(offset)
length = v_pos_default(length, 10)
fast = v_pos_default(fast, 11)
slow = v_pos_default(slow, 14)
close = v_series(close, max(length, fast, slow))
if close is None:
return
offset = v_offset(offset)
# Calculate
total_roc = roc(close, fast) + roc(close, slow)
coppock = wma(total_roc, length)
+5 -4
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.overlap import linreg
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
def cti(
@@ -30,13 +30,14 @@ def cti(
pd.Series: Series of the CTI values for the given period.
"""
# Validate
length = int(length) if length and length > 0 else 12
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 12)
close = v_series(close, length)
if close is None:
return
offset = v_offset(offset)
# Calculate
cti = linreg(close, length=length, r=True)
+10 -8
View File
@@ -3,7 +3,8 @@ from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.ma import ma
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series, get_drift, zero
from pandas_ta.utils import v_drift, v_mamode, v_offset
from pandas_ta.utils import v_pos_default, v_series, v_talib, zero
def dm(
@@ -38,17 +39,18 @@ def dm(
pd.DataFrame: DMP (+DM) and DMN (-DM) columns.
"""
# Validate
length = int(length) if length and length > 0 else 14
mamode = mamode.lower() if mamode and isinstance(mamode, str) else "rma"
high = verify_series(high)
low = verify_series(low)
drift = get_drift(drift)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 14)
high = v_series(high)
low = v_series(low)
if high is None or low is None:
return
mamode = v_mamode(mamode, "rma")
mode_tal = v_talib(talib)
drift = v_drift(drift)
offset = v_offset(offset)
if Imports["talib"] and mode_tal:
from talib import MINUS_DM, PLUS_DM
pos = PLUS_DM(high, low, length)
+6 -5
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import DataFrame, concat, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_drift, get_offset, verify_series, signals
from pandas_ta.utils import signals, v_drift, v_offset, v_pos_default, v_series
def er(
@@ -33,14 +33,15 @@ def er(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
close = verify_series(close, length)
offset = get_offset(offset)
drift = get_drift(drift)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
abs_diff = close.diff(length).abs()
abs_volatility = close.diff(drift).abs()
+7 -6
View File
@@ -2,7 +2,7 @@
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.overlap import ema
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
def eri(
@@ -38,15 +38,16 @@ def eri(
pd.DataFrame: bull power and bear power columns.
"""
# Validate
length = int(length) if length and length > 0 else 13
high = verify_series(high, length)
low = verify_series(low, length)
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 13)
high = v_series(high, length)
low = v_series(low, length)
close = v_series(close, length)
if high is None or low is None or close is None:
return
offset = v_offset(offset)
# Calculate
ema_ = ema(close, length)
bull = high - ema_
+7 -6
View File
@@ -3,7 +3,7 @@ from numpy import log, nan
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.overlap import hl2
from pandas_ta.utils import get_offset, high_low_range, verify_series
from pandas_ta.utils import high_low_range, v_offset, v_pos_default, v_series
def fisher(
@@ -34,16 +34,17 @@ def fisher(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 9
signal = int(signal) if signal and signal > 0 else 1
length = v_pos_default(length, 9)
signal = v_pos_default(signal, 1)
_length = max(length, signal)
high = verify_series(high, _length)
low = verify_series(low, _length)
offset = get_offset(offset)
high = v_series(high, _length)
low = v_series(low, _length)
if high is None or low is None:
return
offset = v_offset(offset)
# Calculate
hl2_ = hl2(high, low)
highest_hl2 = hl2_.rolling(length).max()
+27 -18
View File
@@ -2,7 +2,8 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.overlap import linreg
from pandas_ta.utils import get_drift, get_offset, verify_series
from pandas_ta.utils import v_bool, v_drift, v_mamode, v_offset
from pandas_ta.utils import v_pos_default, v_scalar, v_series
from pandas_ta.volatility import rvi
@@ -44,36 +45,44 @@ def inertia(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 20
rvi_length = int(rvi_length) if rvi_length and rvi_length > 0 else 14
scalar = float(scalar) if scalar and scalar > 0 else 100
refined = False if refined is None else True
thirds = False if thirds is None else True
mamode = mamode if isinstance(mamode, str) else "ema"
length = v_pos_default(length, 20)
rvi_length = v_pos_default(rvi_length, 14)
_length = max(length, rvi_length)
close = verify_series(close, _length)
drift = get_drift(drift)
offset = get_offset(offset)
close = v_series(close, _length)
if close is None:
return
refined = v_bool(refined, False)
thirds = v_bool(thirds, False)
if refined or thirds:
high = verify_series(high, _length)
low = verify_series(low, _length)
high = v_series(high, _length)
low = v_series(low, _length)
if high is None or low is None:
return
scalar = v_scalar(scalar, 100)
mamode = v_mamode(mamode, "ema")
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
if refined:
_mode, rvi_ = "r", rvi(close, high=high, low=low, length=rvi_length,
scalar=scalar, refined=refined, mamode=mamode)
_mode = "r"
rvi_ = rvi(
close, high=high, low=low, length=rvi_length,
scalar=scalar, refined=refined, mamode=mamode
)
elif thirds:
_mode, rvi_ = "t", rvi(close, high=high, low=low, length=rvi_length,
scalar=scalar, thirds=thirds, mamode=mamode)
_mode = "t"
rvi_ = rvi(
close, high=high, low=low, length=rvi_length,
scalar=scalar, thirds=thirds, mamode=mamode
)
else:
_mode, rvi_ = "", rvi(close, length=rvi_length,
scalar=scalar, mamode=mamode)
_mode = ""
rvi_ = rvi(close, length=rvi_length, scalar=scalar, mamode=mamode)
inertia = linreg(rvi_, length=length)
+9 -7
View File
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, non_zero_range, rma_pandas, verify_series
from pandas_ta.utils import non_zero_range, rma_pandas, v_offset
from pandas_ta.utils import v_pos_default, v_series
def kdj(
@@ -37,17 +38,18 @@ def kdj(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 9
signal = int(signal) if signal and signal > 0 else 3
length = v_pos_default(length, 9)
signal = v_pos_default(signal, 3)
_length = max(length, signal)
high = verify_series(high, _length)
low = verify_series(low, _length)
close = verify_series(close, _length)
offset = get_offset(offset)
high = v_series(high, _length)
low = v_series(low, _length)
close = v_series(close, _length)
if high is None or low is None or close is None:
return
offset = v_offset(offset)
# Calculate
highest_high = high.rolling(length).max()
lowest_low = low.rolling(length).min()
+6 -5
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_drift, get_offset, verify_series
from pandas_ta.utils import v_drift, v_offset, v_pos_default, v_series
from .roc import roc
@@ -52,15 +52,16 @@ def kst(
sma3 = int(sma3) if sma3 and sma3 > 0 else 10
sma4 = int(sma4) if sma4 and sma4 > 0 else 15
signal = int(signal) if signal and signal > 0 else 9
signal = v_pos_default(signal, 9)
_length = max(roc1, roc2, roc3, roc4, sma1, sma2, sma3, sma4, signal)
close = verify_series(close, _length)
drift = get_drift(drift)
offset = get_offset(offset)
close = v_series(close, _length)
if close is None:
return
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
rocma1 = roc(close, roc1).rolling(sma1).mean()
rocma2 = roc(close, roc2).rolling(sma2).mean()
+11 -9
View File
@@ -3,12 +3,14 @@ from pandas import concat, DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.overlap import ema
from pandas_ta.utils import get_offset, verify_series, signals
from pandas_ta.utils import signals, v_offset, v_mamode
from pandas_ta.utils import v_pos_default, v_series, v_talib
def macd(
close: Series, fast: Int = None, slow: Int = None, signal: Int = None,
talib: bool = None, offset: Int = None, **kwargs: DictLike
close: Series, fast: Int = None, slow: Int = None,
signal: Int = None, talib: bool = None,
offset: Int = None, **kwargs: DictLike
) -> DataFrame:
"""Moving Average Convergence Divergence (MACD)
@@ -40,18 +42,18 @@ def macd(
pd.DataFrame: macd, histogram, signal columns.
"""
# Validate
fast = int(fast) if fast and fast > 0 else 12
slow = int(slow) if slow and slow > 0 else 26
signal = int(signal) if signal and signal > 0 else 9
fast = v_pos_default(fast, 12)
slow = v_pos_default(slow, 26)
signal = v_pos_default(signal, 9)
if slow < fast:
fast, slow = slow, fast
close = verify_series(close, slow + signal)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
close = v_series(close, slow + signal)
if close is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
as_mode = kwargs.setdefault("asmode", False)
# Calculate
+6 -5
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
def mom(
@@ -32,14 +32,15 @@ def mom(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
close = verify_series(close, length)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import MOM
+7 -6
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.overlap import ema, sma
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
from pandas_ta.volatility import atr
@@ -36,15 +36,16 @@ def pgo(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 14
high = verify_series(high, length)
low = verify_series(low, length)
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 14)
high = v_series(high, length)
low = v_series(low, length)
close = v_series(close, length)
if high is None or low is None or close is None:
return
offset = v_offset(offset)
# Calculate
pgo = close - sma(close, length)
pgo /= ema(atr(high, low, close, length), length)
+11 -9
View File
@@ -3,7 +3,8 @@ from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.ma import ma
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, tal_ma, verify_series
from pandas_ta.utils import tal_ma, v_mamode, v_offset, v_pos_default
from pandas_ta.utils import v_scalar, v_series, v_talib
def ppo(
@@ -37,20 +38,21 @@ def ppo(
pd.DataFrame: ppo, histogram, signal columns
"""
# Validate
fast = int(fast) if fast and fast > 0 else 12
slow = int(slow) if slow and slow > 0 else 26
signal = int(signal) if signal and signal > 0 else 9
scalar = float(scalar) if scalar else 100
mamode = mamode if isinstance(mamode, str) else "sma"
fast = v_pos_default(fast, 12)
slow = v_pos_default(slow, 26)
signal = v_pos_default(signal, 9)
if slow < fast:
fast, slow = slow, fast
close = verify_series(close, max(fast, slow, signal))
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
close = v_series(close, max(fast, slow, signal))
if close is None:
return
scalar = v_scalar(scalar, 100)
mamode = v_mamode(mamode, "sma")
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import PPO
+8 -7
View File
@@ -2,7 +2,7 @@
from numpy import sign
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.utils import get_drift, get_offset, verify_series
from pandas_ta.utils import v_drift, v_offset, v_pos_default, v_scalar, v_series
def psl(
@@ -36,18 +36,19 @@ def psl(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 12
scalar = float(scalar) if scalar and scalar > 0 else 100
close = verify_series(close, length)
drift = get_drift(drift)
offset = get_offset(offset)
length = v_pos_default(length, 12)
close = v_series(close, length)
if close is None:
return
scalar = v_scalar(scalar, 100)
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
if open_ is not None:
open_ = verify_series(open_)
open_ = v_series(open_)
diff = sign(close - open_)
else:
diff = sign(close.diff(drift))
+8 -7
View File
@@ -2,7 +2,7 @@
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.overlap import ema
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_scalar, v_series
def pvo(
@@ -33,18 +33,19 @@ def pvo(
pd.DataFrame: pvo, histogram, signal columns.
"""
# Validate
fast = int(fast) if fast and fast > 0 else 12
slow = int(slow) if slow and slow > 0 else 26
signal = int(signal) if signal and signal > 0 else 9
scalar = float(scalar) if scalar else 100
fast = v_pos_default(fast, 12)
slow = v_pos_default(slow, 26)
signal = v_pos_default(signal, 9)
if slow < fast:
fast, slow = slow, fast
volume = verify_series(volume, max(fast, slow, signal))
offset = get_offset(offset)
volume = v_series(volume, max(fast, slow, signal))
if volume is None:
return
scalar = v_scalar(scalar, 100)
offset = v_offset(offset)
# Calculate
fastma = ema(volume, length=fast)
slowma = ema(volume, length=slow)
+10 -8
View File
@@ -3,7 +3,8 @@ from numpy import isnan, maximum, minimum, nan
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.ma import ma
from pandas_ta.utils import get_drift, get_offset, verify_series
from pandas_ta.utils import v_drift, v_mamode, v_offset
from pandas_ta.utils import v_pos_default, v_scalar, v_series
from .rsi import rsi
@@ -49,18 +50,19 @@ def qqe(
pd.DataFrame: QQE, RSI_MA (basis), QQEl (long), QQEs (short) columns.
"""
# Validate
length = int(length) if isinstance(length, int) and length > 0 else 14
smooth = int(smooth) if isinstance(smooth, int) and smooth > 0 else 5
factor = float(factor) if isinstance(factor, float) and factor else 4.236
length = v_pos_default(length, 14)
smooth = v_pos_default(smooth, 5)
wilders_length = 2 * length - 1
mamode = mamode if isinstance(mamode, str) else "ema"
close = verify_series(close, smooth + wilders_length)
drift = get_drift(drift)
offset = get_offset(offset)
close = v_series(close, smooth + wilders_length)
if close is None:
return
factor = v_scalar(factor, 4.236)
mamode = v_mamode(mamode, "ema")
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
rsi_ = rsi(close, length)
_mode = mamode.lower()[0] if mamode != "ema" else ""
+8 -6
View File
@@ -2,7 +2,8 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_scalar
from pandas_ta.utils import v_series, v_talib
from .mom import mom
@@ -37,15 +38,16 @@ def roc(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
scalar = float(scalar) if scalar and scalar > 0 else 100
close = verify_series(close, length)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
scalar = v_scalar(scalar, 100)
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import ROC
+9 -7
View File
@@ -3,7 +3,8 @@ from pandas import DataFrame, concat, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.maps import Imports
from pandas_ta.overlap import rma
from pandas_ta.utils import get_drift, get_offset, verify_series, signals
from pandas_ta.utils import signals, v_drift, v_offset, v_pos_default
from pandas_ta.utils import v_scalar, v_series, v_talib
def rsi(
@@ -37,16 +38,17 @@ def rsi(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 14
scalar = float(scalar) if scalar else 100
close = verify_series(close, length)
drift = get_drift(drift)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 14)
close = v_series(close, length)
if close is None:
return
scalar = v_scalar(scalar, 100)
mode_tal = v_talib(talib)
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import RSI
+6 -5
View File
@@ -2,7 +2,7 @@
from numpy import nan
from pandas_ta._typing import DictLike, Int
from pandas import concat, DataFrame, Series
from pandas_ta.utils import get_drift, get_offset, verify_series, signals
from pandas_ta.utils import v_drift, v_offset, v_pos_default, v_series, signals
def rsx(
@@ -35,14 +35,15 @@ def rsx(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 14
close = verify_series(close, length)
drift = get_drift(drift)
offset = get_offset(offset)
length = v_pos_default(length, 14)
close = v_series(close, length)
if close is None:
return
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
m = close.size
vC, v1C = 0, 0
+12 -10
View File
@@ -2,7 +2,7 @@
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.overlap import swma
from pandas_ta.utils import get_offset, non_zero_range, verify_series
from pandas_ta.utils import non_zero_range, v_offset, v_pos_default, v_series
def rvgi(
@@ -37,21 +37,23 @@ def rvgi(
pd.Series: New feature generated.
"""
# Validate
high_low_range = non_zero_range(high, low)
close_open_range = non_zero_range(close, open_)
length = int(length) if length and length > 0 else 14
swma_length = int(swma_length) if swma_length and swma_length > 0 else 4
length = v_pos_default(length, 14)
swma_length = v_pos_default(swma_length, 4)
_length = max(length, swma_length)
open_ = verify_series(open_, _length)
high = verify_series(high, _length)
low = verify_series(low, _length)
close = verify_series(close, _length)
offset = get_offset(offset)
open_ = v_series(open_, _length)
high = v_series(high, _length)
low = v_series(low, _length)
close = v_series(close, _length)
if open_ is None or high is None or low is None or close is None:
return
offset = v_offset(offset)
# Calculate
high_low_range = non_zero_range(high, low)
close_open_range = non_zero_range(close, open_)
numerator = swma(
close_open_range, length=swma_length
).rolling(length).sum()
+7 -6
View File
@@ -2,7 +2,7 @@
from numpy import arctan, pi
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_bool, v_offset, v_pos_default, v_series
def slope(
@@ -43,15 +43,16 @@ def slope(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 1
as_angle = True if isinstance(as_angle, bool) else False
to_degrees = True if isinstance(to_degrees, bool) else False
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 1)
close = v_series(close, length)
if close is None:
return
as_angle = v_bool(as_angle, False)
to_degrees = v_bool(to_degrees, False)
offset = v_offset(offset)
# Calculate
slope = close.diff(length) / length
if as_angle:
+10 -9
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_scalar, v_series
from .tsi import tsi
@@ -42,18 +42,19 @@ def smi(
pd.DataFrame: smi, signal, oscillator columns.
"""
# Validate
fast = int(fast) if fast and fast > 0 else 5
slow = int(slow) if slow and slow > 0 else 20
signal = int(signal) if signal and signal > 0 else 5
fast = v_pos_default(fast, 5)
slow = v_pos_default(slow, 20)
signal = v_pos_default(signal, 5)
if slow < fast:
fast, slow = slow, fast
scalar = float(scalar) if scalar else 1
close = verify_series(close, max(fast, slow, signal))
offset = get_offset(offset)
close = v_series(close, max(fast, slow, signal))
if close is None:
return
scalar = v_scalar(scalar, 1)
offset = v_offset(offset)
# Calculate
tsi_df = tsi(close, fast=fast, slow=slow, signal=signal, scalar=scalar)
smi = tsi_df.iloc[:, 0]
@@ -77,8 +78,8 @@ def smi(
osc.fillna(method=kwargs["fill_method"], inplace=True)
# Name and Category
_scalar = f"_{scalar}" if scalar != 1 else ""
_props = f"_{fast}_{slow}_{signal}{_scalar}"
# _scalar = f"_{scalar}" if scalar != 1 else ""
_props = f"_{fast}_{slow}_{signal}_{scalar}"
smi.name = f"SMI{_props}"
signalma.name = f"SMIs{_props}"
osc.name = f"SMIo{_props}"
+15 -13
View File
@@ -4,7 +4,8 @@ from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.overlap import ema, linreg, sma
from pandas_ta.trend import decreasing, increasing
from pandas_ta.utils import get_offset, simplify_columns, unsigned_differences, verify_series
from pandas_ta.utils import simplify_columns, unsigned_differences, v_mamode
from pandas_ta.utils import v_offset, v_pos_default, v_series
from pandas_ta.volatility import bbands, kc
from .mom import mom
@@ -62,26 +63,27 @@ def squeeze(
detailed columns if 'detailed' kwarg is True.
"""
# Validate
bb_length = int(bb_length) if bb_length and bb_length > 0 else 20
bb_std = float(bb_std) if bb_std and bb_std > 0 else 2.0
kc_length = int(kc_length) if kc_length and kc_length > 0 else 20
kc_scalar = float(kc_scalar) if kc_scalar and kc_scalar > 0 else 1.5
mom_length = int(mom_length) if mom_length and mom_length > 0 else 12
mom_smooth = int(mom_smooth) if mom_smooth and mom_smooth > 0 else 6
bb_length = v_pos_default(bb_length, 20)
kc_length = v_pos_default(kc_length, 20)
mom_length = v_pos_default(mom_length, 12)
mom_smooth = v_pos_default(mom_smooth, 6)
_length = max(bb_length, kc_length, mom_length, mom_smooth)
high = verify_series(high, _length)
low = verify_series(low, _length)
close = verify_series(close, _length)
offset = get_offset(offset)
high = v_series(high, _length)
low = v_series(low, _length)
close = v_series(close, _length)
if high is None or low is None or close is None:
return
use_tr = kwargs.setdefault("tr", True)
bb_std = v_pos_default(bb_std, 2.0)
kc_scalar = v_pos_default(kc_scalar, 1.5)
mamode = v_mamode(mamode, "sma")
offset = v_offset(offset)
use_tr = kwargs.pop("tr", True)
asint = kwargs.pop("asint", True)
detailed = kwargs.pop("detailed", False)
lazybear = kwargs.pop("lazybear", False)
mamode = mamode if isinstance(mamode, str) else "sma"
# Calculate
bbd = bbands(close, length=bb_length, std=bb_std, mamode=mamode)
+22 -37
View File
@@ -2,12 +2,13 @@
from numpy import nan
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.ma import ma
from pandas_ta.momentum import mom
from pandas_ta.overlap import ema, sma
# from pandas_ta.overlap import ema, sma
from pandas_ta.trend import decreasing, increasing
from pandas_ta.volatility import bbands, kc
from pandas_ta.utils import get_offset, simplify_columns, unsigned_differences, verify_series
from pandas_ta.utils import simplify_columns, unsigned_differences, v_mamode
from pandas_ta.utils import v_offset, v_pos_default, v_scalar, v_series
def squeeze_pro(
high: Series, low: Series, close: Series,
@@ -67,46 +68,33 @@ def squeeze_pro(
More detailed columns if 'detailed' kwarg is True.
"""
# Validate
bb_length = int(bb_length) if bb_length and bb_length > 0 else 20
bb_std = float(bb_std) if bb_std and bb_std > 0 else 2.0
kc_length = int(kc_length) if kc_length and kc_length > 0 else 20
if kc_scalar_wide and kc_scalar_wide > 0:
kc_scalar_wide = float(kc_scalar_wide)
else:
kc_scalar_wide = 2
if kc_scalar_normal and kc_scalar_normal > 0:
kc_scalar_normal = float(kc_scalar_normal)
else:
kc_scalar_normal = 1.5
if kc_scalar_narrow and kc_scalar_narrow > 0:
kc_scalar_narrow = float(kc_scalar_narrow)
else:
kc_scalar_narrow = 1
mom_length = int(mom_length) if mom_length and mom_length > 0 else 12
mom_smooth = int(mom_smooth) if mom_smooth and mom_smooth > 0 else 6
bb_length = v_pos_default(bb_length, 20)
kc_length = v_pos_default(kc_length, 20)
mom_length = v_pos_default(mom_length, 12)
mom_smooth = v_pos_default(mom_smooth, 6)
_length = max(bb_length, kc_length, mom_length, mom_smooth)
high = verify_series(high, _length)
low = verify_series(low, _length)
close = verify_series(close, _length)
offset = get_offset(offset)
high = v_series(high, _length)
low = v_series(low, _length)
close = v_series(close, _length)
if high is None or low is None or close is None:
return
kc_scalar_narrow = v_scalar(kc_scalar_narrow, 1)
kc_scalar_normal = v_scalar(kc_scalar_normal, 1.5)
kc_scalar_wide = v_scalar(kc_scalar_wide, 2)
valid_kc_scaler = kc_scalar_wide > kc_scalar_normal \
and kc_scalar_normal > kc_scalar_narrow
if not valid_kc_scaler:
return
if high is None or low is None or close is None:
return
use_tr = kwargs.setdefault("tr", True)
bb_std = v_pos_default(bb_std, 2.0)
mamode = v_mamode(mamode, "sma")
offset = v_offset(offset)
use_tr = kwargs.pop("tr", True)
asint = kwargs.pop("asint", True)
detailed = kwargs.pop("detailed", False)
mamode = mamode if isinstance(mamode, str) else "sma"
# Calculate
bbd = bbands(close, length=bb_length, std=bb_std, mamode=mamode)
@@ -130,10 +118,7 @@ def squeeze_pro(
kch_narrow.columns = simplify_columns(kch_narrow)
momo = mom(close, length=mom_length)
if mamode.lower() == "ema":
squeeze = ema(momo, length=mom_smooth)
else: # "sma"
squeeze = sma(momo, length=mom_smooth)
squeeze = ma(mamode, momo, length=mom_smooth)
# Classify Squeezes
squeeze_on_wide = (bbd.l > kch_wide.l) & (bbd.u < kch_wide.u)
+14 -14
View File
@@ -2,7 +2,8 @@
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.overlap import ema
from pandas_ta.utils import get_offset, non_zero_range, verify_series
from pandas_ta.utils import non_zero_range, v_offset
from pandas_ta.utils import v_pos_default, v_series
def stc(
@@ -33,8 +34,9 @@ def stc(
The same goes for osc=, which allows the input of an externally
calculated oscillator, overriding ma1 & ma2.
Coded by rengel8
Sources:
Implemented by rengel8 based on work found here:
https://www.prorealcode.com/prorealtime-indicators/schaff-trend-cycle2/
Args:
@@ -58,22 +60,20 @@ def stc(
pd.DataFrame: stc, macd, stoch
"""
# Validate
if isinstance(tclength, int) and tclength > 0:
tclength = int(tclength)
else:
tclength = 10
fast = int(fast) if isinstance(fast, int) and fast > 0 else 12
slow = int(slow) if isinstance(slow, int) and slow > 0 else 26
factor = float(factor) if isinstance(factor, int) and factor > 0 else 0.5
fast = v_pos_default(fast, 12)
slow = v_pos_default(slow, 26)
tclength = v_pos_default(tclength, 10)
if slow < fast: # mandatory condition, but might be confusing
fast, slow = slow, fast
_length = max(tclength, fast, slow)
close = verify_series(close, _length)
offset = get_offset(offset)
close = v_series(close, _length)
if close is None:
return
factor = v_pos_default(factor, 0.5)
offset = v_offset(offset)
# Calculate
# kwargs allows for three more series (ma1, ma2 and osc) which can be passed
# here ma1 and ma2 input negate internal ema calculations, osc substitutes
@@ -84,8 +84,8 @@ def stc(
# 3 different modes of calculation..
if isinstance(ma1, Series) and isinstance(ma2, Series) and not osc:
ma1 = verify_series(ma1, _length)
ma2 = verify_series(ma2, _length)
ma1 = v_series(ma1, _length)
ma2 = v_series(ma2, _length)
if ma1 is None or ma2 is None:
return
@@ -93,7 +93,7 @@ def stc(
xmacd = ma1 - ma2
pff, pf = schaff_tc(close, xmacd, tclength, factor)
elif isinstance(osc, Series):
osc = verify_series(osc, _length)
osc = v_series(osc, _length)
if osc is None:
return
# According to feeded oscillator (should be ranging around 0 x-axis)
+12 -10
View File
@@ -3,7 +3,8 @@ from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.ma import ma
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, non_zero_range, tal_ma, verify_series
from pandas_ta.utils import non_zero_range, tal_ma, v_mamode
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
def stoch(
@@ -48,20 +49,21 @@ def stoch(
pd.DataFrame: %K, %D columns.
"""
# 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
k = v_pos_default(k, 14)
d = v_pos_default(d, 3)
smooth_k = v_pos_default(smooth_k, 3)
_length = k + d + smooth_k
high = verify_series(high, _length)
low = verify_series(low, _length)
close = verify_series(close, _length)
offset = get_offset(offset)
mamode = mamode if isinstance(mamode, str) else "sma"
mode_tal = bool(talib) if isinstance(talib, bool) else True
high = v_series(high, _length)
low = v_series(low, _length)
close = v_series(close, _length)
if high is None or low is None or close is None:
return
mode_tal = v_talib(talib)
mamode = v_mamode(mamode, "sma")
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import STOCH
+11 -9
View File
@@ -3,7 +3,8 @@ from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.ma import ma
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, non_zero_range, tal_ma, verify_series
from pandas_ta.utils import non_zero_range, tal_ma, v_mamode
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
def stochf(
@@ -41,19 +42,20 @@ def stochf(
pd.DataFrame: Fast %K, %D columns.
"""
# Validate
k = k if k and k > 0 else 14
d = d if d and d > 0 else 3
k = v_pos_default(k, 14)
d = v_pos_default(d, 3)
_length = max(k, d)
high = verify_series(high, _length)
low = verify_series(low, _length)
close = verify_series(close, _length)
offset = get_offset(offset)
mamode = mamode if isinstance(mamode, str) else "sma"
mode_tal = bool(talib) if isinstance(talib, bool) else True
high = v_series(high, _length)
low = v_series(low, _length)
close = v_series(close, _length)
if high is None or low is None or close is None:
return
mamode = v_mamode(mamode, "sma")
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import STOCHF
+10 -8
View File
@@ -3,7 +3,8 @@ from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.ma import ma
from pandas_ta.momentum import rsi
from pandas_ta.utils import get_offset, non_zero_range, verify_series
from pandas_ta.utils import non_zero_range, v_mamode
from pandas_ta.utils import v_offset, v_pos_default, v_series
def stochrsi(
@@ -44,17 +45,18 @@ def stochrsi(
pd.DataFrame: RSI %K, RSI %D columns.
"""
# 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
d = d if d and d > 0 else 3
close = verify_series(close, length + rsi_length + k + d)
offset = get_offset(offset)
mamode = mamode if isinstance(mamode, str) else "sma"
length = v_pos_default(length, 14)
rsi_length = v_pos_default(rsi_length, 14)
k = v_pos_default(k, 3)
d = v_pos_default(d, 3)
close = v_series(close, length + rsi_length + k + d)
if close is None:
return
mamode = v_mamode(mamode, "sma")
offset = v_offset(offset)
# Calculate
rsi_ = rsi(close, length=rsi_length)
lowest_rsi = rsi_.rolling(length).min()
+6 -5
View File
@@ -2,7 +2,7 @@
from numpy import where
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_bool, v_offset, v_series
def td_seq(
@@ -32,14 +32,15 @@ def td_seq(
pd.DataFrame: New feature generated.
"""
# Validate
close = verify_series(close)
offset = get_offset(offset)
asint = asint if isinstance(asint, bool) else False
show_all = show_all if isinstance(show_all, bool) else True
close = v_series(close)
if close is None:
return
asint = v_bool(asint, False)
show_all = v_bool(show_all, True)
offset = v_offset(offset)
# Calculate
up_seq = calc_td(close, "up", show_all)
down_seq = calc_td(close, "down", show_all)
+9 -7
View File
@@ -2,7 +2,8 @@
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.overlap.ema import ema
from pandas_ta.utils import get_drift, get_offset, verify_series
from pandas_ta.utils import v_drift, v_offset, v_pos_default
from pandas_ta.utils import v_scalar, v_series
def trix(
@@ -33,17 +34,18 @@ def trix(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 30
signal = int(signal) if signal and signal > 0 else 9
scalar = float(scalar) if scalar else 100
length = v_pos_default(length, 30)
_length = 3 * length - 2
close = verify_series(close, _length)
drift = get_drift(drift)
offset = get_offset(offset)
close = v_series(close, _length)
if close is None:
return
signal = v_pos_default(signal, 9)
scalar = v_scalar(scalar, 100)
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
ema1 = ema(close=close, length=length, **kwargs)
# if all(isnan(ema1)): return # Emergency Break
+11 -11
View File
@@ -3,7 +3,8 @@ from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.ma import ma
from pandas_ta.overlap import ema
from pandas_ta.utils import get_drift, get_offset, verify_series
from pandas_ta.utils import v_drift, v_mamode, v_offset
from pandas_ta.utils import v_pos_default, v_scalar, v_series
def tsi(
@@ -40,22 +41,21 @@ def tsi(
pd.DataFrame: tsi, signal.
"""
# Validate
fast = int(fast) if fast and fast > 0 else 13
slow = int(slow) if slow and slow > 0 else 25
signal = int(signal) if signal and signal > 0 else 13
# if slow < fast:
# fast, slow = slow, fast
scalar = float(scalar) if scalar else 100
close = verify_series(close, max(fast, slow))
drift = get_drift(drift)
offset = get_offset(offset)
mamode = mamode if isinstance(mamode, str) else "ema"
fast = v_pos_default(fast, 13)
slow = v_pos_default(slow, 25)
close = v_series(close, max(fast, slow))
if "length" in kwargs:
kwargs.pop("length")
if close is None:
return
signal = v_pos_default(signal, 13)
scalar = v_scalar(scalar, 100)
mamode = v_mamode(mamode, "ema")
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
diff = close.diff(drift)
slow_ema = ema(close=diff, length=slow, **kwargs)
+14 -13
View File
@@ -2,7 +2,7 @@
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.maps import Imports
from pandas_ta.utils import get_drift, get_offset, verify_series
from pandas_ta.utils import v_drift, v_offset, v_pos_default, v_series, v_talib
def uo(
@@ -43,23 +43,24 @@ def uo(
pd.Series: New feature generated.
"""
# Validate
fast = int(fast) if fast and fast > 0 else 7
fast_w = float(fast_w) if fast_w and fast_w > 0 else 4.0
medium = int(medium) if medium and medium > 0 else 14
medium_w = float(medium_w) if medium_w and medium_w > 0 else 2.0
slow = int(slow) if slow and slow > 0 else 28
slow_w = float(slow_w) if slow_w and slow_w > 0 else 1.0
fast = v_pos_default(fast, 7)
medium = v_pos_default(medium, 14)
slow = v_pos_default(slow, 28)
_length = max(fast, medium, slow)
high = verify_series(high, _length)
low = verify_series(low, _length)
close = verify_series(close, _length)
drift = get_drift(drift)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
high = v_series(high, _length)
low = v_series(low, _length)
close = v_series(close, _length)
if high is None or low is None or close is None:
return
fast_w = v_pos_default(fast_w, 4.0)
medium_w = v_pos_default(medium_w, 2.0)
slow_w = v_pos_default(slow_w, 1.0)
mode_tal = v_talib(talib)
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import ULTOSC
+8 -7
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
def willr(
@@ -35,21 +35,22 @@ def willr(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 14
length = v_pos_default(length, 14)
if "min_periods" in kwargs and kwargs["min_periods"] is not None:
min_periods = int(kwargs["min_periods"])
else:
min_periods = length
_length = max(length, min_periods)
high = verify_series(high, _length)
low = verify_series(low, _length)
close = verify_series(close, _length)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
high = v_series(high, _length)
low = v_series(low, _length)
close = v_series(close, _length)
if high is None or low is None or close is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import WILLR
+8 -7
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
from .smma import smma
@@ -42,16 +42,17 @@ def alligator(
pd.DataFrame: JAW, TEETH, LIPS columns.
"""
# Validate
jaw = int(jaw) if jaw and jaw > 0 else 13
teeth = int(teeth) if teeth and teeth > 0 else 8
lips = int(lips) if lips and lips > 0 else 5
close = verify_series(close, max(jaw, teeth, lips))
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
jaw = v_pos_default(jaw, 13)
teeth = v_pos_default(teeth, 8)
lips = v_pos_default(lips, 5)
close = v_series(close, max(jaw, teeth, lips))
if close is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
gator_jaw = smma(close, length=jaw, talib=mode_tal)
gator_teeth = smma(close, length=teeth, talib=mode_tal)
+9 -7
View File
@@ -3,7 +3,7 @@ from numpy import append, arange, array, exp, floor, nan, tensordot
from numpy.version import version as npVersion
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas import Series
from pandas_ta.utils import get_offset, strided_window, verify_series
from pandas_ta.utils import strided_window, v_offset, v_pos_default, v_series
def alma(
@@ -39,17 +39,19 @@ def alma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if isinstance(length, int) and length > 0 else 9
sigma = float(sigma) if isinstance(sigma, float) and sigma > 0 else 6.0
length = v_pos_default(length, 9)
close = v_series(close, length)
if close is None:
return
sigma = v_pos_default(sigma, 6.0)
if isinstance(dist_offset, float) and 0 <= dist_offset <= 1:
offset_ = float(dist_offset)
else:
offset_ = 0.85
close = verify_series(close, length)
offset = get_offset(offset)
if close is None:
return
offset = v_offset(offset)
# Calculate
np_close = close.values
+6 -5
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
from .ema import ema
@@ -33,14 +33,15 @@ def dema(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
close = verify_series(close, length)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import DEMA
+8 -7
View File
@@ -3,7 +3,7 @@ from numpy import nan
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_bool, v_offset, v_pos_default, v_series, v_talib
try:
from numba import njit
@@ -59,16 +59,17 @@ def ema(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
presma = bool(presma) if isinstance(presma, bool) else True
mode_tal = bool(talib) if isinstance(talib, bool) else True
close = verify_series(close, length)
offset = get_offset(offset)
adjust = kwargs.pop("adjust", False)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
mode_tal = v_talib(talib)
presma = v_bool(presma, True)
offset = v_offset(offset)
adjust = kwargs.setdefault("adjust", False)
# Calculate
if Imports["talib"] and mode_tal:
from talib import EMA
+7 -5
View File
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import fibonacci, get_offset, verify_series, weights
from pandas_ta.utils import fibonacci, v_ascending, v_offset
from pandas_ta.utils import v_pos_default, v_series, weights
def fwma(
@@ -29,14 +30,15 @@ def fwma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
asc = asc if asc else True
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
asc = v_ascending(asc)
offset = v_offset(offset)
# Calculate
fibs = fibonacci(n=length, weighted=True)
fwma = close.rolling(length, min_periods=length) \
+9 -8
View File
@@ -3,7 +3,7 @@ from numpy import nan
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.ma import ma
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_mamode, v_offset, v_pos_default, v_series
def hilo(
@@ -47,18 +47,19 @@ def hilo(
pd.DataFrame: HILO (line), HILOl (long), HILOs (short) columns.
"""
# Validate
high_length = int(high_length) if high_length and high_length > 0 else 13
low_length = int(low_length) if low_length and low_length > 0 else 21
mamode = mamode.lower() if isinstance(mamode, str) else "sma"
high_length = v_pos_default(high_length, 13)
low_length = v_pos_default(low_length, 21)
_length = max(high_length, low_length)
high = verify_series(high, _length)
low = verify_series(low, _length)
close = verify_series(close, _length)
offset = get_offset(offset)
high = v_series(high, _length)
low = v_series(low, _length)
close = v_series(close, _length)
if high is None or low is None or close is None:
return
mamode = v_mamode(mamode, "sma")
offset = v_offset(offset)
# Calculate
m = close.size
hilo = Series(nan, index=close.index)
+4 -4
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_series
def hl2(
@@ -27,9 +27,9 @@ def hl2(
pd.Series: New feature generated.
"""
# Validate
high = verify_series(high)
low = verify_series(low)
offset = get_offset(offset)
high = v_series(high)
low = v_series(low)
offset = v_offset(offset)
# Calculate
avg = 0.5 * (high.values + low.values)
+6 -6
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_series, v_talib
def hlc3(
@@ -29,11 +29,11 @@ def hlc3(
pd.Series: New feature generated.
"""
# Validate
high = verify_series(high)
low = verify_series(low)
close = verify_series(close)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
high = v_series(high)
low = v_series(low)
close = v_series(close)
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
+5 -4
View File
@@ -2,7 +2,7 @@
from numpy import sqrt
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
from .wma import wma
@@ -31,13 +31,14 @@ def hma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
offset = v_offset(offset)
# Calculate
half_length = int(length / 2)
sqrt_length = int(sqrt(length))
+7 -8
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_series
def hwma(
@@ -15,8 +15,7 @@ def hwma(
moving average by the Holt-Winter method; the three parameters should
be selected to obtain a forecast.
This version has been implemented for Pandas TA by rengel8 based
on a publication for MetaTrader 5.
Coded by rengel8 based on a publication for MetaTrader 5.
Sources:
https://www.mql5.com/en/code/20856
@@ -36,11 +35,11 @@ def hwma(
pd.Series: hwma
"""
# Validate
na = float(na) if na and na > 0 and na < 1 else 0.2
nb = float(nb) if nb and nb > 0 and nb < 1 else 0.1
nc = float(nc) if nc and nc > 0 and nc < 1 else 0.1
close = verify_series(close)
offset = get_offset(offset)
close = v_series(close)
na = float(na) if isinstance(na, float) and 0 < na < 1 else 0.2
nb = float(nb) if isinstance(nb, float) and 0 < nb < 1 else 0.1
nc = float(nc) if isinstance(nc, float) and 0 < nc < 1 else 0.1
offset = v_offset(offset)
# Calculate
last_a = last_v = 0
+11 -10
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import date_range, DataFrame, RangeIndex, Timedelta, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
from .midprice import midprice
@@ -40,20 +40,21 @@ def ichimoku(
For the forward looking period: spanA and spanB columns
"""
# Validate
tenkan = int(tenkan) if tenkan and tenkan > 0 else 9
kijun = int(kijun) if kijun and kijun > 0 else 26
senkou = int(senkou) if senkou and senkou > 0 else 52
tenkan = v_pos_default(tenkan, 9)
kijun = v_pos_default(kijun, 26)
senkou = v_pos_default(senkou, 52)
_length = max(tenkan, kijun, senkou)
high = verify_series(high, _length)
low = verify_series(low, _length)
close = verify_series(close, _length)
offset = get_offset(offset)
if not kwargs.get("lookahead", True):
include_chikou = False
high = v_series(high, _length)
low = v_series(low, _length)
close = v_series(close, _length)
if high is None or low is None or close is None:
return None, None
offset = v_offset(offset)
if not kwargs.get("lookahead", True):
include_chikou = False
# Calculate
tenkan_sen = midprice(high=high, low=low, length=tenkan)
kijun_sen = midprice(high=high, low=low, length=kijun)
+7 -5
View File
@@ -4,7 +4,7 @@ from numpy import average, log, nan, sqrt, zeros_like
from numpy import power as np_power
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_float, v_offset, v_pos_default, v_series
def jma(
@@ -35,13 +35,15 @@ def jma(
pd.Series: New feature generated.
"""
# Validate
_length = int(length) if length and length > 0 else 7
phase = float(phase) if phase and phase != 0 else 0
close = verify_series(close, _length)
offset = get_offset(offset)
_length = v_pos_default(length, 7)
close = v_series(close, _length)
if close is None:
return
phase = v_float(phase, 0.0)
offset = v_offset(offset)
# Calculate
jma = zeros_like(close)
volty = zeros_like(close)
+11 -18
View File
@@ -3,7 +3,8 @@ from numpy import nan
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.ma import ma
from pandas_ta.utils import get_drift, get_offset, non_zero_range, verify_series
from pandas_ta.utils import non_zero_range, v_drift, v_mamode
from pandas_ta.utils import v_offset, v_pos_default, v_series
def kama(
@@ -30,9 +31,7 @@ def kama(
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'
mamode (str): See ``help(ta.ma)``. Default: 'sma'
drift (int): The difference period. Default: 1
offset (int): How many periods to offset the result. Default: 0
@@ -44,24 +43,18 @@ def kama(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
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)
length = v_pos_default(length, 10)
fast = v_pos_default(fast, 2)
slow = v_pos_default(slow, 30)
close = v_series(close, max(fast, slow, length))
if close is None:
return
mamode = v_mamode(mamode, "sma")
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
def weight(length: int) -> float:
return 2 / (length + 1)
+11 -8
View File
@@ -4,7 +4,8 @@ from numpy.version import version
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, strided_window, verify_series
from pandas_ta.utils import strided_window, v_offset, v_pos_default
from pandas_ta.utils import v_series, v_talib
def linreg(
@@ -45,19 +46,21 @@ def linreg(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 14
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 14)
close = v_series(close, length)
if close is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
angle = kwargs.pop("angle", False)
intercept = kwargs.pop("intercept", False)
degrees = kwargs.pop("degrees", False)
r = kwargs.pop("r", False)
slope = kwargs.pop("slope", False)
tsf = kwargs.pop("tsf", False)
mode_tal = bool(talib) if isinstance(talib, bool) else True
if close is None:
return
# Calculate
np_close = close.values
+6 -5
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
def mcgd(
@@ -37,14 +37,15 @@ def mcgd(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
c = float(c) if c and 0 < c <= 1 else 1
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
c = float(c) if isinstance(c, float) and 0 < c <= 1 else 1
offset = v_offset(offset)
# Calculate
close = close.copy()
+6 -5
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
def midpoint(
@@ -28,18 +28,19 @@ def midpoint(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 2
length = v_pos_default(length, 2)
if "min_periods" in kwargs and kwargs["min_periods"] is not None:
min_periods = int(kwargs["min_periods"])
else:
min_periods = length
close = verify_series(close, max(length, min_periods))
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
close = v_series(close, max(length, min_periods))
if close is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import MIDPOINT
+7 -6
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
def midprice(
@@ -29,20 +29,21 @@ def midprice(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 2
length = v_pos_default(length, 2)
if "min_periods" in kwargs and kwargs["min_periods"] is not None:
min_periods = int(kwargs["min_periods"])
else:
min_periods = length
_length = max(length, min_periods)
high = verify_series(high, _length)
low = verify_series(low, _length)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
high = v_series(high, _length)
low = v_series(low, _length)
if high is None or low is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import MIDPRICE
+6 -6
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_series
def ohlc4(
@@ -29,11 +29,11 @@ def ohlc4(
pd.Series: New feature generated.
"""
# Validate
open_ = verify_series(open_)
high = verify_series(high)
low = verify_series(low)
close = verify_series(close)
offset = get_offset(offset)
open_ = v_series(open_)
high = v_series(high)
low = v_series(low)
close = v_series(close)
offset = v_offset(offset)
# Calculate
avg = 0.25 * (open_.values + high.values + low.values + close.values)
+7 -5
View File
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, pascals_triangle, verify_series, weights
from pandas_ta.utils import pascals_triangle, v_offset
from pandas_ta.utils import v_ascending, v_pos_default, v_series, weights
def pwma(
@@ -29,14 +30,15 @@ def pwma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
asc = asc if asc else True
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
asc = v_ascending(asc)
offset = v_offset(offset)
# Calculate
triangle = pascals_triangle(n=length - 1, weighted=True)
pwma = close.rolling(length, min_periods=length) \
+6 -5
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
def rma(
@@ -30,14 +30,15 @@ def rma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
alpha = (1.0 / length) if length > 0 else 0.5
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
alpha = (1.0 / length) if length > 0 else 0.5
offset = v_offset(offset)
# Calculate
rma = close.ewm(alpha=alpha, min_periods=length).mean()
+5 -4
View File
@@ -2,7 +2,7 @@
from numpy import pi, sin
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series, weights
from pandas_ta.utils import v_offset, v_pos_default, v_series, weights
def sinwma(
@@ -31,13 +31,14 @@ def sinwma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 14
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 14)
close = v_series(close, length)
if close is None:
return
offset = v_offset(offset)
# Calculate
sines = Series([sin((i + 1) * pi / (length + 1))
for i in range(0, length)])
+7 -5
View File
@@ -3,7 +3,8 @@ from numpy import convolve, ndarray, ones
from pandas import Series
from pandas_ta._typing import Array, DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, np_prepend, verify_series
from pandas_ta.utils import np_prepend, v_offset, v_pos_default
from pandas_ta.utils import v_series, v_talib
try:
@@ -61,18 +62,19 @@ def sma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
length = v_pos_default(length, 10)
if "min_periods" in kwargs and kwargs["min_periods"] is not None:
min_periods = int(kwargs["min_periods"])
else:
min_periods = length
close = verify_series(close, max(length, min_periods))
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
close = v_series(close, max(length, min_periods))
if close is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import SMA
+8 -6
View File
@@ -3,7 +3,8 @@ from numpy import nan
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.ma import ma
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_mamode, v_offset, v_pos_default
from pandas_ta.utils import v_series, v_talib
def smma(
@@ -43,19 +44,20 @@ def smma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 7
length = v_pos_default(length, 7)
if "min_periods" in kwargs and kwargs["min_periods"] is not None:
min_periods = int(kwargs["min_periods"])
else:
min_periods = length
close = verify_series(close, max(length, min_periods))
offset = get_offset(offset)
mamode = mamode.lower() if isinstance(mamode, str) else "sma"
mode_tal = bool(talib) if isinstance(talib, bool) else True
close = v_series(close, max(length, min_periods))
if close is None:
return
mamode = v_mamode(mamode, "sma")
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
m = close.size
smma = close.copy()
+8 -7
View File
@@ -2,7 +2,7 @@
from numpy import copy, cos, exp
from pandas import Series
from pandas_ta._typing import Array, DictLike, Int, IntFloat
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_bool, v_offset, v_pos_default, v_series
try:
@@ -86,16 +86,17 @@ def ssf(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if isinstance(length, int) and length > 0 else 20
everget = bool(everget) if isinstance(everget, bool) else False
pi = float(pi) if isinstance(pi, float) and pi > 0 else 3.14159
sqrt2 = float(sqrt2) if isinstance(sqrt2, float) and sqrt2 > 0 else 1.414
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 20)
close = v_series(close, length)
if close is None:
return
pi = v_pos_default(pi, 3.14159)
sqrt2 = v_pos_default(sqrt2, 1.414)
everget = v_bool(everget, False)
offset = v_offset(offset)
# Calculate
np_close = close.values
if everget:
+7 -6
View File
@@ -2,7 +2,7 @@
from numpy import copy, cos, exp
from pandas import Series
from pandas_ta._typing import Array, DictLike, Int, IntFloat
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
try:
from numba import njit
@@ -70,15 +70,16 @@ def ssf3(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if isinstance(length, int) and length > 0 else 20
pi = float(pi) if isinstance(pi, float) and pi > 0 else 3.14159
sqrt3 = float(sqrt3) if isinstance(sqrt3, float) and sqrt3 > 0 else 1.732
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 20)
close = v_series(close, length)
if close is None:
return
pi = v_pos_default(pi, 3.14159)
sqrt3 = v_pos_default(sqrt3, 1.732)
offset = v_offset(offset)
# Calculate
np_close = close.values
ssf = np_ssf3(np_close, length, pi, sqrt3)
+9 -10
View File
@@ -3,7 +3,7 @@ from numpy import nan
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.overlap import hl2
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
from pandas_ta.volatility import atr
@@ -39,19 +39,18 @@ def supertrend(
SUPERTl (long), SUPERTs (short) columns.
"""
# Validate
length = int(length) if isinstance(length, int) and length > 0 else 7
if isinstance(multiplier, float) and multiplier > 0:
multiplier = float(multiplier)
else:
multiplier = 3.0
high = verify_series(high, length)
low = verify_series(low, length)
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 7)
high = v_series(high, length)
low = v_series(low, length)
close = v_series(close, length)
if high is None or low is None or close is None:
return
multiplier = v_pos_default(multiplier, 3.0)
offset = v_offset(offset)
# Calculate
m = close.size
dir_, trend = [1] * m, [0] * m
+6 -4
View File
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, symmetric_triangle, verify_series, weights
from pandas_ta.utils import symmetric_triangle, v_offset, v_pos_default
from pandas_ta.utils import v_series, weights
def swma(
@@ -31,13 +32,14 @@ def swma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
offset = v_offset(offset)
# Calculate
triangle = symmetric_triangle(length, weighted=True)
swma = close.rolling(length, min_periods=length) \
+7 -6
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
from .ema import ema
@@ -36,15 +36,16 @@ def t3(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
a = float(a) if a and a > 0 and a < 1 else 0.7
close = verify_series(close, length)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
a = float(a) if isinstance(a, float) and 0 < a < 1 else 0.7
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import T3
+6 -5
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
from .ema import ema
@@ -34,14 +34,15 @@ def tema(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
close = verify_series(close, length)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import TEMA
+6 -5
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series, v_talib
from .sma import sma
@@ -36,14 +36,15 @@ def trima(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
close = verify_series(close, length)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import TRIMA
+6 -5
View File
@@ -2,7 +2,7 @@
from numpy import nan
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_drift, get_offset, verify_series
from pandas_ta.utils import v_drift, v_offset, v_pos_default, v_series
def vidya(
@@ -40,14 +40,15 @@ def vidya(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 14
close = verify_series(close, length)
drift = get_drift(drift)
offset = get_offset(offset)
length = v_pos_default(length, 14)
close = v_series(close, length)
if close is None:
return
drift = v_drift(drift)
offset = v_offset(offset)
# Calculate
m = close.size
alpha = 2 / (length + 1)
+10 -9
View File
@@ -2,7 +2,7 @@
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int, List
from pandas_ta.overlap import hlc3
from pandas_ta.utils import get_offset, is_datetime_ordered, verify_series
from pandas_ta.utils import v_datetime_ordered, v_list, v_offset, v_series
def vwap(
@@ -47,22 +47,23 @@ def vwap(
pd.DataFrame: New feature generated.
"""
# Validate
high = verify_series(high)
low = verify_series(low)
close = verify_series(close)
volume = verify_series(volume)
high = v_series(high)
low = v_series(low)
close = v_series(close)
volume = v_series(volume)
bands = v_list(bands)
offset = v_offset(offset)
if anchor and isinstance(anchor, str) and len(anchor) >= 1:
anchor = anchor.upper()
else:
anchor = "D"
bands = bands if isinstance(bands, list) and len(bands) else []
offset = get_offset(offset)
typical_price = hlc3(high=high, low=low, close=close)
if not is_datetime_ordered(volume):
if not v_datetime_ordered(volume):
_s = "[!] VWAP volume series is not datetime ordered."
print(f"{_s} Results may not be as expected.")
if not is_datetime_ordered(typical_price):
if not v_datetime_ordered(typical_price):
_s = "[!] VWAP price series is not datetime ordered."
print(f"{_s} Results may not be as expected.")
+6 -5
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.overlap import sma
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
def vwma(
@@ -30,14 +30,15 @@ def vwma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
close = verify_series(close, length)
volume = verify_series(volume, length)
offset = get_offset(offset)
length = v_pos_default(length, 10)
close = v_series(close, length)
volume = v_series(volume, length)
if close is None or volume is None:
return
offset = v_offset(offset)
# Calculate
pv = close * volume
vwma = sma(close=pv, length=length) / sma(close=volume, length=length)
+6 -6
View File
@@ -2,7 +2,7 @@
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_series, v_talib
def wcp(
@@ -33,11 +33,11 @@ def wcp(
pd.Series: New feature generated.
"""
# Validate
high = verify_series(high)
low = verify_series(low)
close = verify_series(close)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
high = v_series(high)
low = v_series(low)
close = v_series(close)
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
+8 -6
View File
@@ -3,7 +3,8 @@ from numpy import arange, dot
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.maps import Imports
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_ascending, v_offset, v_pos_default
from pandas_ta.utils import v_series, v_talib
def wma(
@@ -35,15 +36,16 @@ def wma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
asc = asc if asc else True
close = verify_series(close, length)
offset = get_offset(offset)
mode_tal = bool(talib) if isinstance(talib, bool) else True
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
asc = v_ascending(asc)
mode_tal = v_talib(talib)
offset = v_offset(offset)
# Calculate
if Imports["talib"] and mode_tal:
from talib import WMA
+6 -7
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_mamode, v_offset, v_pos_default, v_series
from .dema import dema
from .ema import ema
from .fwma import fwma
@@ -87,14 +87,15 @@ def zlma(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
mamode = mamode.lower() if isinstance(mamode, str) else "ema"
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
mamode = v_mamode(mamode, "ema")
offset = v_offset(offset)
# Calculate
lag = int(0.5 * (length - 1))
close_ = 2 * close - close.shift(lag)
@@ -102,8 +103,6 @@ def zlma(
kwargs.update({"close": close_})
kwargs.update({"length": length})
zlma = _ma(mamode, **kwargs)
# Offset
+3 -3
View File
@@ -2,7 +2,7 @@
from numpy import log, seterr
from pandas import DataFrame, Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_series
def drawdown(
@@ -29,8 +29,8 @@ def drawdown(
pd.DataFrame: drawdown, drawdown percent, drawdown log columns
"""
# Validate
close = verify_series(close)
offset = get_offset(offset)
close = v_series(close)
offset = v_offset(offset)
# Calculate
max_close = close.cummax()
+6 -8
View File
@@ -2,7 +2,7 @@
from pandas import Series
from numpy import log, nan, roll
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_bool, v_offset, v_pos_default, v_series
def log_return(
@@ -32,17 +32,15 @@ def log_return(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 1
if cumulative is not None and cumulative:
cumulative = bool(cumulative)
else:
cumulative = False
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 1)
close = v_series(close, length)
if close is None:
return
cumulative = v_bool(cumulative, False)
offset = v_offset(offset)
# Calculate
np_close = close.values
if cumulative:
+6 -8
View File
@@ -2,7 +2,7 @@
from numpy import nan, roll
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_bool, v_offset, v_pos_default, v_series
def percent_return(
@@ -31,17 +31,15 @@ def percent_return(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 1
if cumulative is not None and cumulative:
cumulative = bool(cumulative)
else:
cumulative = False
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 1)
close = v_series(close, length)
if close is None:
return
cumulative = v_bool(cumulative, False)
offset = v_offset(offset)
# Calculate
np_close = close.values
if cumulative:
+6 -5
View File
@@ -2,7 +2,7 @@
from numpy import log
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
def entropy(
@@ -32,14 +32,15 @@ def entropy(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 10
base = float(base) if base and base > 0 else 2.0
close = verify_series(close, length)
offset = get_offset(offset)
length = v_pos_default(length, 10)
close = v_series(close, length)
if close is None:
return
base = v_pos_default(base, 2.0)
offset = v_offset(offset)
# Calculate
p = close / close.rolling(length).sum()
entropy = (-p * log(p) / log(base)).rolling(length).sum()
+7 -5
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import v_offset, v_pos_default, v_series
def kurtosis(
@@ -25,15 +25,17 @@ def kurtosis(
pd.Series: New feature generated.
"""
# Validate
length = int(length) if length and length > 0 else 30
length = v_pos_default(length, 30)
if "min_periods" in kwargs and kwargs["min_periods"] is not None:
min_periods = int(kwargs["min_periods"])
else:
min_periods = length
close = verify_series(close, max(length, min_periods))
offset = get_offset(offset)
close = v_series(close, max(length, min_periods))
if close is None: return
if close is None:
return
offset = v_offset(offset)
# Calculate
kurtosis = close.rolling(length, min_periods=min_periods).kurt()

Some files were not shown because too many files have changed in this diff Show More