@actuarial-ts/core

中文文档
0.27.0发布于 2026/11/06Apache-2.0TypeScriptES Module零依赖近 30 天下载 2448

Pure, zero-dependency P&C actuarial math for TypeScript: reserving, generalized definition-driven diagnostics, trends, limits, discounting, and seeded stochastic methods with published-value validation.

原始使用文档
文档目录5 节
  1. Reserving quick start
  2. Review execution and verification
  3. Generalized diagnostics
  4. Models, assumptions and financial meaning
  5. License

@actuarial-ts/core

Pure, framework-free P&C actuarial calculations: reserving models, development patterns, diagnostic metrics, financial adjustments, forecasts and review graphs.

This README describes the 0.27.0 candidate. Use all five SDK packages from the same versioned package set. ESM, TypeScript-first, Node 20+, with no runtime dependencies.

The source repository is private. Repository users can start with docs/sdk-guide.md and docs/migrations/0.27-sdk-cleanup.md for installation, package boundaries and the archive/recalculate path. Those guides are not included in the npm tarball. Candidate documentation is not a publication claim.

Reserving quick start

Given claim snapshots with declared dates and amounts:

import { buildTriangles, computeDevelopmentFactors, runChainLadder, runMack } from "@actuarial-ts/core";

const { paid } = buildTriangles(claimSnapshots, { cadence: "annual", asOfDate: "2025-12-31" });
const selected = computeDevelopmentFactors(paid).averages.find((item) => item.spec.key === "all-wtd")!.values;
const chainLadder = runChainLadder(paid, { selected, tailFactor: 1.02 });
const mack = runMack(paid, { selected, tailFactor: 1.02 });

Unobservable triangle cells are null. Volume-weighted factors use sum/sum over rows where both observations exist. CDFs multiply right to left, tail last. Missing, zero or negative divisors produce unavailable factors rather than NaN. True cumulative development age zero is numeric zero; missing positive-age observations remain missing. An origin label such as "0" is an ordinary label.

Use runModel for the connected model contract: it retains typed quantities, source references, assumptions, findings and available uncertainty. Native kernels such as runChainLadder remain useful for direct calculation.

Review execution and verification

A ReviewPlan binds typed inputs, dependencies, operations and named outputs. For a validated plan:

import {
  runReviewPlan,
  verifyReviewPlanRun,
  replayReviewPlanRun,
  REVIEW_PLAN_VERIFICATION_LIMITS,
} from "@actuarial-ts/core";

const run = runReviewPlan(plan);
const verification = verifyReviewPlanRun({
  run,
  limits: REVIEW_PLAN_VERIFICATION_LIMITS,
});
// Explicitly execute the graph again, even for this exact live run:
const replay = replayReviewPlanRun({ run, limits: REVIEW_PLAN_VERIFICATION_LIMITS });

verifyReviewPlanRun preserves an exact authentic current-process execution; imported or copied runs must reproduce through current-SDK execution. Both paths check the caller's limits. ReviewPlanVerification.assurance.calculations records executed-current-sdk or replayed-current-sdk. Re-executing the same SDK is reproducibility evidence, not independent actuarial validation. isVerifiedReviewPlan recognizes only receipts issued by this process.

encodeReviewEvidence and decodeReviewEvidence use actuarial-review-evidence-graph/3. Shared JSON transport does not grant execution or source authority. Physical graph limits govern actual retained work. Explicit tree serialization has its own expansion bound; ordinary graph ownership does not expand shared children. canonicalJsonEqual compares complete canonical content; structural sharing is not permission to skip validation or rely on a hash alone.

Generalized diagnostics

Measures declare quantities, units, development semantics, missingness and population/basis meaning. Formula instances bind typed roles to those measures; presentation and review rules remain separate from arithmetic identity. The following uses caller-authored measures, populations, bases and period policy:

import {
  CASUALTY_FORMULA_TEMPLATES,
  compileDiagnosticDefinition,
  createCasualtyMetricInstances,
  prepareDiagnosticData,
  runMetricDiagnostics,
} from "@actuarial-ts/core";

const instances = createCasualtyMetricInstances({
  counts: { reported: "reported", open: "open", closedNoPay: "closed-no-pay", closedWithPay: "closed-with-pay" },
  exposure: "earned-vehicle-years",
  amountBindings: [
    { id: "gross", paid: "gross-paid", incurred: "gross-incurred" },
    { id: "primary-250k", paid: "primary-paid", incurred: "primary-incurred" },
  ],
});

const compiled = compileDiagnosticDefinition({
  diagnosticDefinitionVersion: "1.0.0",
  id: "fleet-diagnostics",
  version: "1.0.0",
  lossRowGrain: "aggregate",
  measures,
  countPopulations,
  exposureBases,
  amountBases,
  derivedMeasures: [],
  formulas: CASUALTY_FORMULA_TEMPLATES,
  instances,
  reviewRules,
  periodAxis,
});

const prepared = prepareDiagnosticData({ definition: compiled, losses, exposures });
const result = runMetricDiagnostics({ prepared, groupMap: { fleet: "all-fleet" } });

Metrics divide after source-group/origin/valuation aggregation and explicit group mapping. Exposure timing is declared as origin-static or valuation-specific. Claim-level caps are applied before aggregation; pre-limited source values must retain their declared transformation and cannot imply recreated claim detail. Compilation validates the complete definition, dependencies and period coordinates.

Choose matching preparation, calculation and maturity functions:

OperationEager evidenceCompact evidence
PrepareprepareDiagnosticDataprepareDiagnosticDataCompact
CalculaterunMetricDiagnosticsrunMetricDiagnosticsCompact
Select development agesameMaturitysameMaturityCompact
Latest common agecommonMaturitycommonMaturityCompact

Compact owners retain complete audit evidence. Page review evaluations and their sources with pageDiagnosticReviewEvaluations and pageDiagnosticReviewEvaluationSources; paging is not sampling. Materialization explicitly expands evidence and may use substantially more memory. Copies and parsed JSON cannot recreate authentic compiled/prepared owners. For imported data and review/execution gates, use the gateway in @actuarial-ts/data.

Models, assumptions and financial meaning

  • Reserving includes chain ladder, Mack, BF, Benktander, Cape Cod, Expected Claims, frequency-severity, Munich chain ladder, case outstanding, Fisher-Lange, Clark, ODP bootstrap and Merz-Wüthrich one-year risk. Availability and uncertainty are method-specific; inspect the result's findings.
  • selectDevelopmentPattern binds explicit averaging/tail intent to native evidence. createSelectedEstimateRange records human-selected endpoints and rationale; it is a nonprobabilistic range.
  • Connected adjustments cover premium on-leveling/trend, capping/ILFs, ULAE, nominal cash flows and discounting with explicit sources, dates and quantities. createModelForecast and scoreModelForecast preserve frozen forecast vintages and distinguish later restatements from actual emergence.

AnalysisDefinition.financialTermSchedules resolves declared accident/report/date fields over complete claim, occurrence or policy populations. Starts are inclusive, ends exclusive; an equal-priority match is unavailable. A schedule boundary does not create a new deductible or infer annual resets. Use createFinancialTermScheduleBinding for heterogeneous scheduled limitations and deriveRecipeFinancialBasis to derive supported output meaning from a confirmed input basis. These declarations do not authenticate external source facts.

Published source fixtures and independent comparisons are the numerical contract. The package is designed to support the actuary's compliance with the ASOPs; it does not make a work product compliant or replace professional judgment.

License

Apache-2.0. See LICENSE and NOTICE. The source repository is private; the published packages retain their Apache-2.0 license.

版本与发布记录

@actuarial-ts/core 共发布 28 个版本,首次发布于 2026/07/17;过去 12 个月发布了 28 个版本。

版本发布日期距今
0.27.0latest2026/11/062 天前
0.23.02026/10/2216 天前
0.22.12026/10/1919 天前
0.22.02026/10/1029 天前
0.21.02026/10/071 个月前
0.20.02026/10/031 个月前

关于 @actuarial-ts/core 的常见问题

@actuarial-ts/core 是什么?

Pure, zero-dependency P&C actuarial math for TypeScript: reserving, generalized definition-driven diagnostics, trends, limits, discounting, and seeded stochastic methods with published-value validation.

如何安装 @actuarial-ts/core?

在项目目录运行 npm install @actuarial-ts/core,或使用 pnpm add / yarn add / bun add。

@actuarial-ts/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@actuarial-ts/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@actuarial-ts/core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@actuarial-ts/core 可以商用吗?

@actuarial-ts/core 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@actuarial-ts/core 的下载量有多少?

根据 npm 官方下载统计,@actuarial-ts/core 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,448 次,日均约 82 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@actuarial-ts/core 还在维护吗?

最新版本 0.27.0 发布于 2026/11/06(2 天前);至今共发布 28 个版本,其中过去 12 个月发布了 28 个;首次发布于 2026/07/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。