new_rating_plan: Create a rating plan

View source: R/new_rating_plan.R

new_rating_planR Documentation

Create a rating plan

Description

Create a rating plan

Usage

new_rating_plan(
  factor_table,
  rating_spec,
  coverages,
  use_rate_set_key = FALSE,
  max_vars = 12,
  policy_id_col = "policy_id",
  custom_functions = list(),
  validate = TRUE,
  metadata = list()
)

Arguments

factor_table

A normalized long-format data frame containing at least term_name and term_value, plus optional coverage, rate-set, and variable-level lookup columns.

rating_spec

A data frame containing at least term_name and calculation_type. Optional specification columns are normalized and supplied with defaults.

coverages

A character vector naming the coverages to rate.

use_rate_set_key

Logical. If TRUE, factor rows are selected using a rate_set_key supplied in the rating data rather than automatic state-, charter-, book-segment-, and date-based selection.

max_vars

A nonnegative integer giving the maximum number of variable-level slot pairs in the factor table.

policy_id_col

A single character string naming the policy or record identifier column. Its value is stored as record_id in trace output; if the column is absent, the source row number is used.

custom_functions

A named list of custom rating functions referenced by rating-specification rows with value_source = "custom_function". Each function is called with row, coverage, current_premium, plan, spec_row, and lookup. See custom_rating_functions for the function contract and examples.

validate

Logical. If TRUE, run validate_rating_plan() before returning the plan.

metadata

An optional list stored unchanged in the rating-plan object.

Details

Exact lookup structure and standard rating-step metadata are precompiled when the plan is created. Value-only edits to plan$factor_table$term_value can reuse the compiled lookup structure. If lookup keys or the rating specification are changed, rate_policies() detects the structural change and rebuilds the internal cache before rating.

Value

A rating_plan object containing the normalized factor table, rating specification, coverages, configuration, custom functions, and metadata. The object also contains an internal precompiled cache used by the standard non-trace batch-rating engine. The cache is an implementation detail and should not be edited directly.

Examples

ex <- example_rating_plan()

plan <- new_rating_plan(
  factor_table = ex$plan$factor_table,
  rating_spec = ex$plan$rating_spec,
  coverages = "BI"
)

print(plan)
summary(plan)

ratingtables documentation built on Sept. 6, 2026, 1:06 a.m.