diff --git a/setup.py b/setup.py index 65e4321..62e5a75 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='ttools', - version='0.3.1', + version='0.3.2', packages=find_packages(), install_requires=[ 'vectorbtpro', diff --git a/tests/test_ntb.ipynb b/tests/test_ntb.ipynb index 1c9168f..93e81ec 100644 --- a/tests/test_ntb.ipynb +++ b/tests/test_ntb.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 8, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -16,10 +16,10 @@ { "data": { "text/plain": [ - "['CUVWAP']" + "['CUVWAP', 'DIVRELN']" ] }, - "execution_count": 8, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -38,7 +38,10 @@ "#vwap_cum_d = vbt.indicator(\"ttools:CUVWAP\").run(s12_data.high, s12_data.low, s12_data.close, s12_data.volume, anchor=\"D\", drag=50)\n", "#vwap_lin_angle = vbt.indicator(\"talib:LINEARREG_ANGLE\").run(vwap_cum_d.vwap, timeperiod=2)\n", "\n", - "vbt.IF.list_indicators(\"ttools\")\n" + "vbt.IF.list_indicators(\"ttools\")\n", + "\n", + "\n", + "\n" ] } ], diff --git a/ttools/indicators/CUVWAP.py b/ttools/indicators/CUVWAP.py index 916a424..b4016b0 100644 --- a/ttools/indicators/CUVWAP.py +++ b/ttools/indicators/CUVWAP.py @@ -9,6 +9,8 @@ from vectorbtpro.utils.template import RepFunc Cumulative Anchored VWAP indicator on HLCC4 price, anchor = "D", "h", or "min" ... drag = 0 - overlap with previous group. takes into account last N elements from previous group when calculating (simulating v2realbot logic) + +HLCC4 price is rounded to hlcc4_round decimas (default is 3) """ def substitute_anchor(wrapper: ArrayWrapper, anchor: tp.Optional[tp.FrequencyLike]) -> tp.Array1d: @@ -18,16 +20,22 @@ def substitute_anchor(wrapper: ArrayWrapper, anchor: tp.Optional[tp.FrequencyLik return wrapper.get_index_grouper(anchor).get_group_lens() @jit(nopython=True) -def vwap_cum(high, low, close, volume, group_lens, drag): +def vwap_cum(high, low, close, volume, group_lens, drag, hlcc4_round): #anchor based grouping - prepare group indexes group_end_idxs = np.cumsum(group_lens) group_start_idxs = group_end_idxs - group_lens #prepare output out = np.full(volume.shape, np.nan, dtype=np.float_) + #hlcc4 = np.empty_like(close) hlcc4 = (high + low + close + close) / 4 + for i in range(hlcc4.shape[0]): + hlcc4[i] = np.round(hlcc4[i], hlcc4_round) + + #hlcc4 = np.floor(hlcc4 * 1000 + 0.5) / 1000 #nworkaround for np.round(hlcc4, 3) which doesnt work without iterating + #iterate over groups for group in range(len(group_lens)): from_i = group_start_idxs[group] @@ -43,7 +51,7 @@ def vwap_cum(high, low, close, volume, group_lens, drag): out[i] = np.nan else: out[i] = nom_cumsum / denum_cumsum - return out + return out, hlcc4 """ cumulative anchored vwap indicator on HLCC4 price, anchor = "D", "h", or "min" ... @@ -55,12 +63,13 @@ IND_CUVWAP = vbt.IF( module_name='ttools', input_names=['high', 'low', 'close', 'volume'], param_names=['anchor', "drag"], - output_names=['vwap'] + output_names=['vwap','hlcc4'] ).with_apply_func(vwap_cum, takes_1d=True, param_settings=dict( anchor=dict(template=RepFunc(substitute_anchor)), ), anchor="D", - drag=0 + drag=0, + hlcc4_round=3 ) \ No newline at end of file diff --git a/ttools/vbtutils.py b/ttools/vbtutils.py index 76f1607..0d49ed3 100644 --- a/ttools/vbtutils.py +++ b/ttools/vbtutils.py @@ -7,6 +7,7 @@ import datetime def isrising(series: pd.Series, n: int) -> pd.Series: """ Checks if a series is rising over a given window size. + Returns True for windows where values are either strictly increasing or staying the same Parameters ---------- @@ -20,12 +21,12 @@ def isrising(series: pd.Series, n: int) -> pd.Series: pd.Series Boolean mask indicating when the series is falling """ - return series.rolling(n).apply(lambda x: (x == sorted(x, reverse=True)).all(), raw=False).fillna(False).astype(bool) + return series.rolling(n).apply(lambda x: (x == sorted(x, reverse=False)).all(), raw=False).fillna(False).astype(bool) def isfalling(series: pd.Series, n: int) -> pd.Series: """ Checks if a series is falling over a given window size. - + Returns True for windows where values are either strictly decreasing or staying the same Parameters ---------- series : pd.Series