Schema of the book it accepts and a prepare function that builds the rater’s inputs from that book.
The schema is the program’s shape
program.schema is a Schema, the same type as
book.schema. It lists each table and column the program accepts, with its type and whether it
is required. A line’s schema, such as ppa.SCHEMA, accepts the line’s core columns. To read a
column of your own, declare it with with_columns:
program.schema.to_pandas(), or print it.
Relativities includes these line schemas:
A line’s core columns are facts, such as
year_built or liquor_sales. A carrier’s own
selectors, such as its class code, tier or territory, are columns the program declares with
with_columns. The gl tables are the liability part of the bop tables, so a general
liability book is also a businessowners book.
Household exposures
The homeowners schema includes an optionalexposures table, keyed by submission_id and exposure_id.
Each row describes one household exposure, such as a watercraft or an incidental occupancy.
Watercraft facts include propulsion, hull length in whole feet and engine horsepower.
Optional insured_id, dwelling_id and premises_id references name rows in the same submission.
Each reference has type id and uses the target row’s identifier.
An exposure can belong to the household through its submission alone.
The dwelling reference associates the exposure with a dwelling; the premises reference identifies its location at another premises.
The referenced other_premises.kind identifies an other structure, additional residence or care facility.
Coverage purchases, limits and carrier classifications stay in coverage tables or program extensions.
A program can extend exposure rows with its own columns through with_columns(exposures=...).
Books that omit the table receive an empty exposures table.
Existing programs with their own exposures declaration must match the core’s column types.
Declare premises_id as Column("id"), or inherit that column from the core.
Rebuild the program bundle with the updated declaration for ho/1.2.
Common protection requests and product choices
A homeowners Book can hold one common protection request and explicit options for several products.coverages holds the common request; coverage_options uses the same coverage terms and adds the
product’s documented program_id. A matching option replaces the entire common row. Missing option
terms stay missing. A percentage-only election therefore carries an empty dollar amount.
example-ca-ho is an illustrative product ID. Use each program’s documented ID; it selects an
explicit request; the program derives its rating factors. Additional matching option rows add coverages. Options for
other products stay in the original Book. A zero limit remains an explicit zero, and an option with
blank terms remains a selection for the program to validate. The helper returns the selected rows. Each program validates filed limits, required coverages and whether it can offer the requested terms.
The same pattern applies to deductibles and deductible_options, keyed by peril.
ho.deductibles_for resolves whole-row product choices; each selected row supplies an amount or percentage.
A product can therefore request a separate water deductible while retaining the same observed household Book.
Observations stay separate from qualification
HO1.2 also provides datedloss_payments, household residence_employees, system updates,
solid-fuel appliances and organization memberships. Their references stay within the same submission.
A features row’s columns describe the feature that row names, and verified verifies only that row.
Dwelling-wide ember-zone facts, such as deck, five-foot and 30-foot clearance, sit on the ember_resistant_zone
row; there False records an observed failure and empty means unknown.
An employee row describes household work. An actual coverage row separately records an optional employee-coverage purchase. Membership active
is observed at the rated effective date: false and unknown remain distinct, and simultaneous clubs
have separate rows. aaa_memberships_complete declares the AAA club inventory. Other association inventories remain separate.
Personal loss-history completeness and premises history are separate.
Some facts are recorded at two resolutions or from two angles: equivalent bathrooms and bathroom rooms;
measured tree-overhang percent and observed extent; a dwelling’s plumbing-renovation summary and its dated
system_updates; a water_shutoff device and a detector’s own automatic_shutoff; and amount paid, net paid,
incurred and individual payments. The HO1.2 column’s meaning states how the two relate and what agreement a Book
must keep; an HO1.1 column’s meaning stays as released. The Book never fills one from the other; a program reads the column its filed rule names and
decides what to do when only the counterpart is supplied. A dated payment keeps its observed date independently
of carrier cutoffs.
Total rental nights differ from
short-stay nights. Both counts use observed nights; short-stay weeks retain their own unit. Licensed wildfire
reports keep their actual model, score and provenance. An unacquired report remains unknown, distinct from observed zero and the vendor’s explicit no-result value (no_score for Verisk FireLine, vendor_no_hit for ZestyAI Z-FIRE).
A vendor or model the line does not name yet is declared by the program with with_columns, using the naming
convention in the relativities.ho reference, so that a later minor version can add the same columns without breaking it. A tier or factor a carrier assigns
from a score is a program column, not a vendor fact.
New core columns are optional schema vocabulary. A selected risk can still require a particular fact
before its program can calculate a premium. Actual carrier decisions, qualified employment/affinity
relationships and inseparable named packages remain declared, carrier-qualified program columns.
Pet health
A pet book’s group is the policyholder. One submission prices one owner’s pets together. One carrier writes a policy for each pet, and another puts every pet on one policy. Eachpets row holds the pet’s facts: species,
breed, sex, date of birth and enrollment date. It also holds the plan the owner chose: the product,
deductible, reimbursement and annual limit. Coverages beyond accident and illness, such as
wellness or dental illness, are coverages
rows of the pet, with their own limits.
reimbursement_percent is the insurer’s share of a covered bill after the deductible, such as 90. Carriers file this share two ways:
Read the filing’s coinsurance table to tell them apart. The factor is 1 at the plan’s highest
reimbursement, where the loss elimination ratio equals the insurer’s share.
breed is the breed as the owner states it, and each carrier lists breeds in its own words, such
as “Mixed (Large 51-110 Lbs.)” for a mixed breed. A program maps the book’s breed, mixed_breed and
adult_weight to its carrier’s list. A breed the map lacks fails only its own submission: the
rater refuses a breed outside its filed list.
The book keeps carrier assignments out of the core. A breed group, a territory or a renewal
experience level is derived by the rater from the filed tables. When a rater takes one as an
input, the program declares it with with_columns:
Declared columns and later versions
A minor version of a line adds columns, tables and allowed values. It can add a core column with the name of a column that a program declares. The program still loads:with_columns keeps the
line’s column when the declaration agrees with it. A declaration agrees when it has the same
type, the same requirement, the same unit or an empty unit, and for an enum, values that the
line’s column allows. The meaning can differ, because it is the program author’s own words. An enum
declared with fewer values keeps only those values. A submission with any other value is
invalid_book, and prepare reads only the submissions that remain. A declaration that disagrees raises
ValueError, and the message names both specifications. with_tables uses the same rule for a
table with the same name, key and requirement.
prepare holds each carrier-specific rule
prepare is a function from a book to the rater’s inputs. It returns
Inputs: one table for each field of rater.inputs,
such as Inputs(drivers=drivers, vehicles=vehicles). Each table has a submission_id column, and
the program nests its rows into each submission’s input:
Preparation code and item links
Preparation code and item links
A list the rater nests in another list’s items is a table of its own:
Inputs(drivers=drivers, incidents=incidents) puts each incident in the driver with the same
submission_id and driver_id, and drops an incident whose driver is outside drivers. Keep
prepare to flat, vectorized tables like these: Rust nests and rates them, so building lists of
records in Python is the slow way to write the same input.The book’s ID columns, such as vehicle_id, leave each item before rating, and they link each
item to its row in the book. prepare always returns Inputs.
Each submission’s inputs depend only on that submission’s rows. rate gives prepare the book
in chunks, and a failing submission is left out of the book, so this rule keeps each input the
same however the book is split. Relativities converts its values to JSON: dates become ISO text, numpy
numbers become Python numbers, a missing field is left out, and a missing list element stays as None.
A program’s read(inputs, outputs) follows the same rule for one result: rate calls it on more
than one thread and in any order, so its columns depend only on that result.The book stays the same for each carrier, and a change to one carrier touches its own prepare.
For a carrier’s own estimate of an empty fact, write a new prepare that fills the fact and calls
the old one. The book keeps the fact as reported, so one carrier’s estimate stays out of another
carrier’s input.What a program guarantees
- The schema is enforced.
rateandexplaincheck the book against the program’s schema. A missing required column raisesBookErrorbeforeprepareruns. A value of the wrong type, or outside its column’s range, fails its submission asinvalid_book, and the rest rate. - The schema is all
preparereads.preparegets a copy of the book with only the schema’s tables and columns. A column outside the schema raisesKeyErrorinprepare, soprogram.schemalists every column the program can depend on. preparebuilds one input for every submission. It derives and renames values in one vectorized call per chunk, and it keeps a blank fact blank. Document carrier-specific defaults and assumptions in the preparation code. A submission it leaves out, or an exception it raises, is a bug in the program, sorateraises.prepareasks for an answer as data. Some submissions need an answer before they rate, such as which trim a vehicle is.preparefails that submission with aNeedinInputs(failures=...). The need names the book column for the answer, the row, and any allowed options.ratereturns it asmapping_failedwith the codeNEEDS_INPUT, and lists each need in theneedscolumn. A need’s column belongs to the program’s schema, sopreparereads the answer on the next rate.prepare’s columns fit the rater’s input types. Before it rates a chunk,ratechecks that each column of theInputsnames an input inrater.inputs. It also checks that each required input has a column, and that each column’s type fits its input. A mismatch, such as text for anint, is a bug in the program:rateraisesTypeErrorand names each column.- The rater fails each unratable submission alone. The rater checks every input against
rater.inputsbefore it rates any. A blank required field or an unfiled code gets the statusinvalid_inputs, with the field’s path in the reason. A carrier’s eligibility rule, such as the limits it files, lives in the rater and getsrefused, with the carrier’s code. The check stops before the calculation, so the other rows rate at full speed. - Explain matches rate.
explainrunsprepareon the chunk thatrategives it, so its input rows are the exact input rated. Its keys are the keys ofrate, so its table merges with the book and with the rows ofrate.
explain shows the input that the rater rejected,
next to the book’s rows on the same keys.
Result columns carry the rater’s own names
rate returns the rater’s RatingOutcomes as columns, with the names the rater gives them. The
rater defines what it returns, so the result shows exactly that. A total is the carrier’s own
total, and a premium carries the carrier’s own term. A column takes the outcome’s name, and
explain takes the name of the calculation the outcome points to. So
premium: Policy.policy_premium is the column premium in rate and the step
policy_premium in explain. A map outcome has a column per key, and with by, so does an
outcome of each item, such as vehicle_premium.liability.
In a market, two programs share a column when their raters give an outcome the same name. A
six-month premium and a twelve-month annual_premium stay in separate columns.
A comparison basis, such as an annual premium, is your choice. State it once per program, in its
read. read(inputs, outputs) returns the program’s columns for one result, such as
{"annual_premium": outputs["premium"] * 2}. outputs holds the root record’s calculations by
their own names, as explain names them. Programs whose read returns the same name share a
column, so a market’s table is on one basis. program.with_read gives a loaded program another read.
Inspect contracts across programs
Inspect contracts across programs
Each program in a market keeps its own contract
A market holds named programs, and each program keeps its own schema and rater inputs. A merged schema would lose which program needs each column, so read each contract by program:program.schema.to_pandas() the same way, for one row per book column each program accepts.
market.rate checks the book against each program’s schema before that program’s prepare runs.Each layer adds its key
Analysis code for one program works on a market’s table too: it groups by one more column.
rate(data, by="vehicles") keys each row by a table of the book too, such as vehicle_id: one row
per vehicle, with its submission’s status and the rater’s outcomes for that vehicle. by takes any
table of the book’s schema with one row per item of a submission, so the names come from the schema
alone. A program links each item through the IDs in its Inputs, whatever the
rater calls the list. An item may also carry other ID columns its own table holds, such as
an incident’s driver_id. A program whose rater returns outcomes per submission alone has NaN there.
A study whose scenarios set one parameter to several values adds a column for it after its keys,
such as miles for [at(miles=m) for m in range(0, 32_001, 500)].
Execution and performance
Execution and performance
One rating path
program.rate and market.rate use the same native engine as rater.rate. The unit of work is
one program and one chunk of up to 10,000 submissions from one version of the book. prepare
returns the chunk’s Inputs tables, and their columns go to Rust in one call. Rust builds each
submission’s input, checks it and rates it on every core, and Python’s other threads run
meanwhile. Each input is exactly the one its JSON would be, so the rows are the same either way. A
study passes each input’s fingerprint back in, and Rust skips a submission whose input repeats an
earlier version’s. Units run on two threads, so one chunk’s prepare runs while another rates, and a study
builds one version at a time, so memory holds a few chunks, plus the result rows.Each input depends only on its own submission’s rows, so a chunk gives the same rows as the whole
book. explain runs prepare on the chunk that holds the submission, then rates the one
submission again with each calculation kept. Rating is deterministic, so the explanation matches
the rated row. market.explain gives each program’s explanation side by side.Mapping quality is part of rating quality
A correctly implemented algorithm still needs the right inputs. Vehicle symbols, territory assignments, discounts, and coverage selections can change a comparison materially.explain exposes the inputs passed to RSL and its calculations. Review the Python prepare function to establish each mapping’s source and assumptions.
Use Validate a program to reconcile independent cases before analyzing the full book.