update
This commit is contained in:
18
README.md
18
README.md
@ -1,7 +1,19 @@
|
|||||||
# ttools
|
# ttools
|
||||||
A Python library for tools, utilities, and helpers for my trading research workflow.
|
A Python library for tools, utilities, and helpers for my trading research workflow.
|
||||||
|
|
||||||
# Modules
|
Modules:
|
||||||
|
# utils
|
||||||
|
## vbtutils
|
||||||
|
|
||||||
|
Contains helpers for vbtpro
|
||||||
|
|
||||||
|
`AnchoredIndicator` - allows runing any vbt indicator in anchored mode (reset by Day, Hour etc.)
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
```python
|
||||||
|
from ttools import AnchoredIndicator
|
||||||
|
|
||||||
|
mom_standard = vbt.indicator("talib:MOM").run(t1data.data["BAC"].close)
|
||||||
|
mom_anchored_d = AnchoredIndicator("talib:MOM", anchor='D').run(t1data.data["BAC"].close)
|
||||||
|
```
|
||||||
|
|
||||||
- `utils.vbtutils` - contains helpers for vbtpro
|
|
||||||
- `AnchoredIndicator` - allows runing any vbt indicator in anchored mode (reset by Day, Hour etc.)
|
|
||||||
|
|||||||
6
setup.py
6
setup.py
@ -2,10 +2,10 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='ttools',
|
name='ttools',
|
||||||
version='0.1.0',
|
version='0.1.1',
|
||||||
packages=find_packages(),
|
packages=['ttools'],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'vectorbtpro',
|
'vectorbtpro',
|
||||||
# list your dependencies here
|
# list your dependencies here
|
||||||
],
|
],
|
||||||
)
|
) #find_packages()
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
import ttools
|
||||||
|
|
||||||
|
#ttools.AnchoredIndicator("talib:MOM")
|
||||||
1
ttools/__init__.py
Normal file
1
ttools/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .vbtutils import AnchoredIndicator
|
||||||
@ -5,39 +5,39 @@ class AnchoredIndicator:
|
|||||||
"""
|
"""
|
||||||
Allows to run any VBT indicator in anchored mode (reset per Day, Hour, or Minute).
|
Allows to run any VBT indicator in anchored mode (reset per Day, Hour, or Minute).
|
||||||
"""
|
"""
|
||||||
def __init__(self, indicator_name: str, split_by='D'):
|
def __init__(self, indicator_name: str, anchor='D'):
|
||||||
"""
|
"""
|
||||||
Initialize with the name of the indicator (e.g., "talib:MOM").
|
Initialize with the name of the indicator (e.g., "talib:MOM").
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- indicator_name: str, the name of the vectorbt indicator.
|
- indicator_name: str, the name of the vectorbt indicator.
|
||||||
- split_by: str, 'D' for day, 'H' for hour, 'T' for minute (default is 'D').
|
- anchor: str, 'D' for day, 'H' for hour, 'T' for minute (default is 'D').
|
||||||
"""
|
"""
|
||||||
self.indicator_name = indicator_name
|
self.indicator_name = indicator_name
|
||||||
self.indicator = vbt.indicator(indicator_name)
|
self.indicator = vbt.indicator(indicator_name)
|
||||||
self.split_by = split_by
|
self.anchor = anchor
|
||||||
|
|
||||||
def run(self, data, split_by=None, *args, **kwargs):
|
def run(self, data, anchor=None, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Run the indicator on a Series or DataFrame by splitting it by day, hour, or minute,
|
Run the indicator on a Series or DataFrame by splitting it by day, hour, or minute,
|
||||||
applying the indicator to each group, and concatenating the results.
|
applying the indicator to each group, and concatenating the results.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- data: pd.Series or pd.DataFrame, the input data series or dataframe (e.g., close prices).
|
- data: pd.Series or pd.DataFrame, the input data series or dataframe (e.g., close prices).
|
||||||
- split_by: str, 'D' for day, 'H' for hour, 'T' for minute (default is 'D').
|
- anchor: str, 'D' for day, 'H' for hour, 'T' for minute (default is 'D').
|
||||||
- *args, **kwargs: Arguments and keyword arguments passed to the indicator.
|
- *args, **kwargs: Arguments and keyword arguments passed to the indicator.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if split_by is None:
|
if anchor is None:
|
||||||
split_by = self.split_by
|
anchor = self.anchor
|
||||||
|
|
||||||
# Group by the specified frequency
|
# Group by the specified frequency
|
||||||
if split_by == 'D':
|
if anchor == 'D':
|
||||||
grouped_data = data.groupby(data.index.date)
|
grouped_data = data.groupby(data.index.date)
|
||||||
elif split_by in ['H', 'T']:
|
elif anchor in ['H', 'T']:
|
||||||
grouped_data = data.groupby(pd.Grouper(freq=split_by))
|
grouped_data = data.groupby(pd.Grouper(freq=anchor))
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid split_by value. Use 'D' (day), 'H' (hour), or 'T' (minute).")
|
raise ValueError("Invalid anchor value. Use 'D' (day), 'H' (hour), or 'T' (minute).")
|
||||||
|
|
||||||
# Run the indicator function for each group and concatenate the results
|
# Run the indicator function for each group and concatenate the results
|
||||||
results = []
|
results = []
|
||||||
Reference in New Issue
Block a user