I was able to find a solution,
works right as I want
It would seem you are unaware of the Python arithmetic with arrays.
I understand the python arrays but this logic is unacceptable here, because we can't get future data, so the -1 has to be the previous day, -2 the day before it and so on and if no such day is available to throw an exception, but not start everything in a circle.
Using a delayed index provides the proper automatic constraint to the platform.
Can you show me an example of proper way to get data for 2 days back or exeption if no such data is available?
You are simply doing things wrong. But you can disable preloading: Docs - Cerebro
Thank you for your prompt reply. Finally I was able to get it right.
The only moment by disabling preloading I was able to get
next:: current period: 1 date 2018-01-01 23:59:59.999989, current price 50.10, previous price 50.10
it's certainly better, but still not how it should
I want to access the data N days ago. I have written the following code
def next(self): print('next:: current period:', len(self)) print('date %s, current price %.2f, previous price %.2f' % (self.datas.datetime.datetime(), self.data.close, self.data.close[-1]))
the dataset I use consists of 3 lines
2018-01-01,50.1,... 2018-01-02,50.2,... 2018-01-03,50.3,...
and the output is
next:: current period: 1 date 2018-01-01 23:59:59.999989, current price 50.10, previous price 50.30 next:: current period: 2 date 2018-01-02 23:59:59.999989, current price 50.20, previous price 50.10 next:: current period: 3 date 2018-01-03 23:59:59.999989, current price 50.30, previous price 50.20
How can day 1 previous price be 50.30? Why it takes the value of the last day and doesn't throws an error?