pub struct Triangle { /* private fields */ }Expand description
An n_origins × n_devs cumulative loss triangle in row-major layout.
data[i * n_devs + j] is the cumulative loss for origin i at
development age j. Unobserved cells are NaN. The kernels assume the
triangle is square (n_origins == n_devs) and that cell (i, j) is
observed for i + j ≤ n - 1.
Equality (PartialEq) treats two NaN cells at the same position as equal
so tri == tri.clone() holds for triangles with unobserved cells.
Deserialization maps JSON null to NaN and validates via Self::try_new.
Implementations§
Source§impl Triangle
impl Triangle
Sourcepub fn new(n_origins: usize, n_devs: usize, data: Vec<f64>) -> Self
pub fn new(n_origins: usize, n_devs: usize, data: Vec<f64>) -> Self
Construct a triangle from a row-major slice without validation.
Callers must ensure data.len() == n_origins * n_devs. Use
Self::try_new at external ingress boundaries when full validation
(square, finite, non-negative observed cells) is required.
Sourcepub fn try_new(
n_origins: usize,
n_devs: usize,
data: Vec<f64>,
) -> Result<Self, ValidationError>
pub fn try_new( n_origins: usize, n_devs: usize, data: Vec<f64>, ) -> Result<Self, ValidationError>
Construct and validate a square cumulative triangle.
This enforces the same shape, finiteness, and non-negative observed-cell contract used by the checked reserving engines. Row monotonicity is still method-specific and is validated by those engines.
Sourcepub fn try_from_upper_rows(rows: &[&[f64]]) -> Result<Self, ValidationError>
pub fn try_from_upper_rows(rows: &[&[f64]]) -> Result<Self, ValidationError>
Construct and validate a square cumulative triangle directly from
ragged upper-triangle rows (no manual f64::NAN padding required).
Row i must have length n - i where n = rows.len() > 0.
For owned Vec<Vec<f64>> inputs, see Self::try_from_rows.
§Example
use reserving_kernels::Triangle;
let tri = Triangle::try_from_upper_rows(&[
&[100.0, 160.0, 195.0],
&[120.0, 190.0],
&[135.0],
])?;
assert_eq!(tri.n(), 3);
assert_eq!(tri.latest_diagonal(), vec![195.0, 190.0, 135.0]);Sourcepub fn try_from_rows<R: AsRef<[f64]>>(
rows: &[R],
) -> Result<Self, ValidationError>
pub fn try_from_rows<R: AsRef<[f64]>>( rows: &[R], ) -> Result<Self, ValidationError>
Generic variant of Self::try_from_upper_rows accepting any slice of
row buffers (&[Vec<f64>], &[&[f64]], etc.).
Sourcepub fn try_from_incremental_rows(
rows: &[&[f64]],
) -> Result<Self, ValidationError>
pub fn try_from_incremental_rows( rows: &[&[f64]], ) -> Result<Self, ValidationError>
Construct and validate a square cumulative triangle by cumulating incremental upper-triangle rows along each origin period.
Row i must have length n - i where n = rows.len() > 0.
Sourcepub fn get(&self, i: usize, j: usize) -> f64
pub fn get(&self, i: usize, j: usize) -> f64
Cumulative value at origin i, development j. NaN if unobserved.
Sourcepub fn origin_row(&self, i: usize) -> &[f64]
pub fn origin_row(&self, i: usize) -> &[f64]
Observed cumulative slice for origin i (length n - i, excluding trailing NaNs).
Sourcepub fn data(&self) -> &[f64]
pub fn data(&self) -> &[f64]
Borrow the underlying row-major slice of length n_origins * n_devs.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true iff the triangle has zero origins or zero development periods.
Sourcepub fn view(&self) -> TriangleView<'_>
pub fn view(&self) -> TriangleView<'_>
Borrow as a TriangleView.
Sourcepub fn latest_diagonal(&self) -> Vec<f64>
pub fn latest_diagonal(&self) -> Vec<f64>
Extract the latest-observed cumulative anti-diagonal.
Sourcepub fn to_incremental(&self) -> Self
pub fn to_incremental(&self) -> Self
Convert this cumulative triangle to an incremental Triangle.
Sourcepub fn ldfs(&self, tail: f64) -> Result<DevelopmentFactors, ValidationError>
pub fn ldfs(&self, tail: f64) -> Result<DevelopmentFactors, ValidationError>
Volume-weighted development factors and CDFs (tail = 1.0 for fully developed).
Sourcepub fn chain_ladder(
&self,
tail: f64,
) -> Result<ChainLadderProjection, ValidationError>
pub fn chain_ladder( &self, tail: f64, ) -> Result<ChainLadderProjection, ValidationError>
Volume-weighted Chain-Ladder projection (tail = 1.0 for fully developed).
Sourcepub fn mack(&self, tail: f64) -> Result<Mack, ValidationError>
pub fn mack(&self, tail: f64) -> Result<Mack, ValidationError>
Mack (1993) distribution-free chain-ladder reserve & standard error analysis.
Sourcepub fn mack_with_policy(
&self,
tail: f64,
policy: MonotonicityPolicy,
) -> Result<Mack, ValidationError>
pub fn mack_with_policy( &self, tail: f64, policy: MonotonicityPolicy, ) -> Result<Mack, ValidationError>
Mack (1993) analysis under an explicit MonotonicityPolicy.
Sourcepub fn merz_wuthrich(&self) -> Result<MerzWuthrichResult, ValidationError>
pub fn merz_wuthrich(&self) -> Result<MerzWuthrichResult, ValidationError>
Merz & Wüthrich (2008) 1-year Solvency II Claims Development Result (CDR) MSEP.
Sourcepub fn merz_wuthrich_with_policy(
&self,
policy: MonotonicityPolicy,
) -> Result<MerzWuthrichResult, ValidationError>
pub fn merz_wuthrich_with_policy( &self, policy: MonotonicityPolicy, ) -> Result<MerzWuthrichResult, ValidationError>
Merz & Wüthrich (2008) 1-year CDR MSEP under an explicit MonotonicityPolicy.
Sourcepub fn bf(
&self,
expected_ultimate: &[f64],
tail: f64,
) -> Result<BornhuetterFergusonProjection, ValidationError>
pub fn bf( &self, expected_ultimate: &[f64], tail: f64, ) -> Result<BornhuetterFergusonProjection, ValidationError>
Bornhuetter–Ferguson projection using volume-weighted LDFs.
Sourcepub fn cape_cod(
&self,
premium: &[f64],
tail: f64,
) -> Result<CapeCodProjection, ValidationError>
pub fn cape_cod( &self, premium: &[f64], tail: f64, ) -> Result<CapeCodProjection, ValidationError>
Cape Cod projection using volume-weighted LDFs.
Sourcepub fn bootstrap_odp(
&self,
tail: f64,
options: OdpBootstrapOptions,
) -> Result<OdpBootstrapResult, ValidationError>
pub fn bootstrap_odp( &self, tail: f64, options: OdpBootstrapOptions, ) -> Result<OdpBootstrapResult, ValidationError>
Run England & Verrall / Shapland ODP bootstrap reserve simulation.
Sourcepub fn exhibit(
&self,
premium: Option<&[f64]>,
expected_ultimate: Option<&[f64]>,
tail: f64,
) -> Result<ExhibitBundle, ValidationError>
pub fn exhibit( &self, premium: Option<&[f64]>, expected_ultimate: Option<&[f64]>, tail: f64, ) -> Result<ExhibitBundle, ValidationError>
Build a complete JSON-serializable reserving exhibit bundle.
Sourcepub fn benktander(
&self,
expected_ultimate: &[f64],
iterations: usize,
tail: f64,
) -> Result<BenktanderProjection, ValidationError>
pub fn benktander( &self, expected_ultimate: &[f64], iterations: usize, tail: f64, ) -> Result<BenktanderProjection, ValidationError>
Benktander (1976) / Hovinen credibility projection using volume-weighted LDFs.
Sourcepub fn generalized_cape_cod(
&self,
premium: &[f64],
decay: f64,
tail: f64,
) -> Result<GeneralizedCapeCodProjection, ValidationError>
pub fn generalized_cape_cod( &self, premium: &[f64], decay: f64, tail: f64, ) -> Result<GeneralizedCapeCodProjection, ValidationError>
Generalized Cape Cod (Gluck 1997) decay-weighted projection.
Sourcepub fn brosius(&self, tail: f64) -> Result<Brosius, ValidationError>
pub fn brosius(&self, tail: f64) -> Result<Brosius, ValidationError>
Brosius (1993) OLS credibility development projection.
Sourcepub fn fit_odp(&self, tail: f64) -> Result<OdpFit, ValidationError>
pub fn fit_odp(&self, tail: f64) -> Result<OdpFit, ValidationError>
Fit the Over-Dispersed Poisson GLM (fit_odp) with strict monotonicity.
Sourcepub fn glm(
&self,
options: &GlmOptions,
) -> Result<GlmReservingResult, ValidationError>
pub fn glm( &self, options: &GlmOptions, ) -> Result<GlmReservingResult, ValidationError>
Fit a reserving GLM (Odp, Gamma, Tweedie, or LogNormal) via Householder QR IRLS.
Sourcepub fn clark_ldf(
&self,
options: &ClarkOptions,
) -> Result<ClarkMleResult, ValidationError>
pub fn clark_ldf( &self, options: &ClarkOptions, ) -> Result<ClarkMleResult, ValidationError>
Fit Clark (2003) LDF parametric growth-curve MLE.
Sourcepub fn clark_cape_cod(
&self,
premium: &[f64],
options: &ClarkOptions,
) -> Result<ClarkMleResult, ValidationError>
pub fn clark_cape_cod( &self, premium: &[f64], options: &ClarkOptions, ) -> Result<ClarkMleResult, ValidationError>
Fit Clark (2003) Cape Cod parametric growth-curve MLE.
Sourcepub fn ptf(&self, options: &PtfOptions) -> Result<PtfResult, ValidationError>
pub fn ptf(&self, options: &PtfOptions) -> Result<PtfResult, ValidationError>
Fit Barnett & Zehnwirth (2000) Probabilistic Trend Family log-linear regression.
Sourcepub fn diagnostics(&self) -> TriangleDiagnostics
pub fn diagnostics(&self) -> TriangleDiagnostics
Structural triangle diagnostics (observed/missing counts, monotonicity, zero latest).