For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Cerebro crashing with bt.feeds.PandasData when data contains different timezone
-
I am using Yahoo Finance with 15m data. Due to the daylight saving, the timezone in the dates are different from one day to another.
For example (note the
-04:00
vs-05:00
in theDatetime
):Datetime,Open,High,Low,Close,Volume 2020-10-30 15:45:00-04:00,108.43499755859375,109.0,107.87999725341797,108.94499969482422,13274860 2020-11-02 09:30:00-05:00,109.11000061035156,110.68000030517578,109.11000061035156,110.22000122070312,14459826
This causes Cerebro to crash with
bt.feeds.PandasData
, with the following error:File "/Users/kegan/.pyenv/versions/backyahoo/lib/python3.8/site-packages/backtrader/feeds/pandafeed.py", line 268, in _load dt = tstamp.to_pydatetime() AttributeError: 'datetime.datetime' object has no attribute 'to_pydatetime'
If I only use data with one timezone then it does not crash. For example any of these two by themselves independently is OK:
This is OK.
Datetime,Open,High,Low,Close,Volume 2020-10-30 15:45:00-04:00,108.43499755859375,109.0,107.87999725341797,108.94499969482422,13274860
And this is also OK.
Datetime,Open,High,Low,Close,Volume 2020-11-02 09:30:00-05:00,109.11000061035156,110.68000030517578,109.11000061035156,110.22000122070312,14459826
Here is my code:
import os import backtrader as bt import backtrader.feeds as btfeeds import pandas as pd # Create a Stratey class TestStrategy(bt.Strategy): def next(self): pass def main(): DATA = 'data.csv' # Create a cerebro entity cerebro = bt.Cerebro() # Add a strategy cerebro.addstrategy(TestStrategy) # Add the Data Feed to Cerebro dataframe = pd.read_csv(DATA, parse_dates=True, index_col='Datetime') data = bt.feeds.PandasData(dataname=dataframe) cerebro.adddata(data) cerebro.run() if __name__ == '__main__': main()
Is there a way to fix this?
Also, where do I submit bug report? (GitHub Issues seems to have been turn-off).