def _start_finish(self): # A live feed (for example) may have learnt something about the # timezones after the start and that's why the date/time related # parameters are converted at this late stage # Get the output timezone (if any) self._tz = self._gettz() # Lines have already been create, set the tz self.lines.datetime._settz(self._tz) # This should probably be also called from an override-able method self._tzinput = bt.utils.date.Localizer(self._gettzinput()) # Convert user input times to the output timezone (or min/max) if self.p.fromdate is None: self.fromdate = float('-inf') else: self.fromdate = self.date2num(self.p.fromdate) if self.p.todate is None: self.todate = float('inf') else: self.todate = self.date2num(self.p.todate) # FIXME: These two are never used and could be removed self.sessionstart = time2num(self.p.sessionstart) self.sessionend = time2num(self.p.sessionend) self._calendar = cal = self.p.calendar if cal is None: self._calendar = self._env._tradingcal elif isinstance(cal, string_types): self._calendar = PandasMarketCalendar(calendar=cal) self._started = True
def dopostinit(cls, _obj, *args, **kwargs): _obj, args, kwargs = \ super(MetaAbstractDataBase, cls).dopostinit(_obj, *args, **kwargs) _obj._name = _obj.p.name _obj._compression = _obj.p.compression _obj._timeframe = _obj.p.timeframe if _obj.p.sessionstart is None: _obj.p.sessionstart = datetime.time(0, 0, 0) if _obj.p.sessionend is None: _obj.p.sessionend = datetime.time(23, 59, 59) if isinstance(_obj.p.fromdate, datetime.date): # push it to the end of the day, or else intraday # values before the end of the day would be gone _obj.p.fromdate = datetime.datetime.combine( _obj.p.fromdate, _obj.p.sessionstart) if isinstance(_obj.p.todate, datetime.date): # push it to the end of the day, or else intraday # values before the end of the day would be gone _obj.p.todate = datetime.datetime.combine( _obj.p.todate, _obj.p.sessionend) _obj.fromdate = date2num(_obj.p.fromdate) _obj.todate = date2num(_obj.p.todate) _obj.sessionstart = time2num(_obj.p.sessionstart) _obj.sessionend = time2num(_obj.p.sessionend) # hold datamaster points corresponding to own _obj.mlen = list() return _obj, args, kwargs
def dopostinit(cls, _obj, *args, **kwargs): _obj, args, kwargs = \ super(MetaAbstractDataBase, cls).dopostinit(_obj, *args, **kwargs) _obj._name = _obj.p.name _obj._compression = _obj.p.compression _obj._timeframe = _obj.p.timeframe if isinstance(_obj.p.sessionstart, datetime.datetime): _obj.p.sessionstart = _obj.p.sessionstart.time() if _obj.p.sessionstart is None: _obj.p.sessionstart = datetime.time(0, 0, 0) if isinstance(_obj.p.sessionend, datetime.datetime): _obj.p.sessionend = _obj.p.sessionend.time() if _obj.p.sessionend is None: _obj.p.sessionend = datetime.time(23, 59, 59) if isinstance(_obj.p.fromdate, datetime.date): # push it to the end of the day, or else intraday # values before the end of the day would be gone _obj.p.fromdate = datetime.datetime.combine( _obj.p.fromdate, _obj.p.sessionstart) if isinstance(_obj.p.todate, datetime.date): # push it to the end of the day, or else intraday # values before the end of the day would be gone _obj.p.todate = datetime.datetime.combine(_obj.p.todate, _obj.p.sessionend) _obj.fromdate = date2num(_obj.p.fromdate) _obj.todate = date2num(_obj.p.todate) _obj.sessionstart = time2num(_obj.p.sessionstart) _obj.sessionend = time2num(_obj.p.sessionend) # hold datamaster points corresponding to own _obj.mlen = list() _obj._barstack = collections.deque() # for filter operations _obj._filters = list() _obj._ffilters = list() for fp in _obj.p.filters: if inspect.isclass(fp): fp = fp(_obj) if hasattr(fp, 'last'): _obj._ffilters.append((fp, [], {})) _obj._filters.append((fp, [], {})) return _obj, args, kwargs
def dopostinit(cls, _obj, *args, **kwargs): _obj, args, kwargs = \ super(MetaAbstractDataBase, cls).dopostinit(_obj, *args, **kwargs) _obj._name = _obj.p.name _obj._compression = _obj.p.compression _obj._timeframe = _obj.p.timeframe if isinstance(_obj.p.sessionstart, datetime.datetime): _obj.p.sessionstart = _obj.p.sessionstart.time() if _obj.p.sessionstart is None: _obj.p.sessionstart = datetime.time(0, 0, 0) if isinstance(_obj.p.sessionend, datetime.datetime): _obj.p.sessionend = _obj.p.sessionend.time() if _obj.p.sessionend is None: _obj.p.sessionend = datetime.time(23, 59, 59) if isinstance(_obj.p.fromdate, datetime.date): # push it to the end of the day, or else intraday # values before the end of the day would be gone _obj.p.fromdate = datetime.datetime.combine( _obj.p.fromdate, _obj.p.sessionstart) if isinstance(_obj.p.todate, datetime.date): # push it to the end of the day, or else intraday # values before the end of the day would be gone _obj.p.todate = datetime.datetime.combine( _obj.p.todate, _obj.p.sessionend) _obj.fromdate = date2num(_obj.p.fromdate) _obj.todate = date2num(_obj.p.todate) _obj.sessionstart = time2num(_obj.p.sessionstart) _obj.sessionend = time2num(_obj.p.sessionend) # hold datamaster points corresponding to own _obj.mlen = list() _obj._barstack = collections.deque() # for filter operations _obj._filters = list() _obj._ffilters = list() for fp in _obj.p.filters: if inspect.isclass(fp): fp = fp(_obj) if hasattr(fp, 'last'): _obj._ffilters.append((fp, [], {})) _obj._filters.append((fp, [], {})) return _obj, args, kwargs
def __init__(self, data): self.tmnum = time2num(self.p.endtime)