For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Intraday + Daily datasets Date misalignment ?



  • I'm running 2 datasets - one intraday (1-minute), 1 daily (resampled from the intraday dataset, though the problem also occurs with any other daily dataset).

    The intraday dataset is loaded first, the daily - second.
    Signals are generated using the 2nd dataset (daily), trades are executed on the intraday dataset.

    I'm running the buy/sell logic via timer, next() method is skipped (there's nothing in there)
    self.add_timer(
    when=dtm.time(9, 45),
    offset=dtm.timedelta(),
    repeat=dtm.timedelta(),
    weekdays=[],
    weekcarry=True
    )

    Inside notify_timer, I'm logging this:
    currentIntradayDate = self.data0.datetime.date(0)
    currentDailyDate = self.data1.datetime.date(0)
    self.log("Daily DB Date: {} | Intraday DB Date: {}" .format(currentDailyDate, currentIntradayDate))

    This is what I see:
    Daily DB Date: 2020-05-18 | Intraday DB Date: 2020-05-19

    So, for some reason the Daily db date is not the same as the intraday one.

    Any ideas on why this is the case, and what could be done to fix it? (Already tried oldsync=True, which made the backtest not run at all)

    Issue is also open @ https://github.com/backtrader2/backtrader/issues/38

    Regards
    D



  • AFAIU this is by design.

    1. The timers are checked ( and notified if triggered) each time the new bar is produced by any data feed.
    2. Daily data feed produces the bar as the day pass ( so that OLHC prices will be captured)

    So for 2020-05-19 9:25 the last daily bar that was issued was 2020-05-18. Please correct me if my understanding is wrong.



  • That's odd... as per the documentation the primary data feed needs to be the one with the most "ticks" i.e. the intraday one. Why would the timer act on the secondary feed? I don't see that behavior. The timer acts only once, or else I would have seen double logs (i.e. timer acting twice, once for each feed?)



  • The notify_timer() logs aren't necessarily bound to any dataset, I'm explicitly setting "0" to get the "today" value when the function executes. That should be the same Date for both data fees.



  • And as per the documentation, "0" stands for "today", -1 "yesterday" and so forth. Correct me if I'm wrong.



  • @chewbacca said in Intraday + Daily datasets Date misalignment ?:

    Why would the timer act on the secondary feed?

    It doesn't necessarily. Timers are not bound to any data feed at all.

    @chewbacca said in Intraday + Daily datasets Date misalignment ?:

    The timer acts only once, or else I would have seen double logs (i.e. timer acting twice, once for each feed?)

    Right, non-periodic timers will reset once notified, so it can't be triggered anymore.

    @chewbacca said in Intraday + Daily datasets Date misalignment ?:

    "0" stands for "today", -1 "yesterday"

    0 stands for the last delivered bar, -1 stands for the one delivered prior to the last one.



  • So when the timer acts on 09:31, i.e. the first intraday bar has already been delivered, why the buy/sell price would match a price on that bar ?



  • @chewbacca said in Intraday + Daily datasets Date misalignment ?:

    why the buy/sell price would match a price on that bar ?

    Not sure I'm following. Could you provide an example with a data feed sample? Also sharing more code (notify_timer in particular) may help.


Log in to reply
 

});