Skip to content

Filter invalid time intervals to prevent duplicate Friday records#122

Open
val3344 wants to merge 1 commit intobeancount:masterfrom
val3344:fix-lifetimes-map
Open

Filter invalid time intervals to prevent duplicate Friday records#122
val3344 wants to merge 1 commit intobeancount:masterfrom
val3344:fix-lifetimes-map

Conversation

@val3344
Copy link

@val3344 val3344 commented Nov 17, 2025

Remove intervals where begin >= end from lifetimes_map before generating price jobs. This addresses an edge case where closing positions on Fridays could result in duplicate price entries.

The issue stems from the callee's required_daily_prices() function which contains:

for date_begin, date_end in intervals:
    if weekdays_only:
        diff_days = 4 - date_begin.weekday()
        if diff_days < 0:
            date += datetime.timedelta(days=diff_days)

When date_begin == date_end (e.g., when closing positions on Friday), this code would still process the interval and potentially create duplicate Friday records in the price requirements.

By filtering out these invalid intervals at the caller level, we prevent the problematic code path from being executed, ensuring only valid trading periods are processed for price data retrieval.

Remove intervals where begin >= end from lifetimes_map before generating
price jobs. This addresses an edge case where closing positions on
Fridays could result in duplicate price entries.

The issue stems from the callee's required_daily_prices() function which
contains:

    for date_begin, date_end in intervals:
        if weekdays_only:
            diff_days = 4 - date_begin.weekday()
            if diff_days < 0:
                date += datetime.timedelta(days=diff_days)

When date_begin == date_end (e.g., when closing positions on Friday),
this code would still process the interval and potentially create
duplicate Friday records in the price requirements.

By filtering out these invalid intervals at the caller level, we prevent
the problematic code path from being executed, ensuring only valid
trading periods are processed for price data retrieval.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant