From b498d8df3d186f097fae360700f7d467bdcdcf49 Mon Sep 17 00:00:00 2001 From: David Brazda Date: Wed, 16 Oct 2024 17:29:07 +0200 Subject: [PATCH] daily update --- setup.py | 2 +- ttools/vbtutils.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 904a808..4f93cca 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='ttools', - version='0.1.7', + version='0.1.6', packages=find_packages(), install_requires=[ 'vectorbtpro', diff --git a/ttools/vbtutils.py b/ttools/vbtutils.py index 72779e7..e80b77f 100644 --- a/ttools/vbtutils.py +++ b/ttools/vbtutils.py @@ -17,6 +17,8 @@ def create_mask_from_window(entries: Any, entry_window_opens:int, entry_window_c entry_window_closes : int Number of minutes from market start to close the window. + TODO: test with entries not covering whole main session + Returns ------- type of entries @@ -28,9 +30,13 @@ def create_mask_from_window(entries: Any, entry_window_opens:int, entry_window_c market_hours =market_hours.tz_localize(nyse.tz) + # Ensure both entries and market_hours are timezone-aware and in the same timezone + if entries.index.tz is None: + entries.index = entries.index.tz_localize('America/New_York') + # Use merge_asof to align entries with the nearest market_open in market_hours merged = pd.merge_asof( - entries, + entries.to_frame(), market_hours[['market_open', 'market_close']], left_index=True, right_index=True, @@ -48,7 +54,8 @@ def create_mask_from_window(entries: Any, entry_window_opens:int, entry_window_c # Create a boolean mask for entries that are within the window window_opened = (elapsed_minutes >= entry_window_opens) & (elapsed_minutes < entry_window_closes) - return window_opened + # Return the mask as a series with the same index as entries + return pd.Series(window_opened.values, index=entries.index) class AnchoredIndicator: