nautechsystems/nautilus_trader · error

Derive {label} cannot be represented as f64

Error message

Derive {label} cannot be represented as f64

What it means

parse_option_greeks converts rust_decimal::Decimal greek values (delta, gamma, etc.) to f64 for OptionGreeks. If a Decimal cannot be represented as f64 (e.g. NaN or infinite decimal values that to_f64 rejects), this error is thrown naming the greek label.

Source

Thrown at crates/adapters/derive/src/websocket/parse.rs:708

///
/// Returns `Ok(None)` when the ticker does not carry option pricing.
///
/// # Errors
///
/// Returns an error when the ticker timestamp is negative or overflows.
pub fn parse_option_greeks(
    msg: &DeriveTickerMsg,
    ts_init: UnixNanos,
) -> anyhow::Result<Option<OptionGreeks>> {
    let Some(pricing) = msg.data.option_pricing() else {
        return Ok(None);
    };
    let instrument_id = msg.data.instrument_id();
    let ts_event = ticker_ts_event(msg.data.timestamp())?;
    let to_f64 = |label: &str, value: rust_decimal::Decimal| {
        value
            .to_f64()
            .ok_or_else(|| anyhow::anyhow!("Derive {label} cannot be represented as f64"))
    };

    Ok(Some(OptionGreeks {
        instrument_id,
        convention: GreeksConvention::BlackScholes,
        greeks: OptionGreekValues {
            delta: to_f64("delta", pricing.delta)?,
            gamma: to_f64("gamma", pricing.gamma)?,
            vega: to_f64("vega", pricing.vega)?,
            theta: to_f64("theta", pricing.theta)?,
            rho: to_f64("rho", pricing.rho)?,
        },
        mark_iv: Some(to_f64("iv", pricing.iv)?),
        bid_iv: Some(to_f64("bid_iv", pricing.bid_iv)?),
        ask_iv: Some(to_f64("ask_iv", pricing.ask_iv)?),
        underlying_price: Some(to_f64("forward_price", pricing.forward_price)?),
        open_interest: msg
            .data

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Skip/ignore the greeks update for that instrument when values are non-finite
  2. Sanitize incoming decimals (reject NaN) before parsing
  3. Check whether Derive is emitting NaN for the specific instrument and filter those ticks

Example fix

// before
let to_f64 = |label: &str, value: Decimal| value.to_f64().ok_or_else(|| anyhow!("Derive {label} cannot be represented as f64"));
// after (skip invalid instead of failing the whole tick)
let to_f64 = |label: &str, value: Decimal| value.to_f64().filter(|v| v.is_finite());
if greeks.iter().any(|(l, v)| to_f64(l, *v).is_none()) { return Ok(None); }
Defensive patterns

Strategy: try-catch

Validate before calling

fn greeks_are_finite(v: &rust_decimal::Decimal) -> bool { v.is_finite() && v.to_f64().map(|f| f.is_finite()).unwrap_or(false) }

Type guard

fn to_f64_checked(v: rust_decimal::Decimal) -> Option<f64> { v.to_f64().filter(|f| f.is_finite()) }

Try / catch

match parse_option_greeks(&msg) { Ok(Some(g)) => apply(g), Ok(None) => {}, Err(e) if e.to_string().contains("cannot be represented as f64") => warn!("skipping non-finite greeks: {e}"), Err(e) => return Err(e) }

Prevention

When it happens

Trigger: A Derive option ticker payload with option_pricing whose greek decimal is NaN or not convertible to f64; the closure to_f64 fails for any greek field being mapped.

Common situations: Venue sending NaN greeks for illiquid/expiring options; edge-case decimals outside f64 range; instruments without valid pricing models on Derive's side.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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