3
$\begingroup$

I am trying to backtest a strategy with Backtrader (not the first time) and have a problem while printing date & time for each iteration (time stay on 23:59:59). Here are the first lines of my dataset:

Dataset lines

What is printed on the console :

Console log

And finally how I load my data :

data = bt.feeds.GenericCSVData(dataname="BTCUSD_15MIN.csv",
                           datetime=0,
                           fromdate=datetime.datetime(2015,1,13),
                           todate=datetime.datetime(2015,1,15),
                           open=1,
                           high=2,
                           low=3,
                           close=4,
                           openinterest=-1,
                           time=-1,
                           volume=-1,
                           dtformat="%Y-%m-%d %H:%M:%S")

Has someone already got this issue? Thanks a lot!

$\endgroup$
2
$\begingroup$

That for sure only solved your problem by chance (because what you chose is smaller than the actual reality)

Your data is obviously 15-minutes based. But without specification, you let the default values in place: bt.TimeFrame.Daily, which gives you the end of the day for each bar. No surprises there.

The right choice would therefore be:

timeframe=bt.TimeFrame.Minutes,
compression=15,

This is explained in the backtrader community in several posts and in the FAQ.

$\endgroup$
2
$\begingroup$

Answer: This is the line that sorted out my issue :

timeframe=bt.TimeFrame.Ticks

If interested in the strategy results, it's here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.