From 169f07563e7eee0d96a7d7fb89b9dd20c12426ff Mon Sep 17 00:00:00 2001 From: David Brazda Date: Thu, 14 Nov 2024 13:48:20 +0100 Subject: [PATCH] fix vol bars --- setup.py | 2 +- ttools/aggregator_vectorized.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 542a585..f2cdb71 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='ttools', - version='0.7.3', + version='0.7.4', packages=find_packages(), install_requires=[ # list your dependencies here diff --git a/ttools/aggregator_vectorized.py b/ttools/aggregator_vectorized.py index dcec2cd..d425e81 100644 --- a/ttools/aggregator_vectorized.py +++ b/ttools/aggregator_vectorized.py @@ -257,7 +257,7 @@ def generate_volume_bars_nb(ticks, volume_per_bar): price = tick[1] tick_volume = tick[2] tick_day = np.floor(tick_time / 86400) # Calculate the day of the current tick - + splitted = False # Check if the new tick is from a different day, then close the current bar if tick_day != current_day: if trades_count > 0: @@ -321,9 +321,15 @@ def generate_volume_bars_nb(ticks, volume_per_bar): remaining_volume = volume_per_bar buy_volume = 0 sell_volume = 0 - - # Increment bar time if splitting a trade - bar_time = bar_time + 1e-6 + + #if the same trade opened the bar (we are splitting trade to more bars) + #first splitted identified by time, next by flag + if bar_time == tick_time or splitted: + bar_time = bar_time + 1e-6 + splitted = True + else: + bar_time = tick_time + splitted = False prev_price = price