Skip to content

Quote Calculation Functions

Functions for calculating premiums, processing policy changes, and handling cancellations.


Premium Calculation

$CalculatePremiumAdditive

Calculates the final premium by applying all pricing matrix components additively. This is the core function that processes items, factors, discounts, and produces ledger entries.

Signature

$CalculatePremiumAdditive(quoteType)

Parameters

  • quoteType (string) - Type of quote: "NewBusiness", "Renewal", "Regular", "MTA"

Returns

  • Ledger object with all calculation entries

Environment Variables Used

  • PricingMatrix - Input pricing structure
  • Ledger - Output transaction ledger (cleared and rebuilt)
  • Output - Updated with final premium and monthly payments
  • ProductDetails - Product configuration
  • HasActiveFinanceAgreement - Finance status

Example

// Setup pricing matrix
$SetCurrencyToPricingMatrix("GBP");
$SetCommissionRateToPricingMatrix(0.15);
$SetIptRateToPricingMatrix(0.12);
$AddItemToPricingMatrix("Base Premium", 500.00, 1.0);
$AddFactorToPricingMatrix("Age Factor", 1.20, true, 0);

// Calculate final premium
$CalculatePremiumAdditive("NewBusiness");

// Access results
finalPremium = PricingMatrix.Premium;
monthlyPayment = Output.Monthly.MonthlyAmount;

$AddTaxDuty

Adds a fixed tax duty to an already calculated premium and writes a Tax duty ledger entry.

Signature

$AddTaxDuty(quoteType, amount)

Parameters

  • quoteType (string) - Quote type, e.g. "NewBusiness", or "MTA" for a mid-term adjustment
  • amount (number) - Tax duty amount

Behaviour

  • MTA: adds the duty to both PricingMatrix and AdjustmentDifferencePricingMatrix and updates AdditionalPremium.
  • Other quote types: adds the duty to PricingMatrix, then recalculates monthly payments and updates Output, MonthlyPayment and QuotePublicData.

Returns

  • Ledger object

Example

$CalculatePremiumAdditive("NewBusiness");
$AddTaxDuty("NewBusiness", 5.00);

$CheckQuote

Sets QuoteStatus from the underwriter decisions ("Valid", "Referred" or "Declined"). It returns null and leaves an "Invalid" quote unchanged. See $CheckQuote and $InvalidateQuote in Quote Functions for full details.

Signature

$CheckQuote()

Example

$CheckQuote();
if (QuoteStatus == "Declined") {
    // Handle declined quote
}

Midterm Adjustments (MTA)

$CalculateMTAPremium

Calculates premium changes for mid-term adjustments. Handles pro-rata calculations, cooling-off periods, and adjustment differences.

Signature

$CalculateMTAPremium(mtaFee)
$CalculateMTAPremium(mtaFee, failIfProhibitedCalculations)

Parameters

  • mtaFee (number) - Admin fee for the MTA
  • failIfProhibitedCalculations (boolean, optional) - If true (default), throws when the new pricing matrix has a negative premium, a negative commission plus fee, or negative IPT

Environment Variables Used

  • PricingMatrix - New pricing structure (after the change)
  • PreviousMatrix - The pricing matrix before the change (a single object). If it is not supplied, the last item of PreviousMatricies is used instead and a warning is logged; this fallback is temporary, for callers not yet sending PreviousMatrix. If neither is supplied, or PreviousMatricies is empty, the function fails with "PreviousMatrix is required for an MTA"
  • AdjustmentDifferencePricingMatrix - Output adjustment difference (cleared and rebuilt)
  • Ledger - Output ledger entries (cleared and rebuilt)
  • MTADate - Date of adjustment
  • Policy - Policy object with inception/expiry dates
  • MTAWithinCoolingOffPeriod - Whether the MTA falls within the cooling-off period
  • MTAChanges - Object whose keys are the changed sections. If every key is PhotographerType, PersonalDetails or BusinessName, no MTA fee is charged
  • MTAWaivePremium (optional) - If true, waives the premium change
  • MTAShouldChargeAdminFeeDifference (optional, default false) - If true, an increase in the admin fee between PreviousMatrix and PricingMatrix is added to the MTA fee. A decrease is never refunded
  • MTAOverrideFee (optional) - If true, the MTA fee is set to 0 and the fee that would have been charged is saved to MTAOverridenFeeAmount
  • ImportedMTAFee (optional) - If set, used as the MTA fee instead of the calculated one
  • ProductDetails, QuotePublicData - Used to refresh the quote public data

Environment Variables Updated

  • PricingMatrix, AdjustmentDifferencePricingMatrix, Ledger
  • AdditionalPremium - Sum of the gross amounts of all non-fee ledger entries
  • QuotePublicData - Updated from AdjustmentDifferencePricingMatrix
  • MTAWaivedAmount - Premium that was waived (only when MTAWaivePremium is true)
  • MTAOverridenFeeAmount - Fee that was overridden (only when MTAOverrideFee is true)

Admin Fee Rules

  • By default the policy admin fee does not change on an MTA: PricingMatrix takes the base fee from PreviousMatrix.
  • With MTAShouldChargeAdminFeeDifference = true, the new admin fee is kept and the customer pays mtaFee + max(0, newFee - previousFee).
  • The fee is then adjusted in this order: set to 0 for MTAChanges that carry no fee, set to 0 when MTAOverrideFee is true, and replaced by ImportedMTAFee when set.

Returns

  • Ledger object with MTA calculations

Example

// Set MTA context (PreviousMatrix holds the pricing matrix before the change)
MTADate = $ToDate("2024-06-15");
MTAWaivePremium = false;
MTAShouldChargeAdminFeeDifference = false;

// Update pricing matrix with new values
$AddItemToPricingMatrix("Base Premium", 550.00, 1.0);  // Increased coverage

// Calculate MTA premium
$CalculateMTAPremium(25.00);  // £25 MTA fee

// Access adjustment premium
additionalPremium = AdditionalPremium;  // Set by function
adjustmentDifference = AdjustmentDifferencePricingMatrix.Premium;

$ValidateMTAChanges

Validates that MTA changes are allowed. Outside the cooling-off period, an add-on cannot be downgraded: its net amount in PricingMatrix must not be lower than in PreviousMatrix. Add-ons that are new in the MTA are allowed.

Signature

$ValidateMTAChanges()

Parameters

  • None

Environment Variables Used

  • PricingMatrix - New pricing structure (after the change)
  • PreviousMatrix - The pricing matrix before the change, with the same temporary fallback to the last item of PreviousMatricies as $CalculateMTAPremium
  • MTAWithinCoolingOffPeriod - Whether the MTA falls within the cooling-off period. If not set, the MTA is treated as outside it
  • MTAValidationErrors - Object the errors are added to

Environment Variables Updated

  • MTAValidationErrors - One entry per downgraded add-on: the key is the add-on name, the value is "Cannot downgrade outside cooling off period"

Returns

  • MTAValidationErrors

Example

errors = $ValidateMTAChanges();
if ($HasProperty(errors, "Replacement")) {
    $Referral("MTA-INVALID", errors.Replacement, "Level 1");
}

$ValidateCameraMTA

Validates camera-specific MTA changes (domain-specific validation).

Signature

$ValidateCameraMTA()

Parameters

  • None

Returns

  • Validation result

Example

isValid = $ValidateCameraMTA();
if (!isValid) {
    $Decline("MTA-CAMERA", "Camera MTA validation failed");
}

$ValidateC4RMTA

Validates Cover4Rentals-specific MTA changes (domain-specific validation).

Signature

$ValidateC4RMTA()

Parameters

  • None

Returns

  • Validation result

Example

isValid = $ValidateC4RMTA();

Cancellation Functions

$CalculateFullCancellation

Calculates a full refund cancellation (typically within cooling-off period).

Signature

$CalculateFullCancellation(cancellationFee, refundAdministrationFee)

Parameters

  • cancellationFee (number) - Cancellation fee amount
  • refundAdministrationFee (boolean, optional) - If true, refunds admin fees (default: true)

Environment Variables Used

  • Ledger - Output cancellation ledger (cleared and rebuilt)
  • MTALedgerHistory - Historical ledger entries
  • Cancellation - Cancellation object (updated with refund details)
  • FinanceDetails - Finance agreement details
  • CancellationReason - Reason for cancellation

Returns

  • Ledger object with cancellation entries

Non-Refundable Admin Fee

When refundAdministrationFee is false:

  • The Fee ledger entry is written with zero gross and zero tax.
  • The admin fee is deducted from Cancellation.RefundAmount (unless the policy is paid by an invalid finance agreement, in which case the refund is the deposit).
  • Cancellation.NonRefundableAdminFeeAmount is set to the admin fee that was kept. It is 0 when the admin fee is refunded.

Cancellation.BrokerRefundAmount is unchanged either way.

Example

// Full refund within cooling-off period
CancellationReason = "Cooling Off Period";
$CalculateFullCancellation(0.00, true);  // No fee, refund admin fee

// Access refund
refundAmount = Cancellation.RefundAmount;
refundMessage = Cancellation.RefundMessage;

// Keep the admin fee
$CalculateFullCancellation(0.00, false);
keptFee = Cancellation.NonRefundableAdminFeeAmount;

$CalculateProRataCancellation

Calculates a pro-rata refund based on time remaining on policy.

Signature

$CalculateProRataCancellation(cancellationFee, refundAdministrationFee)

Parameters

  • cancellationFee (number) - Cancellation fee amount
  • refundAdministrationFee (boolean, optional) - If true, refunds admin fees (default: true)

Environment Variables Used

  • Same as $CalculateFullCancellation
  • Policy - Policy dates for pro-rata calculation
  • CancellationDate - Date of cancellation

Returns

  • Ledger object with pro-rata cancellation entries

Non-Refundable Admin Fee

When refundAdministrationFee is false, the pro-rated admin fee is deducted from Cancellation.RefundAmount, and Cancellation.NonRefundableAdminFeeAmount is set to the full (not pro-rated) admin fee. Otherwise it behaves as described for $CalculateFullCancellation.

Example

// Pro-rata cancellation mid-policy
CancellationDate = $ToDate("2024-09-01");
CancellationReason = "Customer Request";

$CalculateProRataCancellation(25.00, false);  // £25 fee, no admin refund

// Refund is proportional to time remaining
proRataRefund = Cancellation.RefundAmount;

$CalculateNoRefundCancellation

Processes a cancellation with no refund.

Signature

$CalculateNoRefundCancellation(cancellationFee)

Parameters

  • cancellationFee (number) - Cancellation fee amount (typically 0)

Environment Variables Used

  • Ledger - Output cancellation ledger
  • Cancellation - Updated with zero refund details
  • CancellationReason - Reason for cancellation

Returns

  • Ledger object

Example

// No refund scenario (e.g., after policy end)
CancellationReason = "Policy Expired";
$CalculateNoRefundCancellation(0.00);

// Cancellation.RefundAmount will be 0

Helper Functions

$CalculateAge

Calculates age based on date of birth and reference date.

Signature

$CalculateAge(referenceDate, birthdate, timezone)

Parameters

  • referenceDate (date) - Date to calculate age at (typically today or inception date)
  • birthdate (date) - Date of birth
  • timezone (string, optional) - Timezone ID (e.g., "GMT Standard Time")

Returns

  • Age as number

Example

inceptionDate = $ToDate("2024-03-15");
dateOfBirth = $ToDate("1985-06-20");

ageAtInception = $CalculateAge(inceptionDate, dateOfBirth);
// Returns: 38

// With timezone
ageWithTz = $CalculateAge($Now(), dateOfBirth, "GMT Standard Time");

$GetPostCodeInformation

Looks up a UK postcode in the postcode data set embedded in the library. The data includes deprivation, demographic and flood-risk data.

Signature

$GetPostCodeInformation(postcode)

Parameters

  • postcode (string) - Postcode. Case and whitespace are ignored ("al1 1aa" matches "AL1 1AA")

Returns

An object with:

Property Type Description
postcode String Normalised postcode (upper-case, no spaces)
found Boolean False when the postcode is not in the data set (other fields empty)
imdDecile Number Index of Multiple Deprivation decile (1 = most deprived, 10 = least, 0 = unknown)
countryImd String Country the IMD decile relates to (e.g. "England")
supergroup String Demographic supergroup classification
strategicFortegraFloodRisk Boolean StrategicFortegra flood-risk flag
i4cFloodRisk Boolean I4C flood-risk flag
bspokeArParkDecline Boolean Bspoke AR park decline flag
bspokeApprovedParksListFloodArea String Bspoke approved-parks-list flood area code (e.g. "A", "F1"), or empty
bspokeApprovedParksListDecline String Bspoke approved-parks-list decline: "1", "0" or empty
bspokeFloodRisk Boolean Bspoke flood-risk flag

Errors

  • Throws if not called with exactly one string argument.

Example

info = $GetPostCodeInformation(Answers.Postcode);

if (!info.found) {
    $Referral("PC-UNKNOWN", "Postcode not recognised", "Level 1");
}

if (info.bspokeFloodRisk) {
    $Decline("FLOOD", "Property is in a flood-risk area");
}

$CalculatePolicyDates

Calculates policy inception and expiry dates from the quote environment variables. Takes no arguments and sets InceptionDate, ExpiryDate and PolicyDurationInDays. See Time Functions for full details.

Signature

$CalculatePolicyDates()

Example

$CalculatePolicyDates();
duration = PolicyDurationInDays;

Complete Workflow Examples

New Business Quote

// Initialize
$SetCurrencyToPricingMatrix("GBP");
$SetCommissionRateToPricingMatrix(0.15);
$SetIptRateToPricingMatrix(0.12);

// Calculate age-based premium
age = $CalculateAge($Now(), customerDOB);
basePremium = 400.00;

if (age < 25) {
    basePremium = 600.00;
} else if (age > 65) {
    basePremium = 550.00;
}

$AddItemToPricingMatrix("Base Premium", basePremium, 1.0);

// Apply no claims discount
if (yearsNoClaims >= 5) {
    $AddFactorToPricingMatrix("No Claims Discount", 0.80, true, 0);
}

// Calculate
$CalculatePremiumAdditive("NewBusiness");

totalPremium = PricingMatrix.Premium;

Mid-Term Adjustment

// Customer adds coverage mid-policy
MTADate = $Today();

// Update pricing matrix with new item
$AddItemToPricingMatrix("Additional Camera", 150.00, 1.0);

// Validate changes
errors = $ValidateMTAChanges();
if ($HasProperty(errors, "Replacement")) {
    $Referral("MTA-INVALID", errors.Replacement, "Level 1");
}

// Calculate adjustment premium
$CalculateMTAPremium(15.00);  // £15 MTA fee

additionalCharge = AdditionalPremium;

Cancellation Within Cooling-Off

// Customer cancels within 14 days
CancellationReason = "Cooling Off Period";
CancellationDate = $ToDate("2024-03-20");

// Full refund
$CalculateFullCancellation(0.00, true);

refund = Cancellation.RefundAmount;
message = Cancellation.RefundMessage;
// Message: "A refund is due as the policy lies within the 14 day cooling off period."

Pro-Rata Cancellation

// Customer cancels mid-term
CancellationDate = $ToDate("2024-09-15");
CancellationReason = "Customer Request - No Longer Needed";

// Pro-rata refund with £25 cancellation fee
$CalculateProRataCancellation(25.00, false);

proRataRefund = Cancellation.RefundAmount;
// Refund calculated based on days remaining / total days

Next Steps