pub fn calculate_fixed_risk_position_size(
instrument: &InstrumentAny,
entry: Price,
stop_loss: Price,
equity: Money,
risk: Decimal,
commission_rate: Decimal,
exchange_rate: Decimal,
hard_limit: Option<Decimal>,
unit_batch_size: Decimal,
units: usize,
) -> CorrectnessResult<Quantity>Expand description
Calculates the position size based on fixed risk parameters.
exchange_rate converts the instrument’s quote currency to the equity currency.
Inverse futures, perpetuals, and futures spreads use reciprocal-price PnL directly
when equity uses the instrument’s base currency. Otherwise, they value that PnL in quote currency
at the stop-loss price before conversion.
Inverse options and option spreads retain premium-based sizing.
Reciprocal-price sizing requires positive prices.
The returned quantity rounds down within the risk budget and quantity limits.
§Errors
Returns an error if an input is invalid, decimal arithmetic overflows, or
the final size rounds to zero or cannot be represented as a [Quantity].