nautechsystems/nautilus_trader · error

price must be positive for inverse notional valuation

Error message

price must be positive for inverse notional valuation

What it means

In the inverse notional formula, quantity*multiplier is divided by the price; dividing by zero or a non-positive price is mathematically invalid, so try_notional_value ensures price.is_positive() before the division and raises this error otherwise.

Source

Thrown at crates/model/src/instruments/mod.rs:712

            } else {
                break;
            }
        }

        prices
    }
}

pub(crate) fn try_notional_value(
    quantity: Quantity,
    price: Price,
    multiplier: Quantity,
    is_inverse: bool,
    use_quote_for_inverse: bool,
    currency: Currency,
) -> anyhow::Result<Money> {
    let amount = if is_inverse && !use_quote_for_inverse {
        anyhow::ensure!(
            price.is_positive(),
            "price must be positive for inverse notional valuation"
        );
        quantity
            .as_decimal()
            .checked_mul(multiplier.as_decimal())
            .and_then(|value| value.checked_div(price.as_decimal()))
            .ok_or_else(|| anyhow::anyhow!("inverse notional calculation overflow"))?
    } else if is_inverse {
        quantity.as_decimal()
    } else {
        quantity
            .as_decimal()
            .checked_mul(multiplier.as_decimal())
            .and_then(|value| value.checked_mul(price.as_decimal()))
            .ok_or_else(|| anyhow::anyhow!("notional calculation overflow"))?
    };

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Guard price.is_positive() before computing inverse notional and skip/wait until a real price is available.
  2. Use use_quote_for_inverse=true if quote-denominated notional is acceptable and avoids the division.
  3. Fix the price source so zero/negative prices never reach valuation (e.g. reject zero ticks at ingestion).

Example fix

// before
let notional = instrument.calculate_notional_value(price, qty, None)?;
// after
if !price.is_positive() { return Ok(None); } // or wait for valid price
let notional = instrument.calculate_notional_value(price, qty, None)?;
Defensive patterns

Strategy: validation

Validate before calling

if !price.is_positive() { return Ok(None); } // wait for a valid market price

Try / catch

// Rust
let notional = instrument
    .try_calculate_notional_value(price, qty, None)
    .ok(); // None until a positive price exists

Prevention

When it happens

Trigger: Calling try_calculate_notional_value (via calculate_notional_value's Result path) on an inverse instrument with use_quote_for_inverse=false and a price of zero or negative, typically a mid/last price computed as 0 from empty market data.

Common situations: Startup before any quotes arrive (price initialized to 0), a stale/zero last trade price in backtests, or a division-derived price that collapsed to zero.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/47bf31b07351f330. Report an issue: GitHub.