Skip to main content

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