backtrader.sizers.percents_sizer module

Percent Sizer Module - Percentage-based position sizing.

This module provides sizers that calculate position size based on a percentage of available cash.

Classes:

PercentSizer: Uses percentage of cash for sizing. AllInSizer: Uses 100% of available cash. PercentSizerInt: PercentSizer returning int values. AllInSizerInt: AllInSizer returning int values.

示例

>>> cerebro.addsizer(bt.sizers.PercentSizer, percents=20)
class backtrader.sizers.percents_sizer.PercentSizer[源代码]

基类:Sizer

This sizer return percentages of available cash

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

Params:
  • percents (default: 20)

  • retint (default: False) return an int size or rather the float value

percents

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

retint

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 PercentSizer sizer.

参数:

**kwargs -- Keyword arguments for sizer configuration.

class backtrader.sizers.percents_sizer.AllInSizer[源代码]

基类:PercentSizer

This sizer return all available cash of broker

Params:
  • percents (default: 100)

percents

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

class backtrader.sizers.percents_sizer.PercentSizerInt[源代码]

基类:PercentSizer

This sizer return percentages of available cash in the form of size truncated to an int

Params:
  • percents (default: 20)

retint

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

class backtrader.sizers.percents_sizer.AllInSizerInt[源代码]

基类:PercentSizerInt

This sizer returns all available cash of broker with the size truncated to an int

Params:
  • percents (default: 100)

percents

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