Handling unordered timestamps (bootstrapped data)
Thank you very much for creating and open sourcing this great library, it has been very useful to me.
I'm using Block Bootstrap to create multiple replications of OHLCV data to calculate confidence intervals for some risk-return metrics. Because blocks of OHLCV data are randomly sampled, the resulting data has unordered timestamps. I'm trying to find the best way to work with such data in Backtrader. What I have tried so far:
Feeding the Pandas DataFrame of OHLCV data with randomly ordered timestamps to Backtrader. The backtest seems to run without issues but the calculation of daily returns using the
TimeReturnsanalyzer results in a series with lots of missing dates and a very large number (e.g., 853.00) as the return of the last day. I assume that Backtrader wasn't built to work with unordered timestamps. Is that correct or should I create a bug ticket?
Dropping the DateTimeIndex of the DataFrame and passing it to Backtrader without any timestamps. That didn't work as some places in the Backtrader code require timestamped data.
Creating a fake range of monotonically increasing dates (using the following code) and setting that as the index of the DataFrame. This works but it seems like an ugly hack. I'm wondering if there is a better way.
fake_index = pd.date_range(start=datetime.datetime(1980, 1, 1), periods=len(raw_ohlcv), freq='D') raw_ohlcv = raw_ohlcv.set_index(fake_index, drop=True)