mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-08-11 11:22:48 +08:00
ENH #284 inc and dec strict speed boost TST talib stoch and stochrsi DOC notebooks update
This commit is contained in:
@@ -98,7 +98,7 @@ $ pip install pandas_ta
|
||||
|
||||
Latest Version
|
||||
--------------
|
||||
Best choice! Version: *0.2.79*
|
||||
Best choice! Version: *0.2.80*
|
||||
```sh
|
||||
$ pip install -U git+https://github.com/twopirllc/pandas-ta
|
||||
```
|
||||
@@ -958,8 +958,8 @@ cascaded stochastic calculations with additional smoothing. See: ```help(ta.stc)
|
||||
* _Bollinger Bands_ (**bbands**): New argument ```ddoff``` to control the Degrees of Freedom. 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```. Default: ```False```. See ```help(ta.decreasing)```.
|
||||
* _Increasing_ (**increasing**): New argument ```strict``` checks if the series is continuously increasing over period ```length```. Default: ```False```. See ```help(ta.increasing)```.
|
||||
* _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)```.
|
||||
* _Increasing_ (**increasing**): New argument ```strict``` checks if the series is continuously increasing over period ```length``` with a faster calculation. Default: ```False```. The ```percent``` argument has also been added with default None. See ```help(ta.increasing)```.
|
||||
* _Volume Weighted Average Price_ (**vwap**) Added a new parameter called ```anchor```. Default: "D" for "Daily". See [Timeseries Offset Aliases](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases) for additional options. **Requires** the DataFrame index to be a DatetimeIndex
|
||||
|
||||
<br />
|
||||
|
||||
+247
-229
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -199,6 +199,10 @@
|
||||
" <td>False</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>use_numba</th>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>seed</th>\n",
|
||||
" <td>None</td>\n",
|
||||
" </tr>\n",
|
||||
@@ -246,6 +250,7 @@
|
||||
"order_direction all\n",
|
||||
"cash_sharing False\n",
|
||||
"row_wise False\n",
|
||||
"use_numba True\n",
|
||||
"seed None\n",
|
||||
"freq 1D\n",
|
||||
"incl_unrealized False\n",
|
||||
@@ -446,8 +451,8 @@
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[i] Downloading: SPY, QQQ\n",
|
||||
"[+] SPY(7121, 7) Monday May 10, 2021, NYSE: 11:48:57\n",
|
||||
"[+] QQQ(5579, 7) Monday May 10, 2021, NYSE: 11:48:59\n",
|
||||
"[+] SPY(7128, 7) Wednesday May 19, 2021, NYSE: 7:18:34\n",
|
||||
"[+] QQQ(5586, 7) Wednesday May 19, 2021, NYSE: 7:18:36\n",
|
||||
"[*] Download Complete\n",
|
||||
"\n"
|
||||
]
|
||||
@@ -468,9 +473,9 @@
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[i] Downloading: AAPL, TSLA, TWTR\n",
|
||||
"[+] AAPL(10188, 7) Monday May 10, 2021, NYSE: 11:49:01\n",
|
||||
"[+] TSLA(2735, 7) Monday May 10, 2021, NYSE: 11:49:03\n",
|
||||
"[+] TWTR(1888, 7) Monday May 10, 2021, NYSE: 11:49:06\n",
|
||||
"[+] AAPL(10195, 7) Wednesday May 19, 2021, NYSE: 7:18:39\n",
|
||||
"[+] TSLA(2742, 7) Wednesday May 19, 2021, NYSE: 7:18:40\n",
|
||||
"[+] TWTR(1895, 7) Wednesday May 19, 2021, NYSE: 7:18:42\n",
|
||||
"[*] Download Complete\n",
|
||||
"\n"
|
||||
]
|
||||
@@ -1372,41 +1377,41 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Run Time Monday May 10, 2021, NYSE: 11:49:06\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 Wednesday May 19, 2021, NYSE: 7:18:48\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"
|
||||
]
|
||||
},
|
||||
@@ -1454,41 +1459,41 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Run Time Monday May 10, 2021, NYSE: 11:49:07\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 Wednesday May 19, 2021, NYSE: 7:19:00\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"
|
||||
]
|
||||
},
|
||||
@@ -1539,49 +1544,49 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Run Time Monday May 10, 2021, NYSE: 11:49:07\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 Wednesday May 19, 2021, NYSE: 7:19:02\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"
|
||||
]
|
||||
},
|
||||
@@ -1630,49 +1635,49 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Run Time Monday May 10, 2021, NYSE: 11:49:08\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 Wednesday May 19, 2021, NYSE: 7:19:03\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"
|
||||
]
|
||||
},
|
||||
|
||||
+74
-74
File diff suppressed because one or more lines are too long
@@ -25,6 +25,7 @@ Imports = {
|
||||
"alphaVantage-api": find_spec("alphaVantageAPI") is not None,
|
||||
"matplotlib": find_spec("matplotlib") is not None,
|
||||
"mplfinance": find_spec("mplfinance") is not None,
|
||||
"numba": find_spec("numba") is not None,
|
||||
"yaml": find_spec("yaml") is not None,
|
||||
"scipy": find_spec("scipy") is not None,
|
||||
"sklearn": find_spec("sklearn") is not None,
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from pandas_ta.utils import get_offset, verify_series
|
||||
from pandas_ta.utils import get_drift, get_offset, is_percent, verify_series
|
||||
|
||||
|
||||
def decreasing(close, length=None, strict=None, asint=None, offset=None, **kwargs):
|
||||
def decreasing(close, length=None, strict=None, asint=None, percent=None, drift=None, offset=None, **kwargs):
|
||||
"""Indicator: Decreasing"""
|
||||
# Validate Arguments
|
||||
length = int(length) if length and length > 0 else 1
|
||||
strict = strict if isinstance(strict, bool) else False
|
||||
asint = asint if isinstance(asint, bool) else True
|
||||
close = verify_series(close, length)
|
||||
drift = get_drift(drift)
|
||||
offset = get_offset(offset)
|
||||
percent = float(percent) if is_percent(percent) else False
|
||||
|
||||
if close is None: return
|
||||
|
||||
def stricly_decreasing(series, n):
|
||||
return all([i > j for i,j in zip(series[-n:], series[1:])])
|
||||
|
||||
# Calculate Result
|
||||
close_ = (1 - 0.01 * percent) * close if percent else close
|
||||
if strict:
|
||||
# Returns value as float64? Have to cast to bool
|
||||
decreasing = close.rolling(length, min_periods=length) \
|
||||
.apply(stricly_decreasing, args=(length,), raw=False)
|
||||
decreasing = close < close_.shift(drift)
|
||||
for x in range(3, length + 1):
|
||||
decreasing = decreasing & (close.shift(x - (drift + 1)) < close_.shift(x - drift))
|
||||
|
||||
decreasing.fillna(0, inplace=True)
|
||||
decreasing = decreasing.astype(bool)
|
||||
else:
|
||||
decreasing = close.diff(length) < 0
|
||||
decreasing = close_.diff(length) < 0
|
||||
|
||||
if asint:
|
||||
decreasing = decreasing.astype(int)
|
||||
@@ -40,7 +41,9 @@ def decreasing(close, length=None, strict=None, asint=None, offset=None, **kwarg
|
||||
decreasing.fillna(method=kwargs["fill_method"], inplace=True)
|
||||
|
||||
# Name and Categorize it
|
||||
decreasing.name = f"{'S' if strict else ''}DEC_{length}"
|
||||
_percent = f"_{0.01 * percent}" if percent else ''
|
||||
_props = f"{'S' if strict else ''}DEC{'p' if percent else ''}"
|
||||
decreasing.name = f"{_props}_{length}{_percent}"
|
||||
decreasing.category = "trend"
|
||||
|
||||
return decreasing
|
||||
@@ -66,8 +69,10 @@ Calculation:
|
||||
Args:
|
||||
close (pd.Series): Series of 'close's
|
||||
length (int): It's period. Default: 1
|
||||
asint (bool): Returns as binary. Default: True
|
||||
strict (bool): If True, checks if the series is continuously decreasing over the period. Default: False
|
||||
percent (float): Percent as an integer. Default: None
|
||||
asint (bool): Returns as binary. Default: True
|
||||
drift (int): The difference period. Default: 1
|
||||
offset (int): How many periods to offset the result. Default: 0
|
||||
|
||||
Kwargs:
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from pandas_ta.utils import get_offset, verify_series
|
||||
from pandas_ta.utils import get_drift, get_offset, is_percent, verify_series
|
||||
|
||||
|
||||
def increasing(close, length=None, strict=None, asint=None, offset=None, **kwargs):
|
||||
def increasing(close, length=None, strict=None, asint=None, percent=None, drift=None, offset=None, **kwargs):
|
||||
"""Indicator: Increasing"""
|
||||
# Validate Arguments
|
||||
length = int(length) if length and length > 0 else 1
|
||||
strict = strict if isinstance(strict, bool) else False
|
||||
asint = asint if isinstance(asint, bool) else True
|
||||
close = verify_series(close, length)
|
||||
drift = get_drift(drift)
|
||||
offset = get_offset(offset)
|
||||
percent = float(percent) if is_percent(percent) else False
|
||||
|
||||
if close is None: return
|
||||
|
||||
def stricly_increasing(series, n):
|
||||
return all([i < j for i,j in zip(series[-n:], series[1:])])
|
||||
|
||||
# Calculate Result
|
||||
close_ = (1 + 0.01 * percent) * close if percent else close
|
||||
if strict:
|
||||
# Returns value as float64? Have to cast to bool
|
||||
increasing = close.rolling(length, min_periods=length) \
|
||||
.apply(stricly_increasing, args=(length,), raw=False)
|
||||
increasing = close > close_.shift(drift)
|
||||
for x in range(3, length + 1):
|
||||
increasing = increasing & (close.shift(x - (drift + 1)) > close_.shift(x - drift))
|
||||
|
||||
increasing.fillna(0, inplace=True)
|
||||
increasing = increasing.astype(bool)
|
||||
else:
|
||||
increasing = close.diff(length) > 0
|
||||
increasing = close_.diff(length) > 0
|
||||
|
||||
if asint:
|
||||
increasing = increasing.astype(int)
|
||||
@@ -40,7 +41,9 @@ def increasing(close, length=None, strict=None, asint=None, offset=None, **kwarg
|
||||
increasing.fillna(method=kwargs["fill_method"], inplace=True)
|
||||
|
||||
# Name and Categorize it
|
||||
increasing.name = f"{'S' if strict else ''}INC_{length}"
|
||||
_percent = f"_{0.01 * percent}" if percent else ''
|
||||
_props = f"{'S' if strict else ''}INC{'p' if percent else ''}"
|
||||
increasing.name = f"{_props}_{length}{_percent}"
|
||||
increasing.category = "trend"
|
||||
|
||||
return increasing
|
||||
@@ -66,8 +69,10 @@ Calculation:
|
||||
Args:
|
||||
close (pd.Series): Series of 'close's
|
||||
length (int): It's period. Default: 1
|
||||
asint (bool): Returns as binary. Default: True
|
||||
strict (bool): If True, checks if the series is continuously increasing over the period. Default: False
|
||||
percent (float): Percent as an integer. Default: None
|
||||
asint (bool): Returns as binary. Default: True
|
||||
drift (int): The difference period. Default: 1
|
||||
offset (int): How many periods to offset the result. Default: 0
|
||||
|
||||
Kwargs:
|
||||
|
||||
@@ -9,7 +9,7 @@ from pandas import Series, Timedelta
|
||||
from ._core import verify_series
|
||||
from ._time import total_time
|
||||
from ._math import linear_regression, log_geometric_mean
|
||||
from pandas_ta import RATE
|
||||
from pandas_ta import Imports, RATE
|
||||
from pandas_ta.performance import drawdown, log_return, percent_return
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ setup(
|
||||
"pandas_ta.volatility",
|
||||
"pandas_ta.volume"
|
||||
],
|
||||
version=".".join(("0", "2", "79b")),
|
||||
version=".".join(("0", "2", "80b")),
|
||||
description=long_description,
|
||||
long_description=long_description,
|
||||
author="Kevin Johnson",
|
||||
|
||||
@@ -359,20 +359,49 @@ class TestMomentum(TestCase):
|
||||
self.assertIsInstance(result, DataFrame)
|
||||
self.assertEqual(result.name, "STC_10_12_26_0.5")
|
||||
|
||||
# @skip
|
||||
def test_stoch(self):
|
||||
# TV Correlation
|
||||
result = pandas_ta.stoch(self.high, self.low, self.close)
|
||||
self.assertIsInstance(result, DataFrame)
|
||||
self.assertEqual(result.name, "STOCH_14_3_3")
|
||||
|
||||
try:
|
||||
expected = tal.STOCH(self.high, self.low, self.close, 14, 3, 0, 3)
|
||||
expecteddf = DataFrame({"STOCHk_14_3_0_3": expected[0], "STOCHd_14_3_0_3": expected[1]})
|
||||
pdt.assert_frame_equal(result, expecteddf)
|
||||
except AssertionError as ae:
|
||||
try:
|
||||
stochk_corr = pandas_ta.utils.df_error_analysis(result.iloc[:, 0], expecteddf.iloc[:, 0], col=CORRELATION)
|
||||
self.assertGreater(stochk_corr, CORRELATION_THRESHOLD)
|
||||
except Exception as ex:
|
||||
error_analysis(result.iloc[:, 0], CORRELATION, ex)
|
||||
|
||||
try:
|
||||
stochd_corr = pandas_ta.utils.df_error_analysis(result.iloc[:, 1], expecteddf.iloc[:, 1], col=CORRELATION)
|
||||
self.assertGreater(stochd_corr, CORRELATION_THRESHOLD)
|
||||
except Exception as ex:
|
||||
error_analysis(result.iloc[:, 1], CORRELATION, ex, newline=False)
|
||||
|
||||
def test_stochrsi(self):
|
||||
# TV Correlation
|
||||
result = pandas_ta.stochrsi(self.close)
|
||||
self.assertIsInstance(result, DataFrame)
|
||||
self.assertEqual(result.name, "STOCHRSI_14_14_3_3")
|
||||
|
||||
try:
|
||||
expected = tal.STOCHRSI(self.close, 14, 14, 3, 0)
|
||||
expecteddf = DataFrame({"STOCHRSIk_14_14_0_3": expected[0], "STOCHRSId_14_14_3_0": expected[1]})
|
||||
pdt.assert_frame_equal(result, expecteddf)
|
||||
except AssertionError as ae:
|
||||
try:
|
||||
stochrsid_corr = pandas_ta.utils.df_error_analysis(result.iloc[:, 0], expecteddf.iloc[:, 1], col=CORRELATION)
|
||||
self.assertGreater(stochrsid_corr, CORRELATION_THRESHOLD)
|
||||
except Exception as ex:
|
||||
error_analysis(result.iloc[:, 0], CORRELATION, ex, newline=False)
|
||||
|
||||
@skip
|
||||
def test_td_seq(self):
|
||||
"""TS Sequential: Working but SLOW implementation"""
|
||||
result = pandas_ta.td_seq(self.close)
|
||||
self.assertIsInstance(result, DataFrame)
|
||||
self.assertEqual(result.name, "TD_SEQ")
|
||||
|
||||
Reference in New Issue
Block a user