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.

示例

>>> cerebro.broker.set_filler(backtrader.fillers.FixedBarPerc(perc=50.0))
class backtrader.fillers.FixedSize[源代码]

基类:ParameterizedBase

Returns the execution size for a given order using a percentage of the volume in a bar.

This percentage is set with the parameter perc

Params:

  • 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)[源代码]

Calculate the execution size for an order.

参数:
  • order -- The order being executed.

  • price -- Execution price.

  • ago -- Number of bars back (0 for current, -1 for previous).

返回:

The maximum size that can be executed, limited by

bar volume, remaining order size, and configured size.

返回类型:

float

class backtrader.fillers.FixedBarPerc[源代码]

基类:ParameterizedBase

Returns the execution size for a given order using a percentage of the volume in a bar.

This percentage is set with the parameter perc

Params:

  • 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)[源代码]

Calculate the execution size using percentage of bar volume.

参数:
  • order -- The order being executed.

  • price -- Execution price.

  • ago -- Number of bars back (0 for current, -1 for previous).

返回:

The maximum size that can be executed based on

percentage of bar volume and remaining order size.

返回类型:

float

class backtrader.fillers.BarPointPerc[源代码]

基类:ParameterizedBase

Returns the execution size for a given order. The volume will be distributed uniformly in the range high-low using minmov to 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)[源代码]

Calculate the execution size distributing volume across price range.

参数:
  • order -- The order being executed.

  • price -- Execution price.

  • ago -- Number of bars back (0 for current, -1 for previous).

返回:

The maximum size that can be executed based on

proportional distribution across the price range.

返回类型:

float