Risk¶
- class FixedRiskSizer¶
Bases:
PositionSizerFixed-risk position sizer.
- calculate(entry, stop_loss, equity, risk, commission_rate=Ellipsis, exchange_rate=Ellipsis, hard_limit=None, unit_batch_size=Ellipsis, units=1)¶
Calculates the position size quantity for the given risk parameters.
Returns zero when no position is riskable, including for zero exchange rates and equal entry and stop-loss prices.
# Parameters
entry: The entry price.
stop_loss: The stop-loss price.
equity: The account equity.
risk: The positive risk fraction.
commission_rate: The non-negative commission rate.
exchange_rate: The non-negative exchange rate between the instrument quote currency and the account currency.
hard_limit: The optional positive limit for the total quantity.
unit_batch_size: The non-negative unit batch size.
units: The positive number of units to divide the position into.
# Errors
Returns an error if: - A decimal argument is not a decimal.Decimal. - A parameter violates the constraints above. - Decimal arithmetic overflows. - The final size rounds to zero or cannot be represented as a Quantity.
- class PositionSizer¶
Bases:
objectBase class for position sizers.
- calculate(entry, stop_loss, equity, risk, commission_rate=Ellipsis, exchange_rate=Ellipsis, hard_limit=None, unit_batch_size=Ellipsis, units=1)¶
Calculates the position size quantity for the given risk parameters.
# Errors
Always returns NotImplementedError; subclasses override this method.
- instrument¶
Returns the instrument used for position sizing.
- update_instrument(instrument)¶
Updates the instrument used for position sizing.
# Errors
Returns an error if instrument is invalid or its ID differs from the current instrument ID.