daily fix
This commit is contained in:
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='ttools',
|
name='ttools',
|
||||||
version='0.3.1',
|
version='0.3.2',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'vectorbtpro',
|
'vectorbtpro',
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 8,
|
"execution_count": 2,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
@ -16,10 +16,10 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"['CUVWAP']"
|
"['CUVWAP', 'DIVRELN']"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 8,
|
"execution_count": 2,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"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_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",
|
"#vwap_lin_angle = vbt.indicator(\"talib:LINEARREG_ANGLE\").run(vwap_cum_d.vwap, timeperiod=2)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"vbt.IF.list_indicators(\"ttools\")\n"
|
"vbt.IF.list_indicators(\"ttools\")\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@ -9,6 +9,8 @@ from vectorbtpro.utils.template import RepFunc
|
|||||||
Cumulative Anchored VWAP indicator on HLCC4 price, anchor = "D", "h", or "min" ...
|
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
|
drag = 0 - overlap with previous group. takes into account last N elements from previous group
|
||||||
when calculating (simulating v2realbot logic)
|
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:
|
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()
|
return wrapper.get_index_grouper(anchor).get_group_lens()
|
||||||
|
|
||||||
@jit(nopython=True)
|
@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
|
#anchor based grouping - prepare group indexes
|
||||||
group_end_idxs = np.cumsum(group_lens)
|
group_end_idxs = np.cumsum(group_lens)
|
||||||
group_start_idxs = group_end_idxs - group_lens
|
group_start_idxs = group_end_idxs - group_lens
|
||||||
|
|
||||||
#prepare output
|
#prepare output
|
||||||
out = np.full(volume.shape, np.nan, dtype=np.float_)
|
out = np.full(volume.shape, np.nan, dtype=np.float_)
|
||||||
|
#hlcc4 = np.empty_like(close)
|
||||||
|
|
||||||
hlcc4 = (high + low + close + close) / 4
|
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
|
#iterate over groups
|
||||||
for group in range(len(group_lens)):
|
for group in range(len(group_lens)):
|
||||||
from_i = group_start_idxs[group]
|
from_i = group_start_idxs[group]
|
||||||
@ -43,7 +51,7 @@ def vwap_cum(high, low, close, volume, group_lens, drag):
|
|||||||
out[i] = np.nan
|
out[i] = np.nan
|
||||||
else:
|
else:
|
||||||
out[i] = nom_cumsum / denum_cumsum
|
out[i] = nom_cumsum / denum_cumsum
|
||||||
return out
|
return out, hlcc4
|
||||||
|
|
||||||
"""
|
"""
|
||||||
cumulative anchored vwap indicator on HLCC4 price, anchor = "D", "h", or "min" ...
|
cumulative anchored vwap indicator on HLCC4 price, anchor = "D", "h", or "min" ...
|
||||||
@ -55,12 +63,13 @@ IND_CUVWAP = vbt.IF(
|
|||||||
module_name='ttools',
|
module_name='ttools',
|
||||||
input_names=['high', 'low', 'close', 'volume'],
|
input_names=['high', 'low', 'close', 'volume'],
|
||||||
param_names=['anchor', "drag"],
|
param_names=['anchor', "drag"],
|
||||||
output_names=['vwap']
|
output_names=['vwap','hlcc4']
|
||||||
).with_apply_func(vwap_cum,
|
).with_apply_func(vwap_cum,
|
||||||
takes_1d=True,
|
takes_1d=True,
|
||||||
param_settings=dict(
|
param_settings=dict(
|
||||||
anchor=dict(template=RepFunc(substitute_anchor)),
|
anchor=dict(template=RepFunc(substitute_anchor)),
|
||||||
),
|
),
|
||||||
anchor="D",
|
anchor="D",
|
||||||
drag=0
|
drag=0,
|
||||||
|
hlcc4_round=3
|
||||||
)
|
)
|
||||||
@ -7,6 +7,7 @@ import datetime
|
|||||||
def isrising(series: pd.Series, n: int) -> pd.Series:
|
def isrising(series: pd.Series, n: int) -> pd.Series:
|
||||||
"""
|
"""
|
||||||
Checks if a series is rising over a given window size.
|
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
|
Parameters
|
||||||
----------
|
----------
|
||||||
@ -20,12 +21,12 @@ def isrising(series: pd.Series, n: int) -> pd.Series:
|
|||||||
pd.Series
|
pd.Series
|
||||||
Boolean mask indicating when the series is falling
|
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:
|
def isfalling(series: pd.Series, n: int) -> pd.Series:
|
||||||
"""
|
"""
|
||||||
Checks if a series is falling over a given window size.
|
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
|
Parameters
|
||||||
----------
|
----------
|
||||||
series : pd.Series
|
series : pd.Series
|
||||||
|
|||||||
Reference in New Issue
Block a user