backtrader.filters.calendardays module

Calendar Days Filter Module - Calendar day filling.

This module provides the CalendarDays filter for adding missing calendar days to trading day data.

Classes:

CalendarDays: Fills missing calendar days.

Example

>>> data = bt.feeds.GenericCSVData(dataname='data.csv')
>>> data.addfilter(bt.filters.CalendarDays())
>>> cerebro.adddata(data)
class backtrader.filters.calendardays.CalendarDays[source]

Bases: ParameterizedBase

Bar Filler to add missing calendar days to trading days

Params:

  • fill_price (def: None):

    > 0: The given value to fill 0 or None: Use the last known closing price -1: Use the midpoint of the last bar (High-Low average)

  • fill_vol (def: float(‘NaN’)):

    Value to use to fill the missing volume

  • fill_oi (def: float(‘NaN’)):

    Value to use to fill the missing Open Interest

params = (('fill_price', None), ('fill_vol', nan), ('fill_oi', nan))
ONEDAY = datetime.timedelta(days=1)
lastdt = datetime.date(9999, 12, 31)
__init__(data, **kwargs)[source]

Initialize the CalendarDays filter.

Parameters:
  • data – The data feed to apply the filter to.

  • **kwargs – Additional keyword arguments passed to parent class.

__call__(data)[source]

If the data has a gap larger than 1 day amongst bars, the missing bars are added to the stream.

Params:
  • data: the data source to filter/process

Returns:

this filter does not remove bars from the stream

Return type:

  • False (always)