Skip to main content

reserving_kernels/
benktander.rs

1//! Benktander–Hovinen iterated Bornhuetter–Ferguson credibility reserving method.
2//!
3//! Implements:
4//!
5//! * Benktander (1976), *An Approach to Credibility in Calculating IBNR for
6//!   Casualty Excess Reinsurance*, Actuarial Review / ASTIN.
7//! * Hovinen (1981), *Additive and Continuous IBNR*, ASTIN Colloquium.
8//! * Mack (2000), *Credible Claims Reserve: The Benktander Method*, ASTIN
9//!   Bulletin, Vol. 30, No. 2, pp. 333–347.
10//! * Friedland (2010), *Estimating Unpaid Claims Using Basic Techniques*, CAS,
11//!   Chapter 10.
12//!
13//! ## Closed-Form Recursion
14//!
15//! Starting from an a priori ultimate `U_i^{(0)} = E_i` and maturity percentage
16//! `p_i = 1 / CDF_{d_i}` (unreported fraction `q_i = 1 - p_i`), the `m`-step
17//! Benktander ultimate is:
18//!
19//! ```text
20//! U_i^{(m)} = C_{i, d_i} + q_i · U_i^{(m - 1)}
21//!           = (1 - q_i^m) · U_i^{CL} + q_i^m · E_i
22//! ```
23//!
24//! Special cases:
25//! * `m = 0`: pure a priori Expected Claims (`Z_i = 0`).
26//! * `m = 1`: Bornhuetter–Ferguson (`Z_i = p_i`).
27//! * `m = 2`: classical Benktander (`Z_i = 1 - q_i^2 = p_i (2 - p_i)`).
28//! * `m → ∞`: classical Chain Ladder (`Z_i → 1`).
29
30use crate::apriori::{AprioriInput, build_apriori};
31use crate::chain_ladder::latest_observed_by_origin;
32use crate::ldf::DevelopmentFactors;
33use crate::types::TriangleView;
34use crate::validate::{
35    MonotonicityPolicy, ValidationError, validate_development_factor_slices,
36    validate_latest_and_dev, validate_monotone_cumulative, validate_nonnegative_finite_slice,
37    validate_nonnegative_finite_vector, validate_triangle,
38};
39
40/// Benktander–Hovinen projection result.
41#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
42pub struct BenktanderProjection {
43    /// Number of iterations `m` applied (`m = 1` is BF, `m = 2` is Benktander).
44    pub iterations: usize,
45    /// Latest observed cumulative value by origin.
46    pub latest: Vec<f64>,
47    /// Latest observed development index by origin.
48    pub latest_dev: Vec<usize>,
49    /// Maturity percentage `p_i = 1 / cdf[latest_dev[i]]` by origin.
50    pub maturity: Vec<f64>,
51    /// Implicit credibility weight `Z_i = 1 - (1 - p_i)^m` placed on Chain Ladder.
52    pub credibility_weights: Vec<f64>,
53    /// A priori expected ultimate loss by origin.
54    pub expected_ultimate: Vec<f64>,
55    /// Benktander reserve by origin (`ultimates[i] - latest[i]`).
56    pub reserves: Vec<f64>,
57    /// Benktander ultimate by origin.
58    pub ultimates: Vec<f64>,
59    /// Total latest observed value.
60    pub total_latest: f64,
61    /// Total a priori expected ultimate.
62    pub total_expected_ultimate: f64,
63    /// Total Benktander reserve.
64    pub total_reserve: f64,
65    /// Total Benktander ultimate.
66    pub total_ultimate: f64,
67}
68
69/// Mack (2000, Theorem 1) MSE-optimal credibility weight `Z_i^* = p_i / (p_i + t_i)`
70/// for combining Chain Ladder and a priori ultimates, where `p_i` is maturity
71/// (`1 / CDF`) and `t_i = Var(process) / Var(prior)` is the variance ratio.
72///
73/// Notice `t_i = 0` yields Chain Ladder (`Z = 1`), `t_i = 1 - p_i` yields BF
74/// (`Z = p_i`), and `t_i = (1 - p_i)^2 / (2 - p_i)` yields Benktander.
75#[inline]
76pub fn mack_optimal_credibility(
77    maturity: f64,
78    variance_ratio_t: f64,
79) -> Result<f64, ValidationError> {
80    if !maturity.is_finite() || !variance_ratio_t.is_finite() {
81        return Err(ValidationError::NotFinite);
82    }
83    if !(0.0..=1.0).contains(&maturity) {
84        return Err(ValidationError::InvalidMaturity {
85            index: 0,
86            value: maturity,
87        });
88    }
89    if variance_ratio_t < 0.0 {
90        return Err(ValidationError::Negative);
91    }
92    let denom = maturity + variance_ratio_t;
93    if denom <= 0.0 {
94        Ok(0.0)
95    } else {
96        Ok(maturity / denom)
97    }
98}
99
100/// Checked Benktander–Hovinen reserving service.
101pub struct BenktanderEngine;
102
103impl BenktanderEngine {
104    /// Project Benktander ultimates from explicit expected ultimates with
105    /// `iterations` steps (`iterations = 2` is standard Benktander).
106    pub fn project_from_expected_ultimate(
107        cumulative: &TriangleView<'_>,
108        factors: &DevelopmentFactors,
109        expected_ultimate: &[f64],
110        iterations: usize,
111    ) -> Result<BenktanderProjection, ValidationError> {
112        Self::project_with_policy(
113            cumulative,
114            factors,
115            expected_ultimate,
116            iterations,
117            MonotonicityPolicy::Strict,
118        )
119    }
120
121    /// Project Benktander ultimates under an explicit [`MonotonicityPolicy`].
122    pub fn project_with_policy(
123        cumulative: &TriangleView<'_>,
124        factors: &DevelopmentFactors,
125        expected_ultimate: &[f64],
126        iterations: usize,
127        policy: MonotonicityPolicy,
128    ) -> Result<BenktanderProjection, ValidationError> {
129        validate_triangle(cumulative)?;
130        if policy == MonotonicityPolicy::Strict {
131            validate_monotone_cumulative(cumulative)?;
132        }
133        validate_development_factor_slices(
134            &factors.ldfs,
135            &factors.cdfs,
136            factors.tail,
137            cumulative.n_devs,
138            "Benktander factor",
139        )?;
140        validate_nonnegative_finite_vector(expected_ultimate, cumulative.n_origins)?;
141
142        let n = cumulative.n_origins;
143        let mut latest = vec![0.0; n];
144        let mut latest_dev = vec![0usize; n];
145        latest_observed_by_origin(
146            cumulative.data,
147            cumulative.n_origins,
148            cumulative.n_devs,
149            &mut latest,
150            &mut latest_dev,
151        );
152        validate_latest_and_dev(&latest, &latest_dev, &factors.cdfs)?;
153
154        let mut maturity = vec![0.0; n];
155        let mut credibility_weights = vec![0.0; n];
156        let mut ultimates = vec![0.0; n];
157        let mut reserves = vec![0.0; n];
158
159        for i in 0..n {
160            let cdf = factors.cdfs[latest_dev[i]];
161            let p = 1.0 / cdf;
162            let valid_p = match policy {
163                MonotonicityPolicy::Strict => p.is_finite() && (0.0..=1.0).contains(&p),
164                MonotonicityPolicy::AllowNegativeIncrements => {
165                    p.is_finite() && (0.0..2.0).contains(&p)
166                }
167            };
168            if !valid_p {
169                return Err(ValidationError::InvalidMaturity { index: i, value: p });
170            }
171            let q = 1.0 - p;
172            let q_pow = q.powi(iterations.min(i32::MAX as usize) as i32);
173            let z = 1.0 - q_pow;
174            let cl_ult = latest[i] * cdf;
175            let ult = z * cl_ult + q_pow * expected_ultimate[i];
176            let res = ult - latest[i];
177
178            maturity[i] = p;
179            credibility_weights[i] = z;
180            ultimates[i] = ult;
181            reserves[i] = res;
182        }
183
184        validate_nonnegative_finite_slice(&ultimates)?;
185        let total_latest: f64 = latest.iter().sum();
186        let total_expected_ultimate: f64 = expected_ultimate.iter().sum();
187        let total_reserve: f64 = reserves.iter().sum();
188        let total_ultimate: f64 = ultimates.iter().sum();
189
190        if !total_latest.is_finite()
191            || !total_expected_ultimate.is_finite()
192            || !total_reserve.is_finite()
193            || !total_ultimate.is_finite()
194        {
195            return Err(ValidationError::NotFinite);
196        }
197
198        Ok(BenktanderProjection {
199            iterations,
200            latest,
201            latest_dev,
202            maturity,
203            credibility_weights,
204            expected_ultimate: expected_ultimate.to_vec(),
205            reserves,
206            ultimates,
207            total_latest,
208            total_expected_ultimate,
209            total_reserve,
210            total_ultimate,
211        })
212    }
213
214    /// Project Benktander ultimates using a shared [`AprioriInput`] builder.
215    pub fn project_from_apriori(
216        cumulative: &TriangleView<'_>,
217        factors: &DevelopmentFactors,
218        premium_or_exposure: &[f64],
219        apriori: AprioriInput<'_>,
220        iterations: usize,
221    ) -> Result<BenktanderProjection, ValidationError> {
222        let apriori_vec = build_apriori(premium_or_exposure, apriori)?;
223        Self::project_from_expected_ultimate(
224            cumulative,
225            factors,
226            &apriori_vec.expected_ultimate,
227            iterations,
228        )
229    }
230
231    /// Project Benktander ultimates from earned premium and a scalar ELR.
232    pub fn project_from_scalar_elr(
233        cumulative: &TriangleView<'_>,
234        factors: &DevelopmentFactors,
235        earned_premium: &[f64],
236        expected_loss_ratio: f64,
237        iterations: usize,
238    ) -> Result<BenktanderProjection, ValidationError> {
239        Self::project_from_apriori(
240            cumulative,
241            factors,
242            earned_premium,
243            AprioriInput::ScalarElr(expected_loss_ratio),
244            iterations,
245        )
246    }
247}
248
249#[cfg(test)]
250mod tests {
251    use super::*;
252    use crate::bf::BornhuetterFergusonEngine;
253    use crate::chain_ladder::ChainLadderEngine;
254    use crate::ldf::DevelopmentFactorEngine;
255    use crate::types::Triangle;
256
257    fn sample_triangle() -> Triangle {
258        #[rustfmt::skip]
259        let data = vec![
260            1000.0, 1500.0, 1700.0, 1800.0,
261            1200.0, 1800.0, 2000.0, f64::NAN,
262            1500.0, 2100.0, f64::NAN, f64::NAN,
263            1800.0, f64::NAN, f64::NAN, f64::NAN,
264        ];
265        Triangle::new(4, 4, data)
266    }
267
268    #[test]
269    fn benktander_interpolates_between_bf_and_chain_ladder() {
270        let tri = sample_triangle();
271        let factors = DevelopmentFactorEngine::volume_weighted(&tri.view(), 1.0).expect("factors");
272        let expected = [2000.0, 2200.0, 2600.0, 3200.0];
273
274        let bf = BornhuetterFergusonEngine::project_from_expected_ultimate(
275            &tri.view(),
276            &factors,
277            &expected,
278        )
279        .expect("bf");
280        let cl = ChainLadderEngine::project(&tri.view(), &factors).expect("cl");
281        let bk1 =
282            BenktanderEngine::project_from_expected_ultimate(&tri.view(), &factors, &expected, 1)
283                .expect("bk1");
284        let bk2 =
285            BenktanderEngine::project_from_expected_ultimate(&tri.view(), &factors, &expected, 2)
286                .expect("bk2");
287        let bk_inf =
288            BenktanderEngine::project_from_expected_ultimate(&tri.view(), &factors, &expected, 200)
289                .expect("bk200");
290
291        for i in 0..4 {
292            assert!((bk1.ultimates[i] - bf.ultimates[i]).abs() < 1e-10);
293            assert!((bk_inf.ultimates[i] - cl.ultimates[i]).abs() < 1e-9);
294            // m = 2 recursion check: U^{(2)} = latest + (1 - p) * U^{BF}.
295            let manual = bk2.latest[i] + (1.0 - bk2.maturity[i]) * bf.ultimates[i];
296            assert!((bk2.ultimates[i] - manual).abs() < 1e-10);
297        }
298    }
299
300    #[test]
301    fn mack_optimal_credibility_matches_special_cases() {
302        let p = 0.4;
303        assert!((mack_optimal_credibility(p, 0.0).unwrap() - 1.0).abs() < 1e-12);
304        assert!((mack_optimal_credibility(p, 1.0 - p).unwrap() - p).abs() < 1e-12);
305        let t_bk = (1.0 - p).powi(2) / (2.0 - p);
306        assert!((mack_optimal_credibility(p, t_bk).unwrap() - p * (2.0 - p)).abs() < 1e-12);
307    }
308}