For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
How to get historical data properly?
-
Hi guys,
I am a newbie for backtrader and I need for you help..
Let's say that I have a strategy concerning with average price (like the average price of last 5 days)
So I always need the last 5 days data, sure I can use a variable to track the index and use some thing like
n_avg = 5 hisrotical_prices = [self.dataclose[x - n_avg] for x in range(n_avg )] # without considering the first 4 days from beginning
Any better approach for this?
And what if the strategy need all the historical data? I would expect better than this
def __init__(self): self.idx = 0 #track the timeline def next(self): hisrotical_prices = [self.dataclose[x - self.idx] for x in range(self.idx)] #blablabla self.idx += 1
Because I think there's some reason that the framework hide the real
idx
variable and I don't want to break it...Thanks a lot!
-
data.get(size=x, ago=y)
, where the default isago=0
to start at the current point in time.Everything that has to do with the indexing model is explained here: Docs - Platform Concepts
-
@backtrader Thanks a lot!