Skip to main content
A book holds what was reported about each policy. A study holds each version of the book that you want to price. This split keeps reported facts, assumptions and sampled values apart, so each premium traces back to its source.

A book belongs to every carrier

Each carrier asks for the same policy in its own shape. One carrier wants an age, and another wants years licensed. The book stores the fact behind both: a birth date and a first licensed date. Each program derives what its carrier asks for. One book then serves each carrier, and a new carrier needs a new prepare only. For the same reason, a core column holds a fact with one meaning, such as birth_date. A value that a rater derives, such as an age or a violation class, belongs to the program that derives it. Keep additional facts in columns or tables of your own. The programs that need those facts read them there.

A line is a schema

A line of business is a schema object. Book(tables, schema=ppa.SCHEMA) checks the tables against the PPA schema: the required tables, the keys and the core columns. The examples use the included personal auto schema, ppa.SCHEMA. The homeowners (ho.SCHEMA), businessowners (bop.SCHEMA), general liability (gl.SCHEMA) and pet health (pet.SCHEMA) schemas follow the same rules. Extend a schema with typed columns and tables for your own programs. A plain book, Book(tables), keeps arbitrary tables and infers keys from _id columns. Studies and the rating examples require a line schema, supplied explicitly when you construct or load the book. print(book.schema) shows the line’s tables and columns, then your own. Each column’s origin is line, declared or observed. An observed column has the type its values have. The PPA book schema lists each table, key and core column of ppa.SCHEMA.

Declare your own columns

A column that only your programs read can still have a type. Declare it on the schema, and each book built with that schema types and checks it like a core column. The result is the same line, so studies and programs take the book.
A book sorts each problem by its reach. A problem with the book’s shape, such as a missing table, column or key, raises one BookError with each problem at once. A bad cell, such as 'high' in a whole-number column or a value outside its column’s range, is blanked, and book.problems lists it: one row per cell, with what the cell holds, what the column expects, and a line of pandas that fixes it. rate fails that submission as invalid_book with the same message, and rates the rest.
A large book keeps rating when a few cells are bad, and each failure stays visible in the results. To require a book that fits its schema exactly, build it with strict=True. Each bad cell then raises with the shape problems, in one BookError. A study or with_tables rebuilds a strict book with the default rule, so a scenario’s bad cell fails only its own submission.A column’s range bounds the fact itself, such as a model year from 1900. A carrier’s eligibility rule, such as the driver ages it rates, belongs to its rater. rater.inputs lists the rater’s ranges, and the rater fails a submission outside them as invalid_inputs. The book stays the same for every carrier.Declared columns receive the same typing and validation as core columns. Pandas stores whole numbers as Int64, numbers as Float64, dates as datetime64, and booleans as boolean. Use a text column for codes whose spelling matters, including alphanumeric vehicle symbols and codes with leading zeros.

A book knows where it came from

book.source is the directory Book.read_csv read, a URI you pass as source=, or None for a book built in code. A changed book, such as one from with_tables, has the source None, because the source holds the earlier book. Retain the source data and transformation steps with each analysis.

A book stays the same

A book is checked once, when you build it, and stays the same after that. Each table property returns a copy. To change a book, you change a copy in pandas and build a new book with with_tables. Each result then refers to exactly one set of facts, and an earlier book stays valid beside a later one.

A study builds versions on demand

A study holds the book, its scenarios and its fills, and builds one version of the book at a time. Memory holds one version, the book and the current scenario, however large the grid.
A scenario is a function marked with @scenario. Call it with parameters to set them, such as raise_deductible(after=2_500): that gives a new scenario for the study to run. Its label names it in the results, with its parameters filled in.
study.to_json() writes the study: the book’s source and fingerprint, each scenario by import path, label and parameters, and each fill. Study.from_json reads it back, and the same JSON and the same code build books with the same contents. Define each scenario and fill function at the top level of a module. Save the book to a folder of your own first, so the JSON points at files that stay.
A study checks each version as it builds it:
  • A scenario returns a book of the same schema, with the same submissions in the same order.
  • A draw fills blank values only. Each reported value stays as reported.
  • A saved study records the book’s schema and a fingerprint of its tables. It rejects changed source data or a supplied book with different contents.

Scenarios and draws answer different questions

Each filled column gets a <column>_source column, reported or modeled, in each version, so a modeled value stays visible as modeled. Draw k uses the same random streams in each scenario. This is the method of common random numbers. A fact that a scenario leaves unchanged gets the same modeled value in each scenario, which reduces sampling noise in paired scenario comparisons.

Where a value goes

A study works for each line

A study keeps the schema of the book you give it. The scenario and draw checks read the book’s tables, so a book for another line of business follows the same rules.

Each fill draws its own stream

Each fill gets its own generator, seeded by the seed, the draw and the columns it fills. Each fill keeps its values when you add another. A fill returns one value per row, in row order, so an unchanged row gets the same value in each scenario. A scenario that adds a row moves later values in the stream, so draw by row key when a scenario adds rows.

A study rates a repeated input once

Most inputs repeat across a study’s versions: a submission with complete facts, or one a scenario leaves unchanged, has the same input in each draw. Rating depends on the input alone, so rate reuses the row of an input it rated in the version before.

The book defines what a comparison represents

A market basket represents the profiles and weights you selected. A portfolio extract represents its observed mix, subject to the retained rating population. Carry your own segment dimensions through the book and join them to results by key. Report matched counts and rating exceptions beside premium statistics so each result has a clear population.