diff --git a/pandas_ta/statistics/entropy.py b/pandas_ta/statistics/entropy.py index 27f33fd..11c74a0 100644 --- a/pandas_ta/statistics/entropy.py +++ b/pandas_ta/statistics/entropy.py @@ -4,7 +4,35 @@ from pandas_ta.utils import get_offset, verify_series def entropy(close, length=None, base=None, offset=None, **kwargs): - """Indicator: Entropy (ENTP)""" + """Entropy (ENTP) + + Introduced by Claude Shannon in 1948, entropy measures the unpredictability + of the data, or equivalently, of its average information. A die has higher + entropy (p=1/6) versus a coin (p=1/2). + + Sources: + https://en.wikipedia.org/wiki/Entropy_(information_theory) + + Calculation: + Default Inputs: + length=10, base=2 + + P = close / SUM(close, length) + E = SUM(-P * npLog(P) / npLog(base), length) + + Args: + close (pd.Series): Series of 'close's + length (int): It's period. Default: 10 + base (float): Logarithmic Base. Default: 2 + 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 = int(length) if length and length > 0 else 10 base = float(base) if base and base > 0 else 2.0 @@ -32,35 +60,3 @@ def entropy(close, length=None, base=None, offset=None, **kwargs): entropy.category = "statistics" return entropy - - -entropy.__doc__ = \ -"""Entropy (ENTP) - -Introduced by Claude Shannon in 1948, entropy measures the unpredictability -of the data, or equivalently, of its average information. A die has higher -entropy (p=1/6) versus a coin (p=1/2). - -Sources: - https://en.wikipedia.org/wiki/Entropy_(information_theory) - -Calculation: - Default Inputs: - length=10, base=2 - - P = close / SUM(close, length) - E = SUM(-P * npLog(P) / npLog(base), length) - -Args: - close (pd.Series): Series of 'close's - length (int): It's period. Default: 10 - base (float): Logarithmic Base. Default: 2 - 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. -""" diff --git a/pandas_ta/statistics/kurtosis.py b/pandas_ta/statistics/kurtosis.py index beaeeb7..d5641f8 100644 --- a/pandas_ta/statistics/kurtosis.py +++ b/pandas_ta/statistics/kurtosis.py @@ -3,7 +3,27 @@ from pandas_ta.utils import get_offset, verify_series def kurtosis(close, length=None, offset=None, **kwargs): - """Indicator: Kurtosis""" + """Rolling Kurtosis + + Calculates the Kurtosis over a rolling period. + + Calculation: + Default Inputs: + length=30 + KURTOSIS = close.rolling(length).kurt() + + Args: + close (pd.Series): Series of 'close's + length (int): It's period. Default: 30 + 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 = int(length) if length and length > 0 else 30 min_periods = int(kwargs["min_periods"]) if "min_periods" in kwargs and kwargs["min_periods"] is not None else length @@ -30,27 +50,3 @@ def kurtosis(close, length=None, offset=None, **kwargs): kurtosis.category = "statistics" return kurtosis - - -kurtosis.__doc__ = \ -"""Rolling Kurtosis - -Sources: - -Calculation: - Default Inputs: - length=30 - KURTOSIS = close.rolling(length).kurt() - -Args: - close (pd.Series): Series of 'close's - length (int): It's period. Default: 30 - 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. -""" diff --git a/pandas_ta/statistics/mad.py b/pandas_ta/statistics/mad.py index 1d6a379..b23462e 100644 --- a/pandas_ta/statistics/mad.py +++ b/pandas_ta/statistics/mad.py @@ -4,7 +4,27 @@ from pandas_ta.utils import get_offset, verify_series def mad(close, length=None, offset=None, **kwargs): - """Indicator: Mean Absolute Deviation""" + """Rolling Mean Absolute Deviation + + Calculates the Mean Absolute Deviation over a rolling period. + + Calculation: + Default Inputs: + length=30 + mad = close.rolling(length).mad() + + Args: + close (pd.Series): Series of 'close's + length (int): It's period. Default: 30 + 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 = int(length) if length and length > 0 else 30 min_periods = int(kwargs["min_periods"]) if "min_periods" in kwargs and kwargs["min_periods"] is not None else length @@ -35,27 +55,3 @@ def mad(close, length=None, offset=None, **kwargs): mad.category = "statistics" return mad - - -mad.__doc__ = \ -"""Rolling Mean Absolute Deviation - -Sources: - -Calculation: - Default Inputs: - length=30 - mad = close.rolling(length).mad() - -Args: - close (pd.Series): Series of 'close's - length (int): It's period. Default: 30 - 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. -""" diff --git a/pandas_ta/statistics/median.py b/pandas_ta/statistics/median.py index 9190b05..e650bfd 100644 --- a/pandas_ta/statistics/median.py +++ b/pandas_ta/statistics/median.py @@ -3,7 +3,30 @@ from pandas_ta.utils import get_offset, verify_series def median(close, length=None, offset=None, **kwargs): - """Indicator: Median""" + """Rolling Median + + Calculates the Median over a rolling period. Sibling of a Simple Moving Average. + + Sources: + https://www.incrediblecharts.com/indicators/median_price.php + + Calculation: + Default Inputs: + length=30 + MEDIAN = close.rolling(length).median() + + Args: + close (pd.Series): Series of 'close's + length (int): It's period. Default: 30 + 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 = int(length) if length and length > 0 else 30 min_periods = int(kwargs["min_periods"]) if "min_periods" in kwargs and kwargs["min_periods"] is not None else length @@ -30,30 +53,3 @@ def median(close, length=None, offset=None, **kwargs): median.category = "statistics" return median - - -median.__doc__ = \ -"""Rolling Median - -Rolling Median of over 'n' periods. Sibling of a Simple Moving Average. - -Sources: - https://www.incrediblecharts.com/indicators/median_price.php - -Calculation: - Default Inputs: - length=30 - MEDIAN = close.rolling(length).median() - -Args: - close (pd.Series): Series of 'close's - length (int): It's period. Default: 30 - 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. -""" diff --git a/pandas_ta/statistics/quantile.py b/pandas_ta/statistics/quantile.py index 70a1d88..fd01af2 100644 --- a/pandas_ta/statistics/quantile.py +++ b/pandas_ta/statistics/quantile.py @@ -3,7 +3,28 @@ from pandas_ta.utils import get_offset, verify_series def quantile(close, length=None, q=None, offset=None, **kwargs): - """Indicator: Quantile""" + """Rolling Quantile + + Calculates the Quantile over a rolling period. + + Calculation: + Default Inputs: + length=30, q=0.5 + QUANTILE = close.rolling(length).quantile(q) + + Args: + close (pd.Series): Series of 'close's + length (int): It's period. Default: 30 + q (float): The quantile. Default: 0.5 + 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 = int(length) if length and length > 0 else 30 min_periods = int(kwargs["min_periods"]) if "min_periods" in kwargs and kwargs["min_periods"] is not None else length @@ -31,28 +52,3 @@ def quantile(close, length=None, q=None, offset=None, **kwargs): quantile.category = "statistics" return quantile - - -quantile.__doc__ = \ -"""Rolling Quantile - -Sources: - -Calculation: - Default Inputs: - length=30, q=0.5 - QUANTILE = close.rolling(length).quantile(q) - -Args: - close (pd.Series): Series of 'close's - length (int): It's period. Default: 30 - q (float): The quantile. Default: 0.5 - 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. -""" diff --git a/pandas_ta/statistics/skew.py b/pandas_ta/statistics/skew.py index 79d0212..4af7b37 100644 --- a/pandas_ta/statistics/skew.py +++ b/pandas_ta/statistics/skew.py @@ -3,7 +3,27 @@ from pandas_ta.utils import get_offset, verify_series def skew(close, length=None, offset=None, **kwargs): - """Indicator: Skew""" + """Rolling Skew + + Calculates the Skew over a rolling period. + + Calculation: + Default Inputs: + length=30 + SKEW = close.rolling(length).skew() + + Args: + close (pd.Series): Series of 'close's + length (int): It's period. Default: 30 + 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 = int(length) if length and length > 0 else 30 min_periods = int(kwargs["min_periods"]) if "min_periods" in kwargs and kwargs["min_periods"] is not None else length @@ -30,27 +50,3 @@ def skew(close, length=None, offset=None, **kwargs): skew.category = "statistics" return skew - - -skew.__doc__ = \ -"""Rolling Skew - -Sources: - -Calculation: - Default Inputs: - length=30 - SKEW = close.rolling(length).skew() - -Args: - close (pd.Series): Series of 'close's - length (int): It's period. Default: 30 - 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. -""" diff --git a/pandas_ta/statistics/stdev.py b/pandas_ta/statistics/stdev.py index f0e6780..013144a 100644 --- a/pandas_ta/statistics/stdev.py +++ b/pandas_ta/statistics/stdev.py @@ -6,7 +6,34 @@ from pandas_ta.utils import get_offset, verify_series def stdev(close, length=None, ddof=None, talib=None, offset=None, **kwargs): - """Indicator: Standard Deviation""" + """Rolling Standard Deviation + + Calculates the Standard Deviation over a rolling period. + + Calculation: + Default Inputs: + length=30 + VAR = Variance + STDEV = variance(close, length).apply(np.sqrt) + + Args: + close (pd.Series): Series of 'close's + length (int): It's period. Default: 30 + ddof (int): Delta Degrees of Freedom. + The divisor used in calculations is N - ddof, + where N represents the number of elements. The 'talib' argument + must be false for 'ddof' to work. Default: 1 + talib (bool): If TA Lib is installed and talib is True, Returns the TA Lib + version. TA Lib does not have a 'ddof' argument. Default: True + 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 = int(length) if isinstance(length, int) and length > 0 else 30 ddof = int(ddof) if isinstance(ddof, int) and ddof >= 0 and ddof < length else 1 @@ -38,34 +65,3 @@ def stdev(close, length=None, ddof=None, talib=None, offset=None, **kwargs): stdev.category = "statistics" return stdev - - -stdev.__doc__ = \ -"""Rolling Standard Deviation - -Sources: - -Calculation: - Default Inputs: - length=30 - VAR = Variance - STDEV = variance(close, length).apply(np.sqrt) - -Args: - close (pd.Series): Series of 'close's - length (int): It's period. Default: 30 - ddof (int): Delta Degrees of Freedom. - The divisor used in calculations is N - ddof, - where N represents the number of elements. The 'talib' argument - must be false for 'ddof' to work. Default: 1 - talib (bool): If TA Lib is installed and talib is True, Returns the TA Lib - version. TA Lib does not have a 'ddof' argument. Default: True - 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. -""" diff --git a/pandas_ta/statistics/tos_stdevall.py b/pandas_ta/statistics/tos_stdevall.py index 3c1186a..796e729 100644 --- a/pandas_ta/statistics/tos_stdevall.py +++ b/pandas_ta/statistics/tos_stdevall.py @@ -8,8 +8,45 @@ from .stdev import stdev as stdev from pandas_ta.utils import get_offset, verify_series def tos_stdevall(close, length=None, stds=None, ddof=None, offset=None, **kwargs): - """Indicator: TD Ameritrade's Think or Swim Standard Deviation All""" - # Validate Arguments + """TD Ameritrade's Think or Swim Standard Deviation All (TOS_STDEV) + + A port of TD Ameritrade's Think or Swim Standard Deviation All indicator which + returns the standard deviation of data for the entire plot or for the interval + of the last bars defined by the length parameter. + + Sources: + https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Statistical/StDevAll + + Calculation: + Default Inputs: + length=None (All), stds=[1, 2, 3], ddof=1 + LR = Linear Regression + STDEV = Standard Deviation + + LR = LR(close, length) + STDEV = STDEV(close, length, ddof) + for level in stds: + LOWER = LR - level * STDEV + UPPER = LR + level * STDEV + + Args: + close (pd.Series): Series of 'close's + length (int): Bars from current bar. Default: None + stds (list): List of Standard Deviations in increasing order from the + central Linear Regression line. Default: [1,2,3] + ddof (int): Delta Degrees of Freedom. + The divisor used in calculations is N - ddof, + where N represents the number of elements. Default: 1 + 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.DataFrame: Central LR, Pairs of Lower and Upper LR Lines based on + mulitples of the standard deviation. Default: returns 7 columns. + """ # Validate Arguments stds = stds if isinstance(stds, list) and len(stds) > 0 else [1, 2, 3] if min(stds) <= 0: return if not all(i < j for i, j in zip(stds, stds[1:])): @@ -62,45 +99,3 @@ def tos_stdevall(close, length=None, stds=None, ddof=None, offset=None, **kwargs df.category = "statistics" return df - - -tos_stdevall.__doc__ = \ -"""TD Ameritrade's Think or Swim Standard Deviation All (TOS_STDEV) - -A port of TD Ameritrade's Think or Swim Standard Deviation All indicator which -returns the standard deviation of data for the entire plot or for the interval -of the last bars defined by the length parameter. - -Sources: - https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Statistical/StDevAll - -Calculation: - Default Inputs: - length=None (All), stds=[1, 2, 3], ddof=1 - LR = Linear Regression - STDEV = Standard Deviation - - LR = LR(close, length) - STDEV = STDEV(close, length, ddof) - for level in stds: - LOWER = LR - level * STDEV - UPPER = LR + level * STDEV - -Args: - close (pd.Series): Series of 'close's - length (int): Bars from current bar. Default: None - stds (list): List of Standard Deviations in increasing order from the - central Linear Regression line. Default: [1,2,3] - ddof (int): Delta Degrees of Freedom. - The divisor used in calculations is N - ddof, - where N represents the number of elements. Default: 1 - 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.DataFrame: Central LR, Pairs of Lower and Upper LR Lines based on - mulitples of the standard deviation. Default: returns 7 columns. -""" diff --git a/pandas_ta/statistics/variance.py b/pandas_ta/statistics/variance.py index c964c9f..1216f2d 100644 --- a/pandas_ta/statistics/variance.py +++ b/pandas_ta/statistics/variance.py @@ -4,7 +4,33 @@ from pandas_ta.utils import get_offset, verify_series def variance(close, length=None, ddof=None, talib=None, offset=None, **kwargs): - """Indicator: Variance""" + """Rolling Variance + + Calculates the Variance over a rolling period. + + Calculation: + Default Inputs: + length=30 + VARIANCE = close.rolling(length).var() + + Args: + close (pd.Series): Series of 'close's + length (int): It's period. Default: 30 + ddof (int): Delta Degrees of Freedom. + The divisor used in calculations is N - ddof, + where N represents the number of elements. The 'talib' argument + must be false for 'ddof' to work. Default: 1 + talib (bool): If TA Lib is installed and talib is True, Returns the TA Lib + version. TA Lib does not have a 'ddof' argument. Default: True + 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 = int(length) if isinstance(length, int) and length > 1 else 30 ddof = int(ddof) if isinstance(ddof, int) and ddof >= 0 and ddof < length else 1 @@ -37,33 +63,3 @@ def variance(close, length=None, ddof=None, talib=None, offset=None, **kwargs): variance.category = "statistics" return variance - - -variance.__doc__ = \ -"""Rolling Variance - -Sources: - -Calculation: - Default Inputs: - length=30 - VARIANCE = close.rolling(length).var() - -Args: - close (pd.Series): Series of 'close's - length (int): It's period. Default: 30 - ddof (int): Delta Degrees of Freedom. - The divisor used in calculations is N - ddof, - where N represents the number of elements. The 'talib' argument - must be false for 'ddof' to work. Default: 1 - talib (bool): If TA Lib is installed and talib is True, Returns the TA Lib - version. TA Lib does not have a 'ddof' argument. Default: True - 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. -""" diff --git a/pandas_ta/statistics/zscore.py b/pandas_ta/statistics/zscore.py index 26de34b..8aa0fa3 100644 --- a/pandas_ta/statistics/zscore.py +++ b/pandas_ta/statistics/zscore.py @@ -5,7 +5,32 @@ from pandas_ta.utils import get_offset, verify_series def zscore(close, length=None, std=None, offset=None, **kwargs): - """Indicator: Z Score""" + """Rolling Z Score + + Calculates the Z Score over a rolling period. + + Calculation: + Default Inputs: + length=30, std=1 + SMA = Simple Moving Average + STDEV = Standard Deviation + std = std * STDEV(close, length) + mean = SMA(close, length) + ZSCORE = (close - mean) / std + + Args: + close (pd.Series): Series of 'close's + length (int): It's period. Default: 30 + std (float): It's period. Default: 1 + 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 = int(length) if length and length > 1 else 30 std = float(std) if std and std > 1 else 1 @@ -35,31 +60,3 @@ def zscore(close, length=None, std=None, offset=None, **kwargs): return zscore - -zscore.__doc__ = \ -"""Rolling Z Score - -Sources: - -Calculation: - Default Inputs: - length=30, std=1 - SMA = Simple Moving Average - STDEV = Standard Deviation - std = std * STDEV(close, length) - mean = SMA(close, length) - ZSCORE = (close - mean) / std - -Args: - close (pd.Series): Series of 'close's - length (int): It's period. Default: 30 - std (float): It's period. Default: 1 - 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. -"""