backtrader.fillers module¶
Fillers Module - Order execution size calculation.
This module provides filler classes that determine how much of an order can be executed based on available volume, price constraints, and user-defined parameters.
- Classes:
FixedSize: Execute with fixed maximum size. FixedBarPerc: Execute using percentage of bar volume. BarPointPerc: Execute distributing volume across price range.
Example
>>> cerebro.broker.set_filler(backtrader.fillers.FixedBarPerc(perc=50.0))
- class backtrader.fillers.FixedSize[source]¶
Bases:
ParameterizedBaseReturns the execution size for a given order using a percentage of the volume in a bar.
This percentage is set with the parameter
percParams:
size(default:None) maximum size to be executed.
- The actual
volume of the bar at execution time is also a limit if smaller than the size
If the value of this parameter evaluates to False, the entire volume of the bar will be used to match the order
- params = (('size', None),)¶
- __call__(order, price, ago)[source]¶
Calculate the execution size for an order.
- Parameters:
order – The order being executed.
price – Execution price.
ago – Number of bars back (0 for current, -1 for previous).
- Returns:
- The maximum size that can be executed, limited by
bar volume, remaining order size, and configured size.
- Return type:
- class backtrader.fillers.FixedBarPerc[source]¶
Bases:
ParameterizedBaseReturns the execution size for a given order using a percentage of the volume in a bar.
This percentage is set with the parameter
percParams:
perc(default:100.0) (valied values:0.0-100.0)Percentage of the volume bar to use to execute an order
- params = (('perc', 100.0),)¶
- __call__(order, price, ago)[source]¶
Calculate the execution size using percentage of bar volume.
- Parameters:
order – The order being executed.
price – Execution price.
ago – Number of bars back (0 for current, -1 for previous).
- Returns:
- The maximum size that can be executed based on
percentage of bar volume and remaining order size.
- Return type:
- class backtrader.fillers.BarPointPerc[source]¶
Bases:
ParameterizedBaseReturns the execution size for a given order. The volume will be distributed uniformly in the range high-low using
minmovto partition.From the allocated volume for the given price, the perc percentage will be used
Params:
minmov(default:0.01)Minimum price movement. Used to partition the range high-low to proportionally distribute the volume amongst possible prices
perc(default:100.0) (valied values:0.0-100.0)Percentage of the volume allocated to the order execution price to use for matching # minmov defaults to 0.01, based on distance between high and low prices, see how many parts can be divided # perc defaults to 100, trading limit is order can only be placed for each part’s perc
- params = (('minmov', None), ('perc', 100.0))¶
- __call__(order, price, ago)[source]¶
Calculate the execution size distributing volume across price range.
- Parameters:
order – The order being executed.
price – Execution price.
ago – Number of bars back (0 for current, -1 for previous).
- Returns:
- The maximum size that can be executed based on
proportional distribution across the price range.
- Return type: