Skip to main content
Install Relativities before running the synthetic examples. A policy with several vehicles or locations holds them as a list of records. Each item calculates its own premium, and the policy adds the premiums up:
The example rates a business auto policy from the synthetic carrier Example Mutual. Its manual rates each vehicle by class, discounts a fleet, and adds three policy charges.

Rate a policy with three vehicles

Save the rater as fleet/rater.rsl:
fleet/rater.rsl
A request sends the list as a JSON array, with one object for each vehicle:
explain gives one row for each calculation of each vehicle, named by its position in the request. The three vehicle premiums add up to 3,096. The charges of 40, 100 and 150 bring the annual premium to 3,386.

Declare the list

Declare the item as its own record, with its inputs:
Declare the list as an input of the policy:
  • keyed by number names the input that identifies each vehicle. Each vehicle in a request has its own number.
  • len(self) in [1, 20] states how many vehicles a policy rates.
  • unique(self as v, v.plate) states that a second input is distinct across the list.
  • Each rule carries the code, the message and the citation of its refusal.
The rater refuses a request that breaks one of these rules, before it rates:

Rate each item in its own step

Write the calculations of one vehicle in the Vehicle record. self is that vehicle:
The rater runs the step once for each vehicle. The tanker is a heavy vehicle, so vehicles[1].premium is 800 × 1.8 = 1440.

Read a policy value from an item

A vehicle reads a value of its policy by the record’s name, as in Policy.fleet_factor:
The policy calculates fleet_factor once, from the length of the list:
The van and the box truck take the fleet factor of 0.9. The tanker is the lead vehicle and keeps its full premium.

Add the items up

sum binds a name to each item and adds one value for each:
  • sum of an empty list is 0.
  • max, min and avg take the same two parts and need a list with one item or more.
  • The length rule [1, 20] gives the check that proof. On a list that accepts zero items, these three get E-EMPTY-FOLD.
To round after each item, see Round after each factor.

Write a rule over the list total

A rule on the record reads a fold over its list. Write it after the record’s closing brace:
self is the policy, so the fold reads self.vehicles. The rater checks the rule before it rates:
A total of 1,000,000 rates, and one dollar more is refused with the rule’s code. The rule sits on the root record, so the reason is the message alone.

Count and test the items

count, exists and all take the list and a condition on one item:
The example has one heavy vehicle, so the heavy charge is 40. The box truck lacks telematics, so all_telematics is false.

Pick one item

argmax gives the item with the greatest score. The manual names the vehicle with the greatest cost new as the lead vehicle:
  • The result is an option: Some item, or None for an empty list. match reads it, and both arms are required.
  • then [cite: manual:p3]: v.model_year is the filed tie-breaker: of two vehicles with the same cost, the newer one leads.
  • The list key breaks each remaining tie: the vehicle with the lowest number leads.
  • argmin gives the item with the least score in the same way.
Each tie-breaker is stated, so a request rates the same way in any order of its list:
In the second request the box truck is newer, so it leads. In the third request the cost and year tie, so vehicle 2 leads. find gives the first item, in key order, that meets a condition:
The tanker is the first vehicle that hauls hazardous cargo, and it is heavy, so the charge is 150. A policy with zero hazardous vehicles takes the None arm. A selection needs a keyed list. argmax, argmin, find, topn or rank on a list that lacks keyed by gets E-SELECT-TIE.
  • Lists in the function reference covers filter, topn, rank, index and avg.
  • Work with dates counts the incidents in a look-back window.
  • Refusals lists the reason codes a rater returns for a list.