Skip to main content
Install Relativities and download the synthetic examples before running this page. This page shows how to read and write each part of a rater. It uses the dwelling fire rater from Write your first rater, plus two small raters for the forms that rater skips.

The parts of a rater file

A rater file holds a fixed set of blocks, in this order. Each block matches a part of the rating manual. The spec block also holds the language version line. Copy it as the tutorial shows. A line that starts with # is a comment.

Name the values the manual uses

The Types block names the sets of values that the manual uses:
  • An enum lists named choices, such as the perils. A request sends a member by its name.
  • A band type groups numbers into ranges. IntBands(1, 4, 7, 10..) makes the bands 1 to 3, 4 to 6, 7 to 9, and 10 and up.
  • A number type gives a precision. Money holds whole cents.
An enum member can have a different name in a request. fire_resistive = "fire-resistive" makes a request send "fire-resistive":
Premium, Factor and Rate are built-in number types. Use them for premiums, multipliers and rates.

Declare the inputs

The inputs are the facts that a request sends. Each input has a type and, for a number, a range. This rater shows each kind of input:
keyed by number makes each building’s number unique in its list. Each Option input needs a match with a None arm and a Some arm before a calculation uses it.

Add rules to the inputs

A rule is a where clause. The rater checks every rule before it calculates, and refuses a request that breaks one. Each number input needs a range. The range tells the check which values to prove the calculations for. A rule from the filing gets a code, a message and a citation in brackets. The refusal carries all three. A rule that reads several inputs goes after the record’s closing brace:
The sample download includes this rater in relativities-examples/rsl/inputs. Rate one good request and one that breaks two rules:
The second request breaks two rules, and the refusal lists both. Refusals describes each part of a refusal.

Write the calculations

A step block holds calculations. Each calculation has a name, a type, often a citation, and a formula after =:
  • self.dwelling.coverage_a reads an input of the record, or of a record inside it.
  • +, -, * and / do arithmetic on exact decimals.
  • sum(self.items as i, i.charge) adds a value over each item of a list. product, min, max, avg and count work the same way.
  • sum(Peril as p, ...) adds a value over each member of an enum.
  • The order of the calculations is free. The rater works out the order from what each formula reads.

Choose a value

if picks between two values. match picks one value for each member of an enum, or for each case of an Option:
@Construction.frame names a member of the Construction enum. A match lists every case.

Keep one value per peril

peril_premium[p: Peril] is a map: one value for each member of Peril. Read one value with self.peril_premium[p]. A rater returns a map as a JSON object keyed by member. A map can cover only some members. This rater gives a deductible credit to fire and wind only:
if p in PropertyPeril reads the credit only for fire and wind. The sample download includes this rater in relativities-examples/rsl/maps:

Read a table

A table declares its key columns after dims and its output columns after ->. Its rows live in a CSV file named after the table:
lookup!(BaseRate, self.dwelling.protection_class) finds the row for a key. .rate[p] reads one peril’s rate from it. Read a filed table covers tables with more keys and rows the filing leaves out.

Round where the manual rounds

round(x, 0, half_up) rounds to whole dollars, with halves going up. The second number counts decimal places, and the third names the rounding mode. RSL rounds only where a round says so. Round a premium lists the modes.

Cite the filing

Each filed number cites the place in the filing that prints it. [cite: manual:p3] points to page 3 of the manual source. Tables, constants and rounding calculations each need one. Citations explains the rules.

Name the outcome

RatingOutcomes names the values that the rater returns. At least one of them is a Premium calculation that rounds: