backtrader.filters.session module¶
Session Filter Module - Session bar filling.
This module provides the SessionFiller filter for adding missing bars over gaps within a trading session.
- Classes:
SessionFiller: Fills missing bars within a session.
Example
>>> data = bt.feeds.GenericCSVData(dataname='data.csv')
>>> data.addfilter(bt.filters.SessionFiller())
>>> cerebro.adddata(data)
- class backtrader.filters.session.SessionFiller[source]¶
Bases:
ParameterizedBaseBar Filler to add missing bars over gaps in a session.
This class has been refactored from MetaParams to the new ParameterizedBase system for Day 36-38 of the metaprogramming removal project.
How to use it:
Instantiate the class (1 instance per filter needed)
addfilterit to the data withdata.addfilter(filter_instance)
Bar
filllogic:The
fill_pricewill be used to fillopen,high,lowandcloseIf
Nonethen thecloseprice of the last (previous) bar will be used.Volume will be set to
fill_volopeninterestwill be set tofill_oi
- Parameters:
(def (- Skip_first_fill) –
None):
Price to be used to fill missing bars. If None will be used the closing price of the previous bar
(def –
float(‘NaN’)):
Value to use to fill the missing volume
(def –
float(‘NaN’)):
Value to use to fill the missing Open Interest
(def –
True):
Upon seeing the 1st valid bar do not fill from the sessionstart up to that bar
- fill_price¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- fill_vol¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- fill_oi¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- skip_first_fill¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- MAXDATE = datetime.datetime(9999, 12, 31, 23, 59, 59, 999999)¶
- __init__(data, **kwargs)[source]¶
Initialize the SessionFiller.
- Parameters:
data – The data feed to apply the filter to.
**kwargs – Additional keyword arguments passed to parent class.
- __call__(data)[source]¶
- Params:
data: the data source to filter/process
- Returns:
False (always) because this filter does not remove bars from the
stream
The logic (starting with a session end control flag of MAXDATE)
If new bar is over session end (never true for 1st bar)
Fill up to the session end. Reset sessionend to MAXDATE & fall through
If the session end is flagged as MAXDATE
Recalculate session limits and check whether the bar is within them
If so, fill up and record the last seen tim
Else … the incoming bar is in the session, fill up to it
- class backtrader.filters.session.SessionFilterSimple[source]¶
Bases:
ParameterizedBaseThis class can be applied to a data source as a filter and will filter out intraday bars which fall outside the regular session times (ie: pre/post market data)
This class has been refactored from MetaParams to the new ParameterizedBase system for Day 36-38 of the metaprogramming removal project.
This is a “simple” filter and must NOT manage the stack of the data (passed during init and __call__)
It needs no “last” method because it has nothing to deliver
Bar Management will be done by the SimpleFilterWrapper class made which is added durint the DataBase.addfilter_simple call
- class backtrader.filters.session.SessionFilter[source]¶
Bases:
ParameterizedBaseThis class can be applied to a data source as a filter and will filter out intraday bars which fall outside the regular session times (ie: pre/post market data)
This class has been refactored from MetaParams to the new ParameterizedBase system for Day 36-38 of the metaprogramming removal project.
This is a “non-simple” filter and must manage the stack of the data (passed during init and __call__)
It needs no “last” method because it has nothing to deliver