ENH bbands percent included TST DOC updated

This commit is contained in:
Kevin Johnson
2021-06-19 12:49:50 -07:00
parent bc3c5f917b
commit b6cbcefe3a
9 changed files with 1168 additions and 1161 deletions
+3 -3
View File
@@ -14,7 +14,7 @@ Pandas TA - A Technical Analysis Library in Python 3
[![Downloads](https://img.shields.io/pypi/dm/pandas_ta?style=flat)](https://pypistats.org/packages/pandas_ta)
[![Stars](https://img.shields.io/github/stars/twopirllc/pandas-ta?style=flat)](#stars)
[![Forks](https://img.shields.io/github/forks/twopirllc/pandas-ta?style=flat)](#forks)
[![Used By](https://img.shields.io/badge/used_by-138-orange.svg?style=flat)](#usedby)
[![Used By](https://img.shields.io/badge/used_by-140-orange.svg?style=flat)](#usedby)
[![Contributors](https://img.shields.io/github/contributors/twopirllc/pandas-ta?style=flat)](#contributors)
[![Issues](https://img.shields.io/github/issues-raw/twopirllc/pandas-ta?style=flat)](#issues)
[![Closed Issues](https://img.shields.io/github/issues-closed-raw/twopirllc/pandas-ta?style=flat)](#closed-issues)
@@ -110,7 +110,7 @@ $ pip install pandas_ta
Latest Version
--------------
Best choice! Version: *0.2.91b*
Best choice! Version: *0.2.92b*
```sh
$ pip install -U git+https://github.com/twopirllc/pandas-ta
```
@@ -971,7 +971,7 @@ trading account, or fund. See: ```help(ta.drawdown)```
* _ADX_ (**adx**): Added ```mamode``` with default "**RMA**" and with the same ```mamode``` options as TradingView. New argument ```lensig``` so it behaves like TradingView's builtin ADX indicator. See ```help(ta.adx)```.
* _Archer Moving Averages Trends_ (**amat**): Added ```drift``` argument and more descriptive column names.
* _Average True Range_ (**atr**): The default ```mamode``` is now "**RMA**" and with the same ```mamode``` options as TradingView. See ```help(ta.atr)```.
* _Bollinger Bands_ (**bbands**): New argument ```ddoff``` to control the Degrees of Freedom. Default is 0. See ```help(ta.bbands)```.
* _Bollinger Bands_ (**bbands**): New argument ```ddoff``` to control the Degrees of Freedom. Included BB Percent (BBP) as the final column. Default is 0. See ```help(ta.bbands)```.
* _Choppiness Index_ (**chop**): New argument ```ln``` to use Natural Logarithm (True) instead of the Standard Logarithm (False). Default is False. See ```help(ta.chop)```.
* _Chande Kroll Stop_ (**cksp**): Added ```tvmode``` with default ```True```. When ```tvmode=False```, **cksp** implements “The New Technical Trader” with default values. See ```help(ta.cksp)```.
* _Decreasing_ (**decreasing**): New argument ```strict``` checks if the series is continuously decreasing over period ```length``` with a faster calculation. Default: ```False```. The ```percent``` argument has also been added with default None. See ```help(ta.decreasing)```.
+229 -229
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+162 -162
View File
@@ -34,7 +34,7 @@
"Pandas v1.2.4\n",
"vectorbt >= v0.18.1\n",
"\n",
"Pandas TA v0.2.81b0\n",
"Pandas TA v0.2.89b0\n",
"To install the Latest Version:\n",
"$ pip install -U git+https://github.com/twopirllc/pandas-ta\n",
"\n"
@@ -451,8 +451,8 @@
"output_type": "stream",
"text": [
"[i] Downloading: SPY, QQQ\n",
"[+] SPY(7133, 7) Wednesday May 26, 2021, NYSE: 10:59:35\n",
"[+] QQQ(5591, 7) Wednesday May 26, 2021, NYSE: 10:59:37\n",
"[+] SPY(7149, 7) Saturday June 19, 2021, NYSE: 7:58:24\n",
"[+] QQQ(5607, 7) Saturday June 19, 2021, NYSE: 7:58:27\n",
"[*] Download Complete\n",
"\n"
]
@@ -473,9 +473,9 @@
"output_type": "stream",
"text": [
"[i] Downloading: AAPL, TSLA, TWTR\n",
"[+] AAPL(10200, 7) Wednesday May 26, 2021, NYSE: 10:59:39\n",
"[+] TSLA(2747, 7) Wednesday May 26, 2021, NYSE: 10:59:41\n",
"[+] TWTR(1900, 7) Wednesday May 26, 2021, NYSE: 10:59:42\n",
"[+] AAPL(10216, 7) Saturday June 19, 2021, NYSE: 7:58:30\n",
"[+] TSLA(2763, 7) Saturday June 19, 2021, NYSE: 7:58:32\n",
"[+] TWTR(1916, 7) Saturday June 19, 2021, NYSE: 7:58:34\n",
"[*] Download Complete\n",
"\n"
]
@@ -1377,41 +1377,41 @@
{
"data": {
"text/plain": [
"Run Time Wednesday May 26, 2021, NYSE: 10:59:43\n",
"Mode TEST\n",
"Strategy Buy and Hold\n",
"Direction longonly\n",
"Symbol SPY\n",
"Fees [%] 0.25\n",
"Slippage [%] 0.25\n",
"Accumulate False\n",
"Start 2005-01-03 00:00:00\n",
"End 2009-12-31 00:00:00\n",
"Duration 1259 days 00:00:00\n",
"Init. Cash 100.0\n",
"Total Profit 1.945272\n",
"Total Return [%] 1.945272\n",
"Benchmark Return [%] 2.455635\n",
"Position Coverage [%] 100.0\n",
"Max. Drawdown [%] 55.189436\n",
"Avg. Drawdown [%] 2.615867\n",
"Max. Drawdown Duration 562 days 00:00:00\n",
"Avg. Drawdown Duration 24 days 01:55:11.999999999\n",
"Num. Trades 0\n",
"Gross Exposure 1.0\n",
"Sharpe Ratio 0.163325\n",
"Sortino Ratio 0.231223\n",
"Calmar Ratio 0.010149\n",
"Annual Return [%] 0.560106\n",
"Annual Volatility [%] 28.894472\n",
"Omega Ratio 1.028442\n",
"Skew 0.426804\n",
"Kurtosis 14.956038\n",
"Tail Ratio 0.88191\n",
"Common Sense Ratio 0.88685\n",
"Value at Risk -0.022291\n",
"Alpha -0.001443\n",
"Beta 1.000002\n",
"Run Time Saturday June 19, 2021, NYSE: 7:58:39\n",
"Mode TEST\n",
"Strategy Buy and Hold\n",
"Direction longonly\n",
"Symbol SPY\n",
"Fees [%] 0.25\n",
"Slippage [%] 0.25\n",
"Accumulate False\n",
"Start 2005-01-03 00:00:00\n",
"End 2009-12-31 00:00:00\n",
"Duration 1259 days 00:00:00\n",
"Init. Cash 100.0\n",
"Total Profit 1.945272\n",
"Total Return [%] 1.945272\n",
"Benchmark Return [%] 2.455635\n",
"Position Coverage [%] 100.0\n",
"Max. Drawdown [%] 55.189436\n",
"Avg. Drawdown [%] 2.615867\n",
"Max. Drawdown Duration 562 days 00:00:00\n",
"Avg. Drawdown Duration 24 days 01:55:11.999999999\n",
"Num. Trades 0\n",
"Gross Exposure 1.0\n",
"Sharpe Ratio 0.163325\n",
"Sortino Ratio 0.231223\n",
"Calmar Ratio 0.010149\n",
"Annual Return [%] 0.560106\n",
"Annual Volatility [%] 28.894472\n",
"Omega Ratio 1.028442\n",
"Skew 0.426804\n",
"Kurtosis 14.956038\n",
"Tail Ratio 0.88191\n",
"Common Sense Ratio 0.88685\n",
"Value at Risk -0.022291\n",
"Alpha -0.001443\n",
"Beta 1.000002\n",
"dtype: object"
]
},
@@ -1459,41 +1459,41 @@
{
"data": {
"text/plain": [
"Run Time Wednesday May 26, 2021, NYSE: 10:59:44\n",
"Mode TEST\n",
"Strategy Buy and Hold\n",
"Direction longonly\n",
"Symbol AAPL\n",
"Fees [%] 0.25\n",
"Slippage [%] 0.25\n",
"Accumulate False\n",
"Start 2005-01-03 00:00:00\n",
"End 2009-12-31 00:00:00\n",
"Duration 1259 days 00:00:00\n",
"Init. Cash 100.0\n",
"Total Profit 562.60143\n",
"Total Return [%] 562.60143\n",
"Benchmark Return [%] 565.918578\n",
"Position Coverage [%] 100.0\n",
"Max. Drawdown [%] 60.866748\n",
"Avg. Drawdown [%] 6.076352\n",
"Max. Drawdown Duration 457 days 00:00:00\n",
"Avg. Drawdown Duration 22 days 17:32:18.461538461\n",
"Num. Trades 0\n",
"Gross Exposure 1.0\n",
"Sharpe Ratio 1.329387\n",
"Sortino Ratio 1.982724\n",
"Calmar Ratio 1.199638\n",
"Annual Return [%] 73.018058\n",
"Annual Volatility [%] 51.088459\n",
"Omega Ratio 1.209774\n",
"Skew -0.0376\n",
"Kurtosis 3.435275\n",
"Tail Ratio 1.037861\n",
"Common Sense Ratio 1.795687\n",
"Value at Risk -0.041247\n",
"Alpha -0.00145\n",
"Beta 1.00001\n",
"Run Time Saturday June 19, 2021, NYSE: 7:58:52\n",
"Mode TEST\n",
"Strategy Buy and Hold\n",
"Direction longonly\n",
"Symbol AAPL\n",
"Fees [%] 0.25\n",
"Slippage [%] 0.25\n",
"Accumulate False\n",
"Start 2005-01-03 00:00:00\n",
"End 2009-12-31 00:00:00\n",
"Duration 1259 days 00:00:00\n",
"Init. Cash 100.0\n",
"Total Profit 562.60143\n",
"Total Return [%] 562.60143\n",
"Benchmark Return [%] 565.918578\n",
"Position Coverage [%] 100.0\n",
"Max. Drawdown [%] 60.866748\n",
"Avg. Drawdown [%] 6.076352\n",
"Max. Drawdown Duration 457 days 00:00:00\n",
"Avg. Drawdown Duration 22 days 17:32:18.461538461\n",
"Num. Trades 0\n",
"Gross Exposure 1.0\n",
"Sharpe Ratio 1.329387\n",
"Sortino Ratio 1.982724\n",
"Calmar Ratio 1.199638\n",
"Annual Return [%] 73.018058\n",
"Annual Volatility [%] 51.088459\n",
"Omega Ratio 1.209774\n",
"Skew -0.0376\n",
"Kurtosis 3.435275\n",
"Tail Ratio 1.037861\n",
"Common Sense Ratio 1.795687\n",
"Value at Risk -0.041247\n",
"Alpha -0.00145\n",
"Beta 1.00001\n",
"dtype: object"
]
},
@@ -1544,49 +1544,49 @@
{
"data": {
"text/plain": [
"Run Time Wednesday May 26, 2021, NYSE: 10:59:44\n",
"Mode TEST\n",
"Strategy Long Strategy\n",
"Direction longonly\n",
"Symbol SPY\n",
"Fees [%] 0.25\n",
"Slippage [%] 0.25\n",
"Accumulate False\n",
"Start 2005-01-03 00:00:00\n",
"End 2009-12-31 00:00:00\n",
"Duration 1259 days 00:00:00\n",
"Init. Cash 100.0\n",
"Total Profit 49.766868\n",
"Total Return [%] 49.766868\n",
"Benchmark Return [%] 2.455635\n",
"Position Coverage [%] 52.819698\n",
"Max. Drawdown [%] 10.131765\n",
"Avg. Drawdown [%] 1.723872\n",
"Max. Drawdown Duration 451 days 00:00:00\n",
"Avg. Drawdown Duration 17 days 20:34:17.142857143\n",
"Num. Trades 2\n",
"Win Rate [%] 100.0\n",
"Best Trade [%] 14.916866\n",
"Worst Trade [%] 6.746063\n",
"Avg. Trade [%] 10.831464\n",
"Max. Trade Duration 335 days 00:00:00\n",
"Avg. Trade Duration 264 days 00:00:00\n",
"Expectancy 11.305097\n",
"SQN 2.470596\n",
"Gross Exposure 0.528197\n",
"Sharpe Ratio 1.009581\n",
"Sortino Ratio 1.431911\n",
"Calmar Ratio 1.226146\n",
"Annual Return [%] 12.423018\n",
"Annual Volatility [%] 12.357496\n",
"Omega Ratio 1.224227\n",
"Skew -0.412954\n",
"Kurtosis 6.272176\n",
"Tail Ratio 1.032277\n",
"Common Sense Ratio 1.160517\n",
"Value at Risk -0.010296\n",
"Alpha 0.122838\n",
"Beta 0.182612\n",
"Run Time Saturday June 19, 2021, NYSE: 7:58:53\n",
"Mode TEST\n",
"Strategy Long Strategy\n",
"Direction longonly\n",
"Symbol SPY\n",
"Fees [%] 0.25\n",
"Slippage [%] 0.25\n",
"Accumulate False\n",
"Start 2005-01-03 00:00:00\n",
"End 2009-12-31 00:00:00\n",
"Duration 1259 days 00:00:00\n",
"Init. Cash 100.0\n",
"Total Profit 49.766868\n",
"Total Return [%] 49.766868\n",
"Benchmark Return [%] 2.455635\n",
"Position Coverage [%] 52.819698\n",
"Max. Drawdown [%] 10.131765\n",
"Avg. Drawdown [%] 1.723872\n",
"Max. Drawdown Duration 451 days 00:00:00\n",
"Avg. Drawdown Duration 17 days 20:34:17.142857143\n",
"Num. Trades 2\n",
"Win Rate [%] 100.0\n",
"Best Trade [%] 14.916866\n",
"Worst Trade [%] 6.746063\n",
"Avg. Trade [%] 10.831464\n",
"Max. Trade Duration 335 days 00:00:00\n",
"Avg. Trade Duration 264 days 00:00:00\n",
"Expectancy 11.305097\n",
"SQN 2.470596\n",
"Gross Exposure 0.528197\n",
"Sharpe Ratio 1.009581\n",
"Sortino Ratio 1.431911\n",
"Calmar Ratio 1.226146\n",
"Annual Return [%] 12.423018\n",
"Annual Volatility [%] 12.357496\n",
"Omega Ratio 1.224227\n",
"Skew -0.412954\n",
"Kurtosis 6.272176\n",
"Tail Ratio 1.032277\n",
"Common Sense Ratio 1.160517\n",
"Value at Risk -0.010296\n",
"Alpha 0.122838\n",
"Beta 0.182612\n",
"dtype: object"
]
},
@@ -1635,49 +1635,49 @@
{
"data": {
"text/plain": [
"Run Time Wednesday May 26, 2021, NYSE: 10:59:45\n",
"Mode TEST\n",
"Strategy Long Strategy\n",
"Direction longonly\n",
"Symbol AAPL\n",
"Fees [%] 0.25\n",
"Slippage [%] 0.25\n",
"Accumulate False\n",
"Start 2005-01-03 00:00:00\n",
"End 2009-12-31 00:00:00\n",
"Duration 1259 days 00:00:00\n",
"Init. Cash 100.0\n",
"Total Profit 98.993099\n",
"Total Return [%] 98.993099\n",
"Benchmark Return [%] 565.918578\n",
"Position Coverage [%] 62.271644\n",
"Max. Drawdown [%] 59.898137\n",
"Avg. Drawdown [%] 6.193394\n",
"Max. Drawdown Duration 506 days 00:00:00\n",
"Avg. Drawdown Duration 32 days 01:30:00\n",
"Num. Trades 3\n",
"Win Rate [%] 66.666667\n",
"Best Trade [%] 58.200243\n",
"Worst Trade [%] -33.15062\n",
"Avg. Trade [%] 10.753768\n",
"Max. Trade Duration 363 days 00:00:00\n",
"Avg. Trade Duration 207 days 08:00:00\n",
"Expectancy 4.466566\n",
"SQN 0.130735\n",
"Gross Exposure 0.622716\n",
"Sharpe Ratio 0.739016\n",
"Sortino Ratio 1.08289\n",
"Calmar Ratio 0.36859\n",
"Annual Return [%] 22.077862\n",
"Annual Volatility [%] 35.543979\n",
"Omega Ratio 1.140899\n",
"Skew 0.024374\n",
"Kurtosis 4.672291\n",
"Tail Ratio 1.095481\n",
"Common Sense Ratio 1.337339\n",
"Value at Risk -0.029217\n",
"Alpha -0.063652\n",
"Beta 0.482566\n",
"Run Time Saturday June 19, 2021, NYSE: 7:58:54\n",
"Mode TEST\n",
"Strategy Long Strategy\n",
"Direction longonly\n",
"Symbol AAPL\n",
"Fees [%] 0.25\n",
"Slippage [%] 0.25\n",
"Accumulate False\n",
"Start 2005-01-03 00:00:00\n",
"End 2009-12-31 00:00:00\n",
"Duration 1259 days 00:00:00\n",
"Init. Cash 100.0\n",
"Total Profit 98.993099\n",
"Total Return [%] 98.993099\n",
"Benchmark Return [%] 565.918578\n",
"Position Coverage [%] 62.271644\n",
"Max. Drawdown [%] 59.898137\n",
"Avg. Drawdown [%] 6.193394\n",
"Max. Drawdown Duration 506 days 00:00:00\n",
"Avg. Drawdown Duration 32 days 01:30:00\n",
"Num. Trades 3\n",
"Win Rate [%] 66.666667\n",
"Best Trade [%] 58.200243\n",
"Worst Trade [%] -33.15062\n",
"Avg. Trade [%] 10.753768\n",
"Max. Trade Duration 363 days 00:00:00\n",
"Avg. Trade Duration 207 days 08:00:00\n",
"Expectancy 4.466566\n",
"SQN 0.130735\n",
"Gross Exposure 0.622716\n",
"Sharpe Ratio 0.739016\n",
"Sortino Ratio 1.08289\n",
"Calmar Ratio 0.36859\n",
"Annual Return [%] 22.077862\n",
"Annual Volatility [%] 35.543979\n",
"Omega Ratio 1.140899\n",
"Skew 0.024374\n",
"Kurtosis 4.672291\n",
"Tail Ratio 1.095481\n",
"Common Sense Ratio 1.337339\n",
"Value at Risk -0.029217\n",
"Alpha -0.063652\n",
"Beta 0.482566\n",
"dtype: object"
]
},
+84 -84
View File
File diff suppressed because one or more lines are too long
+12 -5
View File
@@ -3,7 +3,7 @@ from pandas import DataFrame
from pandas_ta import Imports
from pandas_ta.overlap import ma
from pandas_ta.statistics import stdev
from pandas_ta.utils import get_offset, verify_series
from pandas_ta.utils import get_offset, non_zero_range, verify_series
def bbands(close, length=None, std=None, mamode=None, ddof=0, offset=None, **kwargs):
@@ -31,7 +31,9 @@ def bbands(close, length=None, std=None, mamode=None, ddof=0, offset=None, **kwa
lower = mid - deviations
upper = mid + deviations
bandwidth = 100 * (upper - lower) / mid
ulr = non_zero_range(upper, lower)
bandwidth = 100 * ulr / mid
percent = non_zero_range(close, lower) / ulr
# Offset
if offset != 0:
@@ -39,6 +41,7 @@ def bbands(close, length=None, std=None, mamode=None, ddof=0, offset=None, **kwa
mid = mid.shift(offset)
upper = upper.shift(offset)
bandwidth = bandwidth.shift(offset)
percent = bandwidth.shift(offset)
# Handle fills
if "fillna" in kwargs:
@@ -46,24 +49,27 @@ def bbands(close, length=None, std=None, mamode=None, ddof=0, offset=None, **kwa
mid.fillna(kwargs["fillna"], inplace=True)
upper.fillna(kwargs["fillna"], inplace=True)
bandwidth.fillna(kwargs["fillna"], inplace=True)
percent.fillna(kwargs["fillna"], inplace=True)
if "fill_method" in kwargs:
lower.fillna(method=kwargs["fill_method"], inplace=True)
mid.fillna(method=kwargs["fill_method"], inplace=True)
upper.fillna(method=kwargs["fill_method"], inplace=True)
bandwidth.fillna(method=kwargs["fill_method"], inplace=True)
percent.fillna(method=kwargs["fill_method"], inplace=True)
# Name and Categorize it
lower.name = f"BBL_{length}_{std}"
mid.name = f"BBM_{length}_{std}"
upper.name = f"BBU_{length}_{std}"
bandwidth.name = f"BBB_{length}_{std}"
percent.name = f"BBP_{length}_{std}"
upper.category = lower.category = "volatility"
mid.category = bandwidth.category = upper.category
# Prepare DataFrame to return
data = {
lower.name: lower, mid.name: mid, upper.name: upper,
bandwidth.name: bandwidth
bandwidth.name: bandwidth, percent.name: percent
}
bbandsdf = DataFrame(data)
bbandsdf.name = f"BBANDS_{length}_{std}"
@@ -75,7 +81,7 @@ def bbands(close, length=None, std=None, mamode=None, ddof=0, offset=None, **kwa
bbands.__doc__ = \
"""Bollinger Bands (BBANDS)
A popular volatility indicator.
A popular volatility indicator by John Bollinger.
Sources:
https://www.tradingview.com/wiki/Bollinger_Bands_(BB)
@@ -96,6 +102,7 @@ Calculation:
UPPER = MID + std * stdev
BANDWIDTH = 100 * (UPPER - LOWER) / MID
PERCENT = (close - LOWER) / (UPPER - LOWER)
Args:
close (pd.Series): Series of 'close's
@@ -110,5 +117,5 @@ Kwargs:
fill_method (value, optional): Type of fill method
Returns:
pd.DataFrame: lower, mid, upper, bandwidth columns.
pd.DataFrame: lower, mid, upper, bandwidth, and percent columns.
"""
+1 -1
View File
@@ -19,7 +19,7 @@ setup(
"pandas_ta.volatility",
"pandas_ta.volume"
],
version=".".join(("0", "2", "91b")),
version=".".join(("0", "2", "92b")),
description=long_description,
long_description=long_description,
author="Kevin Johnson",
+1 -1
View File
@@ -36,7 +36,7 @@ class TestVolatilityExtension(TestCase):
def test_bbands_ext(self):
self.data.ta.bbands(append=True)
self.assertIsInstance(self.data, DataFrame)
self.assertEqual(list(self.data.columns[-4:]), ["BBL_5_2.0", "BBM_5_2.0", "BBU_5_2.0", "BBB_5_2.0"])
self.assertEqual(list(self.data.columns[-5:]), ["BBL_5_2.0", "BBM_5_2.0", "BBU_5_2.0", "BBB_5_2.0", "BBP_5_2.0"])
def test_donchian_ext(self):
self.data.ta.donchian(append=True)
+1 -1
View File
@@ -157,7 +157,7 @@ class TestStrategyMethods(TestCase):
def test_custom_col_names_tuple(self):
self.category = "Custom C"
custom_args_ta = [{"kind": "bbands", "col_names": ("LB", "MB", "UB", "BW")}]
custom_args_ta = [{"kind": "bbands", "col_names": ("LB", "MB", "UB", "BW", "BP")}]
custom = pandas_ta.Strategy(
"Custom Col Numbers Tuple",