nautechsystems/nautilus_trader · error
`calculate_from_realized_pnls` {IMPL_ERR} `{}`
Error message
`calculate_from_realized_pnls` {IMPL_ERR} `{}` What it means
The default `calculate_from_realized_pnls` on the statistic trait panics when the concrete statistic has not overridden it and the analyzer feeds realized PnL values. It signals that the statistic does not support realized-PnL input.
Source
Thrown at crates/analysis/src/statistic.rs:57
/// Returns the name of this statistic for display and identification purposes.
fn name(&self) -> String;
/// Calculates the statistic from time-indexed returns data.
///
/// # Panics
///
/// Panics if this method is not implemented for the specific statistic.
fn calculate_from_returns(&self, returns: &Returns) -> Option<Self::Item> {
panic!("`calculate_from_returns` {IMPL_ERR} `{}`", self.name());
}
/// Calculates the statistic from realized profit and loss values.
///
/// # Panics
///
/// Panics if this method is not implemented for the specific statistic.
fn calculate_from_realized_pnls(&self, realized_pnls: &[f64]) -> Option<Self::Item> {
panic!(
"`calculate_from_realized_pnls` {IMPL_ERR} `{}`",
self.name()
);
}
/// Calculates the statistic from position data.
///
/// # Panics
///
/// Panics if this method is not implemented for the specific statistic.
fn calculate_from_positions(&self, positions: &[Position]) -> Option<Self::Item> {
panic!("`calculate_from_positions` {IMPL_ERR} `{}`", self.name());
}
/// Calculates the statistic from time-indexed strategy returns relative to a benchmark.
///
/// Defaults to `None`; only benchmark-relative statistics (beta, alpha, information
/// ratio, tracking error, Treynor ratio) override this method. The `None` defaultView on GitHub (pinned to 18893faf8b)
Solutions
- Implement `calculate_from_realized_pnls` on the statistic.
- Or compute the statistic from its supported input type (returns or positions).
- Or exclude the statistic from realized-PnL analysis paths.
Example fix
// before
impl PerformanceStatistic for SharpeRatio {
fn calculate_from_returns(&self, r: &Returns) -> Option<f64> { Some(calc(r)) }
}
analyzer.calculate_from_realized_pnls(&pnls); // panic
// after
impl PerformanceStatistic for SharpeRatio {
fn calculate_from_returns(&self, r: &Returns) -> Option<f64> { Some(calc(r)) }
fn calculate_from_realized_pnls(&self, pnls: &[f64]) -> Option<f64> {
Some(calc_from_pnls(pnls))
}
} Defensive patterns
Strategy: type-guard
Validate before calling
let pnls_based = analyzer.statistics().iter().filter(|s| s.supports_realized_pnls()).cloned().collect::<Vec<_>>(); assert!(!pnls_based.is_empty(), "no registered statistic supports realized PnL input");
Prevention
- Override every calculation method of the statistic trait, returning None when unsupported
- Match analyzer input type (returns vs pnls vs positions) to registered statistics
- Unit-test custom statistics with each input type
When it happens
Trigger: Portfolio/analyzer computing statistics from `realized_pnls: &[f64]` for a statistic that only implements returns- or positions-based calculation.
Common situations: Returns-based statistics (e.g. Sharpe on returns) registered into a realized-PnL analysis path; custom statistics with incomplete trait implementations.
Related errors
- `calculate_from_returns` {IMPL_ERR} `{}`
- `calculate_from_positions` {IMPL_ERR} `{}`
- `handle_quote_tick` {IMPL_ERR} `{}`
- Warning: Column name '{column_name}' is not of type i64.
- Warning: Statistics not available for column '{column_name}'
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/566a8bc8b6db4404.
Report an issue: GitHub.