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.

Example

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

Bases: 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)[source]

Initialize the PercentSizer sizer.

Parameters:

**kwargs – Keyword arguments for sizer configuration.

class backtrader.sizers.percents_sizer.AllInSizer[source]

Bases: 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[source]

Bases: 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[source]

Bases: 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