Skip to content

Wrong timezone for DataFactory #721

@ypxie

Description

@ypxie
data0 = DataFactory(dataname='SPY', 
    historical=True, 
    fromdate=datetime(2023, 2, 24, 9, 30, 0), 
    todate=datetime(2023, 2, 25, 16, 0, 0), 
    timeframe=bt.TimeFrame.Minutes,
    tz=global_tz,
    compression=5)

cerebro = bt.Cerebro()
cerebro.adddata(data0)
data0.getfeed()
data0.start()

def print_data(datafeed, num_print=10):
    dd = datafeed.next()
    while dd:
        dd = datafeed.next()
    
    print(len(datafeed))
    for d in datafeed:
        _open = datafeed.open.array
        _close = datafeed.close.array
        _datetime =  datafeed.datetime.array
        for idx, (this_open, this_close, this_dtime) in enumerate(zip(_open, _close, _datetime) ):
            print(this_open, this_close, num2date(this_dtime) )
            if idx > num_print:
                break

print_data(data0, 10000)

will have the following results:

`78
399.63 399.65 2023-02-24 09:30:00
399.67 399.67 2023-02-24 09:35:00
399.6 399.59 2023-02-24 09:40:00
399.58 399.47 2023-02-24 09:45:00
399.48 399.48 2023-02-24 09:50:00
399.41 399.42 2023-02-24 09:55:0

.....

393.89 394.1 2023-02-24 15:55:00`

It seems that DataFactory is confused by the utc timezone and NYC timezone. IT returned data with utc timezone, but still use NYV timezone 16:00:00 as end datetime. Please fix this.

For example,
399.63 399.65 2023-02-24 09:30:00 is utc timezone,
but it still truncate each data's data to 15:55:00 which is based on NYC timezone, this is wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions