1use crate::deterministic::benktander::{BenktanderEngine, BenktanderProjection};
7use crate::deterministic::bf::{BornhuetterFergusonEngine, BornhuetterFergusonProjection};
8use crate::deterministic::brosius::{self, Brosius};
9use crate::deterministic::cape_cod::{CapeCodEngine, CapeCodProjection};
10use crate::deterministic::chain_ladder::{ChainLadderEngine, ChainLadderProjection};
11use crate::deterministic::generalized_cape_cod::{
12 GeneralizedCapeCodEngine, GeneralizedCapeCodProjection,
13};
14use crate::deterministic::ldf::{DevelopmentFactorEngine, DevelopmentFactors};
15use crate::diagnostics::triangle_diagnostics::{self, TriangleDiagnostics};
16use crate::preprocessing::exhibit::{ExhibitBundle, build_exhibit_bundle};
17use crate::preprocessing::triangle::{cumulative_to_incremental, latest_diagonal};
18use crate::stochastic::bootstrap_odp::{
19 OdpBootstrapOptions, OdpBootstrapResult, OdpFit, bootstrap_odp, fit_odp,
20};
21use crate::stochastic::clark_mle::{self, ClarkMleResult, ClarkOptions};
22use crate::stochastic::glm_reserving::{self, GlmOptions, GlmReservingResult};
23use crate::stochastic::mack::{self, Mack};
24use crate::stochastic::merz_wuthrich::{self, MerzWuthrichResult};
25use crate::stochastic::ptf_regression::{self, PtfOptions, PtfResult};
26use crate::types::{Triangle, TriangleView};
27use crate::validate::{MonotonicityPolicy, ValidationError};
28
29impl Triangle {
30 pub fn latest_diagonal(&self) -> Vec<f64> {
32 latest_diagonal(&self.view())
33 }
34
35 pub fn to_incremental(&self) -> Self {
37 let n = self.n();
38 Self::new(n, n, cumulative_to_incremental(&self.view()))
39 }
40
41 pub fn ldfs(&self, tail: f64) -> Result<DevelopmentFactors, ValidationError> {
43 self.view().ldfs(tail)
44 }
45
46 pub fn chain_ladder(&self, tail: f64) -> Result<ChainLadderProjection, ValidationError> {
48 self.view().chain_ladder(tail)
49 }
50
51 pub fn mack(&self, tail: f64) -> Result<Mack, ValidationError> {
53 self.view().mack(tail)
54 }
55
56 pub fn mack_with_policy(
58 &self,
59 tail: f64,
60 policy: MonotonicityPolicy,
61 ) -> Result<Mack, ValidationError> {
62 self.view().mack_with_policy(tail, policy)
63 }
64
65 pub fn merz_wuthrich(&self) -> Result<MerzWuthrichResult, ValidationError> {
67 self.view().merz_wuthrich()
68 }
69
70 pub fn merz_wuthrich_with_policy(
72 &self,
73 policy: MonotonicityPolicy,
74 ) -> Result<MerzWuthrichResult, ValidationError> {
75 self.view().merz_wuthrich_with_policy(policy)
76 }
77
78 pub fn bf(
80 &self,
81 expected_ultimate: &[f64],
82 tail: f64,
83 ) -> Result<BornhuetterFergusonProjection, ValidationError> {
84 self.view().bf(expected_ultimate, tail)
85 }
86
87 pub fn cape_cod(
89 &self,
90 premium: &[f64],
91 tail: f64,
92 ) -> Result<CapeCodProjection, ValidationError> {
93 self.view().cape_cod(premium, tail)
94 }
95
96 pub fn bootstrap_odp(
98 &self,
99 tail: f64,
100 options: OdpBootstrapOptions,
101 ) -> Result<OdpBootstrapResult, ValidationError> {
102 self.view().bootstrap_odp(tail, options)
103 }
104
105 pub fn exhibit(
107 &self,
108 premium: Option<&[f64]>,
109 expected_ultimate: Option<&[f64]>,
110 tail: f64,
111 ) -> Result<ExhibitBundle, ValidationError> {
112 self.view().exhibit(premium, expected_ultimate, tail)
113 }
114
115 pub fn benktander(
117 &self,
118 expected_ultimate: &[f64],
119 iterations: usize,
120 tail: f64,
121 ) -> Result<BenktanderProjection, ValidationError> {
122 self.view().benktander(expected_ultimate, iterations, tail)
123 }
124
125 pub fn generalized_cape_cod(
127 &self,
128 premium: &[f64],
129 decay: f64,
130 tail: f64,
131 ) -> Result<GeneralizedCapeCodProjection, ValidationError> {
132 self.view().generalized_cape_cod(premium, decay, tail)
133 }
134
135 pub fn brosius(&self, tail: f64) -> Result<Brosius, ValidationError> {
137 self.view().brosius(tail)
138 }
139
140 pub fn fit_odp(&self, tail: f64) -> Result<OdpFit, ValidationError> {
142 self.view().fit_odp(tail)
143 }
144
145 pub fn glm(&self, options: &GlmOptions) -> Result<GlmReservingResult, ValidationError> {
147 self.view().glm(options)
148 }
149
150 pub fn clark_ldf(&self, options: &ClarkOptions) -> Result<ClarkMleResult, ValidationError> {
152 self.view().clark_ldf(options)
153 }
154
155 pub fn clark_cape_cod(
157 &self,
158 premium: &[f64],
159 options: &ClarkOptions,
160 ) -> Result<ClarkMleResult, ValidationError> {
161 self.view().clark_cape_cod(premium, options)
162 }
163
164 pub fn ptf(&self, options: &PtfOptions) -> Result<PtfResult, ValidationError> {
166 self.view().ptf(options)
167 }
168
169 pub fn diagnostics(&self) -> TriangleDiagnostics {
171 self.view().diagnostics()
172 }
173}
174
175impl TriangleView<'_> {
176 pub fn ldfs(&self, tail: f64) -> Result<DevelopmentFactors, ValidationError> {
178 DevelopmentFactorEngine::volume_weighted(self, tail)
179 }
180
181 pub fn chain_ladder(&self, tail: f64) -> Result<ChainLadderProjection, ValidationError> {
183 let factors = DevelopmentFactorEngine::volume_weighted(self, tail)?;
184 ChainLadderEngine::project(self, &factors)
185 }
186
187 pub fn mack(&self, tail: f64) -> Result<Mack, ValidationError> {
189 mack::analyze(self, tail)
190 }
191
192 pub fn mack_with_policy(
194 &self,
195 tail: f64,
196 policy: MonotonicityPolicy,
197 ) -> Result<Mack, ValidationError> {
198 mack::analyze_with_policy(self, tail, policy)
199 }
200
201 pub fn merz_wuthrich(&self) -> Result<MerzWuthrichResult, ValidationError> {
203 merz_wuthrich::analyze(self)
204 }
205
206 pub fn merz_wuthrich_with_policy(
208 &self,
209 policy: MonotonicityPolicy,
210 ) -> Result<MerzWuthrichResult, ValidationError> {
211 merz_wuthrich::analyze_with_policy(self, policy)
212 }
213
214 pub fn bf(
216 &self,
217 expected_ultimate: &[f64],
218 tail: f64,
219 ) -> Result<BornhuetterFergusonProjection, ValidationError> {
220 let factors = DevelopmentFactorEngine::volume_weighted(self, tail)?;
221 BornhuetterFergusonEngine::project_from_expected_ultimate(self, &factors, expected_ultimate)
222 }
223
224 pub fn cape_cod(
226 &self,
227 premium: &[f64],
228 tail: f64,
229 ) -> Result<CapeCodProjection, ValidationError> {
230 let factors = DevelopmentFactorEngine::volume_weighted(self, tail)?;
231 CapeCodEngine::project(self, &factors, premium)
232 }
233
234 pub fn bootstrap_odp(
236 &self,
237 tail: f64,
238 options: OdpBootstrapOptions,
239 ) -> Result<OdpBootstrapResult, ValidationError> {
240 bootstrap_odp(self, tail, options)
241 }
242
243 pub fn exhibit(
245 &self,
246 premium: Option<&[f64]>,
247 expected_ultimate: Option<&[f64]>,
248 tail: f64,
249 ) -> Result<ExhibitBundle, ValidationError> {
250 build_exhibit_bundle(self, premium, expected_ultimate, tail)
251 }
252
253 pub fn benktander(
255 &self,
256 expected_ultimate: &[f64],
257 iterations: usize,
258 tail: f64,
259 ) -> Result<BenktanderProjection, ValidationError> {
260 let factors = DevelopmentFactorEngine::volume_weighted(self, tail)?;
261 BenktanderEngine::project_from_expected_ultimate(
262 self,
263 &factors,
264 expected_ultimate,
265 iterations,
266 )
267 }
268
269 pub fn generalized_cape_cod(
271 &self,
272 premium: &[f64],
273 decay: f64,
274 tail: f64,
275 ) -> Result<GeneralizedCapeCodProjection, ValidationError> {
276 let factors = DevelopmentFactorEngine::volume_weighted(self, tail)?;
277 GeneralizedCapeCodEngine::project(self, &factors, premium, decay)
278 }
279
280 pub fn brosius(&self, tail: f64) -> Result<Brosius, ValidationError> {
282 brosius::project(self, tail)
283 }
284
285 pub fn fit_odp(&self, tail: f64) -> Result<OdpFit, ValidationError> {
287 fit_odp(self, tail, MonotonicityPolicy::Strict)
288 }
289
290 pub fn glm(&self, options: &GlmOptions) -> Result<GlmReservingResult, ValidationError> {
292 glm_reserving::fit_glm(self, options)
293 }
294
295 pub fn clark_ldf(&self, options: &ClarkOptions) -> Result<ClarkMleResult, ValidationError> {
297 clark_mle::fit_clark_ldf(self, options)
298 }
299
300 pub fn clark_cape_cod(
302 &self,
303 premium: &[f64],
304 options: &ClarkOptions,
305 ) -> Result<ClarkMleResult, ValidationError> {
306 clark_mle::fit_clark_cape_cod(self, premium, options)
307 }
308
309 pub fn ptf(&self, options: &PtfOptions) -> Result<PtfResult, ValidationError> {
311 ptf_regression::fit_ptf(self, options)
312 }
313
314 pub fn diagnostics(&self) -> TriangleDiagnostics {
316 triangle_diagnostics::analyze(self)
317 }
318}