Cerebro Backtest Time Frame
How do we set the time frame within which
I understand we can supply
todatewhile fetching data but that specifies data time frame that includes unstable period of indicators, etc. and not backtest time frame.
todatespecify time spans and not time frames and apply only to data feeds.
There is no such thing as
time span) for
Some extra elaboration is really needed to understand the question.
@backtrader - Thank you again for the prompt response.
Lets say we want to simulate/backtest a
Strategybetween any given dates eg. 2nd Jan 2012 to 1st Jan 2013, we need to calculate
todatefor the DataFeed in such a way that indicator lookback periods are taken into account and Backtest starts from exact
startdatewe wanted it to.
This is cumbersome and may be we can bake this login into
Cerebrosuch that irrespective of the
Datasupplied to it, it can calculate indicators applying the relevant lookbak period or from the beginning of data feed and start the backtest from the
datewe want it to start.
Don't take any action in
2nd Jan 2012is met.
Good idea!! We can do that! But that is hacky!
The right pattern would be - Cerebro should not call
Ok... Thank you for the suggestion.
Here is how I am doing it.
# Cerebro Sub Class class Cerebro(bt.Cerebro): params = (("startdate", None), ("enddate", None))
class MyStrategy(bt.Strategy): def next(self): if self.env.p.startdate is not None: if self.env.p.startdate > self.datas.datetime.date(0): return if self.env.p.enddate is not None: if self.env.p.enddate < self.datas.datetime.date(0): return # Your Logic goes here
This works as intended but not as efficient as it can be since the indicators are calculated inside the strategy from the beginning of the data feed.