FRENESDE

Sizers

By default, each buy() is for 1 unit. A sizer decides for you how many units to buy or sell; you add it with cerebro.addsizer().
cerebro.addsizer(bt.sizers.FixedSize, stake=10) always buys 10 units: it is a fixed size, simple but blind to price and volatility.
cerebro.addsizer(bt.sizers.PercentSizer, percents=20) commits about 20% of the available cash: the size adapts to the price and to how the capital evolves.
For a custom rule, such as risking 1% of capital between entry and stop, you write a class inheriting from bt.Sizer and code _getsizing(). A size passed directly to buy() still takes priority.

Examples

Key terms

Sizer
Object that computes order sizes
FixedSize
Sizer that always uses the same quantity
PercentSizer
Sizer that commits a percentage of cash
stake
FixedSize’s quantity parameter
Take the mission on Doji Academy

← Back to the index