{"record":{"id":"566a8bc8b6db4404","repo":"nautechsystems/nautilus_trader","slug":"calculate-from-realized-pnls-impl-err","errorCode":null,"errorMessage":"`calculate_from_realized_pnls` {IMPL_ERR} `{}`","messagePattern":"`calculate_from_realized_pnls` (.+?) `(.+?)`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/analysis/src/statistic.rs","lineNumber":57,"sourceCode":"    /// Returns the name of this statistic for display and identification purposes.\n    fn name(&self) -> String;\n\n    /// Calculates the statistic from time-indexed returns data.\n    ///\n    /// # Panics\n    ///\n    /// Panics if this method is not implemented for the specific statistic.\n    fn calculate_from_returns(&self, returns: &Returns) -> Option<Self::Item> {\n        panic!(\"`calculate_from_returns` {IMPL_ERR} `{}`\", self.name());\n    }\n\n    /// Calculates the statistic from realized profit and loss values.\n    ///\n    /// # Panics\n    ///\n    /// Panics if this method is not implemented for the specific statistic.\n    fn calculate_from_realized_pnls(&self, realized_pnls: &[f64]) -> Option<Self::Item> {\n        panic!(\n            \"`calculate_from_realized_pnls` {IMPL_ERR} `{}`\",\n            self.name()\n        );\n    }\n\n    /// Calculates the statistic from position data.\n    ///\n    /// # Panics\n    ///\n    /// Panics if this method is not implemented for the specific statistic.\n    fn calculate_from_positions(&self, positions: &[Position]) -> Option<Self::Item> {\n        panic!(\"`calculate_from_positions` {IMPL_ERR} `{}`\", self.name());\n    }\n\n    /// Calculates the statistic from time-indexed strategy returns relative to a benchmark.\n    ///\n    /// Defaults to `None`; only benchmark-relative statistics (beta, alpha, information\n    /// ratio, tracking error, Treynor ratio) override this method. The `None` default","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/analysis/src/statistic.rs#L39-L75","documentation":"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.","triggerScenarios":"Portfolio/analyzer computing statistics from `realized_pnls: &[f64]` for a statistic that only implements returns- or positions-based calculation.","commonSituations":"Returns-based statistics (e.g. Sharpe on returns) registered into a realized-PnL analysis path; custom statistics with incomplete trait implementations.","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."],"exampleFix":"// before\nimpl PerformanceStatistic for SharpeRatio {\n    fn calculate_from_returns(&self, r: &Returns) -> Option<f64> { Some(calc(r)) }\n}\nanalyzer.calculate_from_realized_pnls(&pnls); // panic\n// after\nimpl PerformanceStatistic for SharpeRatio {\n    fn calculate_from_returns(&self, r: &Returns) -> Option<f64> { Some(calc(r)) }\n    fn calculate_from_realized_pnls(&self, pnls: &[f64]) -> Option<f64> {\n        Some(calc_from_pnls(pnls))\n    }\n}","handlingStrategy":"type-guard","validationCode":"let pnls_based = analyzer.statistics().iter().filter(|s| s.supports_realized_pnls()).cloned().collect::<Vec<_>>();\nassert!(!pnls_based.is_empty(), \"no registered statistic supports realized PnL input\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["analysis","statistics","rust","trait"],"backgroundTag":"method-not-implemented","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}