I have an alpha model that sets the insight period with a `timedelta`.

Using a timedelta of 1 day, the flattening of positions happens (after 1 day) as expected.

However, when using a timedelta of 1 day - 1 second, the algorithm holds the position for a longer-than-expected period of time (shown below). 

Looking at the debug, it looks like that the insights' `CloseTimeUtc` is incorrectly generated despite the `generatedTimeUtc` and `Period` look correct during runtime. What's going on here?

76569_1700603287.jpg76569_1700603326.jpg

Below is a minimum reproduceable example:

from AlgorithmImports import *
from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel

import functools
import pandas as pd

class InternFundReplica(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2023, 1, 23)
        self.SetCash(30000)

        # params
        tickers = ['VXX']
        symbols = {ticker: Symbol.Create(ticker, SecurityType.Equity, Market.USA) for ticker in tickers}


        # Algorithmic Framework
        self.UniverseSettings.Resolution = Resolution.Minute
        self.AddUniverseSelection(ManualUniverseSelectionModel(list(symbols.values())))
        self.AddAlpha(TurnAroundTuesdayAlpha('turnaround_tuesday_alpha', 1.0))
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())


    def OnData(self, data: Slice):
        pass



class TurnAroundTuesdayAlpha(AlphaModel):
    """
        If Monday is down, hold for tuesday
    """
    def __init__(self, model_name: str, allocation: float):
        super().__init__()
    
    def Update(self, algorithm, data):
        return []

    def OnSecuritiesChanged(self, algorithm, changes):
        for security in changes.AddedSecurities:
            algorithm.Schedule.On(
                algorithm.DateRules.Every(DayOfWeek.Monday),
                algorithm.TimeRules.BeforeMarketClose(security.Symbol, 2),
                functools.partial(self.monday_before_close, algorithm, security.Symbol)
            )

    def monday_before_close(self, algorithm, symbol):
        trade_bars = list(algorithm.History[TradeBar](symbol, timedelta(days = 1), Resolution.Minute, extendedMarketHours = False))
        todays_bars = [b for b in trade_bars if b.Time.date() == algorithm.Time.date()]
        if len(todays_bars) > 0:
            day_open = todays_bars[0].Open
            latest_close = trade_bars[-1].Close
            if latest_close < day_open * 0.995:
                algorithm.EmitInsights(
                    Insight.Price(
                        symbol, timedelta(days = 1) - timedelta(seconds = 1),
                        direction = InsightDirection.Up
                    )
                )

Thanks!