backtrader.sizers.fixedsize module

Fixed Size Sizer Module - Fixed stake position sizing.

This module provides the FixedSize sizer for using a fixed stake size in trading operations.

Classes:

FixedSize: Returns a fixed stake size for orders.

示例

>>> cerebro.addsizer(bt.sizers.FixedSize, stake=10)
class backtrader.sizers.fixedsize.FixedSize[源代码]

基类:Sizer

This sizer simply returns a fixed size for any operation. Size can be controlled by the number of tranches that a system wishes to use to scale into trades by specifying the tranches parameter.

This class has been refactored from legacy params tuple to the new ParameterDescriptor system for Day 36-38 of the metaprogramming removal project.

Params:
  • stake (default: 1)

  • tranches (default: 1)

stake

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

tranches

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

__init__(**kwargs)[源代码]

Initialize the FixedSize sizer.

参数:

**kwargs -- Keyword arguments for sizer configuration including stake and tranches parameters.

setsizing(stake)[源代码]

Set the fixed stake size for operations.

参数:

stake (int) -- The stake size to set. If tranches > 1, this value will be divided by tranches and stored as the internal stake.

backtrader.sizers.fixedsize.SizerFix

FixedSize 的别名

class backtrader.sizers.fixedsize.FixedReverser[源代码]

基类:Sizer

This sizer returns the needes fixed size to reverse an open position or the fixed size to open one

  • To open a position: return the param stake

  • To reverse a position: return 2 * stake

Params:
  • stake (default: 1)

stake

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

__init__(**kwargs)[源代码]

Initialize the FixedReverser sizer.

参数:

**kwargs -- Keyword arguments for sizer configuration including stake parameter.

class backtrader.sizers.fixedsize.FixedSizeTarget[源代码]

基类:Sizer

This sizer simply returns a fixed target size, useful when coupled with Target Orders and specifically cerebro.target_order_size(). Size can be controlled by the number of tranches that a system wishes to use to scale into trades by specifying the tranches parameter.

Params:
  • stake (default: 1)

  • tranches (default: 1)

stake

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

tranches

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

__init__(**kwargs)[源代码]

Initialize the FixedSizeTarget sizer.

参数:

**kwargs -- Keyword arguments for sizer configuration including stake and tranches parameters.

setsizing(stake)[源代码]

Set the fixed target stake size for operations.

参数:

stake (int) -- The target stake size to set. If tranches > 1, this value will be divided by tranches and adjusted based on current position size to reach the target.