非寿险赔款发展三角、确定性准备金估计与历史回测工具
| 输入和任务 | 处理 | 输出 |
|---|---|---|
| 准备金分析员的累计或增量赔款 | 校验三角、选择 volume/simple/regression 因子、Chain Ladder 投影 | 每事故期已付/最终赔款/未付准备金,发展期和支付日历 |
| 数据工程师的先验最终赔款或暴露量 | BF、迭代 Benktander、Cape Cod | 统一估计对象、可对账现金流、JSON/CSV |
| 模型复核者的历史数据和因子选择 | 最近窗口、配对排除、手工因子、历史截面重新拟合、单因子压力 | 原始残差、留出 MAE/RMSE/WAPE、准备金变化 |
moon update
moon add TWISTY2Ynb/moonrunoff@0.1.0import { "TWISTY2Ynb/moonrunoff" @runoff }
options("is-main": true)fn main raise {
let t = @runoff.Triangle::new([
[100.0, 150.0, 180.0],
[120.0, 180.0],
[140.0],
])
let p = @runoff.Pattern::fit(t)
let estimate = @runoff.chain_ladder(t, p)
assert_true((estimate.total_reserve() - 148.0).abs() < 1.0e-9)
assert_true(estimate.reconcile().balanced)
println(estimate.to_json())
}git clone https://github.com/TWISTY2Ynb/moonrunoff.git
cd moonrunoff
moon run examples/claims
moon run examples/exposure
moon run examples/reviewmoon run cmd/moonrunoff -- --request '{"triangle":[[100,150,180],[120,180],[140]]}'
moon run cmd/moonrunoff -- --request '{"triangle":[[100,150,180],[120,180],[140]],"estimator":"bornhuetter-ferguson","prior":[200,220,240]}'
moon run cmd/moonrunoff -- --request '{"triangle":[[100,150,180],[120,190],[140]],"action":"backtest"}'
moon run cmd/moonrunoff -- --request '{"triangle":[[100,150,180],[120,180],[140]],"action":"stress","shock":0.02}'python tools/check_toolchain.py
moon info
moon fmt --check
moon check --deny-warn
moon test --deny-warn
moon build --deny-warn
python tools/differential.py
moon test --deny-warn --enable-coverage
moon coverage report -- -f summarypub(all) suberror RunoffError {
Shape(String)
Value(String)
Selection(String)
Numerical(String)
Parse(String)
} derive(Debug)pub(all) struct BacktestScore {
count : Int
bias : Double
mean_absolute_error : Double
root_mean_square_error : Double
weighted_absolute_percentage_error : Double?
} derive(Debug)pub struct CapeCodResult {
// private fields
}pub struct Estimate {
// private fields
}fn Estimate::discounted_reserves(self : Estimate, forward_rates : Array[Double]) -> Array[Double] raise RunoffErrorfn Estimate::reconcile(self : Estimate, relative_tolerance? : Double) -> Reconciliation raise RunoffErrorpub(all) struct FactorStat {
age : Int
factor : Double
pairs : Int
skipped_zero : Int
numerator : Double
denominator : Double
} derive(Debug)pub(all) struct FitSummary {
pairs : Int
zero_bases : Int
mean_absolute_residual : Double
root_mean_square_residual : Double
maximum_absolute_residual : Double
} derive(Debug)pub(all) struct HoldoutCell {
cutoff : Int
origin : Int
age : Int
predicted : Double
observed : Double
error : Double
} derive(Debug)pub(all) struct OriginEstimate {
origin : Int
age : Int
latest : Double
ultimate : Double
reserve : Double
} derive(Debug)pub(all) struct PairDiagnostic {
origin : Int
age : Int
base : Double
observed : Double
expected : Double
residual : Double
ratio : Double?
} derive(Debug)pub struct Pattern {
// private fields
}fn Pattern::fit(triangle : Triangle, average? : Average, tail? : Double) -> Pattern raise RunoffErrorpub(all) struct Payment {
origin : Int
age : Int
calendar : Int
amount : Double
is_tail : Bool
} derive(Debug)pub(all) struct Reconciliation {
latest : Double
ultimate : Double
reserve : Double
payment_total : Double
calendar_total : Double
maximum_origin_error : Double
tolerance : Double
balanced : Bool
} derive(Debug)pub(all) struct StressResult {
name : String
base_reserve : Double
stressed_reserve : Double
change : Double
relative_change : Double?
} derive(Debug)pub struct Triangle {
// private fields
}fn benktander(triangle : Triangle, pattern : Pattern, prior : Array[Double], iterations? : Int) -> Estimate raise RunoffErrorfn bornhuetter_ferguson(triangle : Triangle, pattern : Pattern, prior : Array[Double]) -> Estimate raise RunoffErrorfn cape_cod(triangle : Triangle, pattern : Pattern, exposure : Array[Double]) -> CapeCodResult raise RunoffErrorfn compare_stress(triangle : Triangle, base : Pattern, stressed : Pattern, name? : String) -> StressResult raise RunoffErrorfn development_factors(triangle : Triangle, average? : Average) -> Array[FactorStat] raise RunoffErrorfn execute_request_result(text : String) -> Stringfn factor_sensitivity(triangle : Triangle, pattern : Pattern, shock? : Double) -> Array[StressResult] raise RunoffErrorfn holdout(triangle : Triangle, cutoff : Int, average? : Average) -> Array[HoldoutCell] raise RunoffErrorfn pair_diagnostics(triangle : Triangle, pattern : Pattern) -> Array[PairDiagnostic] raise RunoffErrorfn selected_factors(triangle : Triangle, average? : Average, recent? : Int, excluded? : Array[(Int, Int)], overrides? : Array[(Int, Double)]) -> Array[FactorStat] raise RunoffErrorfn stress_pattern(pattern : Pattern, multipliers : Array[Double], tail_multiplier? : Double) -> Pattern raise RunoffError