Skip to main content

Triangle

Struct Triangle 

Source
pub struct Triangle {
    pub n_origins: usize,
    pub n_devs: usize,
    pub data: Vec<f64>,
}
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.

Fields§

§n_origins: usize

Number of origin (accident / policy) periods.

§n_devs: usize

Number of development periods.

§data: Vec<f64>

Row-major buffer of length n_origins * n_devs.

Implementations§

Source§

impl Triangle

Source

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.

Source

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.

Source

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]);
Source

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.).

Source

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.

Source

pub fn get(&self, i: usize, j: usize) -> f64

Cumulative value at origin i, development j. NaN if unobserved.

Source

pub fn origin_row(&self, i: usize) -> &[f64]

Observed cumulative slice for origin i (length n - i, excluding trailing NaNs).

Source

pub fn n(&self) -> usize

Square triangle dimension min(n_origins, n_devs).

Source

pub fn is_empty(&self) -> bool

true iff the triangle has zero origins or zero development periods.

Source

pub fn view(&self) -> TriangleView<'_>

Borrow as a TriangleView.

Source

pub fn latest_diagonal(&self) -> Vec<f64>

Extract the latest-observed cumulative anti-diagonal.

Source

pub fn to_incremental(&self) -> Self

Convert this cumulative triangle to an incremental Triangle.

Source

pub fn ldfs(&self, tail: f64) -> Result<DevelopmentFactors, ValidationError>

Volume-weighted development factors and CDFs (tail = 1.0 for fully developed).

Source

pub fn chain_ladder( &self, tail: f64, ) -> Result<ChainLadderProjection, ValidationError>

Volume-weighted Chain-Ladder projection (tail = 1.0 for fully developed).

Source

pub fn mack(&self, tail: f64) -> Result<Mack, ValidationError>

Mack (1993) distribution-free chain-ladder reserve & standard error analysis.

Source

pub fn mack_with_policy( &self, tail: f64, policy: MonotonicityPolicy, ) -> Result<Mack, ValidationError>

Mack (1993) analysis under an explicit MonotonicityPolicy.

Source

pub fn merz_wuthrich(&self) -> Result<MerzWuthrichResult, ValidationError>

Merz & Wüthrich (2008) 1-year Solvency II Claims Development Result (CDR) MSEP.

Source

pub fn bf( &self, expected_ultimate: &[f64], tail: f64, ) -> Result<BornhuetterFergusonProjection, ValidationError>

Bornhuetter–Ferguson projection using volume-weighted LDFs.

Source

pub fn cape_cod( &self, premium: &[f64], tail: f64, ) -> Result<CapeCodProjection, ValidationError>

Cape Cod projection using volume-weighted LDFs.

Source

pub fn bootstrap_odp( &self, tail: f64, options: OdpBootstrapOptions, ) -> Result<OdpBootstrapResult, ValidationError>

Run England & Verrall / Shapland ODP bootstrap reserve simulation.

Source

pub fn exhibit( &self, premium: Option<&[f64]>, expected_ultimate: Option<&[f64]>, tail: f64, ) -> Result<ExhibitBundle, ValidationError>

Build a complete JSON-serializable reserving exhibit bundle.

Source

pub fn benktander( &self, expected_ultimate: &[f64], iterations: usize, tail: f64, ) -> Result<BenktanderProjection, ValidationError>

Benktander (1976) / Hovinen credibility projection using volume-weighted LDFs.

Source

pub fn generalized_cape_cod( &self, premium: &[f64], decay: f64, tail: f64, ) -> Result<GeneralizedCapeCodProjection, ValidationError>

Generalized Cape Cod (Gluck 1997) decay-weighted projection.

Source

pub fn brosius(&self, tail: f64) -> Result<Brosius, ValidationError>

Brosius (1993) OLS credibility development projection.

Source

pub fn fit_odp(&self, tail: f64) -> Result<OdpFit, ValidationError>

Fit the Over-Dispersed Poisson GLM (fit_odp) with strict monotonicity.

Source

pub fn glm( &self, options: &GlmOptions, ) -> Result<GlmReservingResult, ValidationError>

Fit a reserving GLM (Odp, Gamma, Tweedie, or LogNormal) via Householder QR IRLS.

Source

pub fn clark_ldf( &self, options: &ClarkOptions, ) -> Result<ClarkMleResult, ValidationError>

Fit Clark (2003) LDF parametric growth-curve MLE.

Source

pub fn clark_cape_cod( &self, premium: &[f64], options: &ClarkOptions, ) -> Result<ClarkMleResult, ValidationError>

Fit Clark (2003) Cape Cod parametric growth-curve MLE.

Source

pub fn ptf(&self, options: &PtfOptions) -> Result<PtfResult, ValidationError>

Fit Barnett & Zehnwirth (2000) Probabilistic Trend Family log-linear regression.

Source

pub fn diagnostics(&self) -> TriangleDiagnostics

Structural triangle diagnostics (observed/missing counts, monotonicity, zero latest).

Trait Implementations§

Source§

impl Clone for Triangle

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Triangle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Triangle

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Triangle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Triangle

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Triangle

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Triangle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.