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
Parameters
quoteType(string) - Type of quote: "NewBusiness", "Renewal", "Regular", "MTA"
Returns
- Ledger object with all calculation entries
Environment Variables Used
PricingMatrix- Input pricing structureLedger- Output transaction ledger (cleared and rebuilt)Output- Updated with final premium and monthly paymentsProductDetails- Product configurationHasActiveFinanceAgreement- 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
Parameters
quoteType(string) - Quote type, e.g."NewBusiness", or"MTA"for a mid-term adjustmentamount(number) - Tax duty amount
Behaviour
- MTA: adds the duty to both
PricingMatrixandAdjustmentDifferencePricingMatrixand updatesAdditionalPremium. - Other quote types: adds the duty to
PricingMatrix, then recalculates monthly payments and updatesOutput,MonthlyPaymentandQuotePublicData.
Returns
- Ledger object
Example
$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
Example
Midterm Adjustments (MTA)¶
$CalculateMTAPremium¶
Calculates premium changes for mid-term adjustments. Handles pro-rata calculations, cooling-off periods, and adjustment differences.
Signature
Parameters
mtaFee(number) - Admin fee for the MTAfailIfProhibitedCalculations(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 ofPreviousMatriciesis used instead and a warning is logged; this fallback is temporary, for callers not yet sendingPreviousMatrix. If neither is supplied, orPreviousMatriciesis 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 adjustmentPolicy- Policy object with inception/expiry datesMTAWithinCoolingOffPeriod- Whether the MTA falls within the cooling-off periodMTAChanges- Object whose keys are the changed sections. If every key isPhotographerType,PersonalDetailsorBusinessName, no MTA fee is chargedMTAWaivePremium(optional) - If true, waives the premium changeMTAShouldChargeAdminFeeDifference(optional, default false) - If true, an increase in the admin fee betweenPreviousMatrixandPricingMatrixis added to the MTA fee. A decrease is never refundedMTAOverrideFee(optional) - If true, the MTA fee is set to 0 and the fee that would have been charged is saved toMTAOverridenFeeAmountImportedMTAFee(optional) - If set, used as the MTA fee instead of the calculated oneProductDetails,QuotePublicData- Used to refresh the quote public data
Environment Variables Updated
PricingMatrix,AdjustmentDifferencePricingMatrix,LedgerAdditionalPremium- Sum of the gross amounts of all non-fee ledger entriesQuotePublicData- Updated fromAdjustmentDifferencePricingMatrixMTAWaivedAmount- Premium that was waived (only whenMTAWaivePremiumis true)MTAOverridenFeeAmount- Fee that was overridden (only whenMTAOverrideFeeis true)
Admin Fee Rules
- By default the policy admin fee does not change on an MTA:
PricingMatrixtakes the base fee fromPreviousMatrix. - With
MTAShouldChargeAdminFeeDifference = true, the new admin fee is kept and the customer paysmtaFee + max(0, newFee - previousFee). - The fee is then adjusted in this order: set to 0 for
MTAChangesthat carry no fee, set to 0 whenMTAOverrideFeeis true, and replaced byImportedMTAFeewhen 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
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 ofPreviousMatriciesas$CalculateMTAPremiumMTAWithinCoolingOffPeriod- Whether the MTA falls within the cooling-off period. If not set, the MTA is treated as outside itMTAValidationErrors- 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
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
Parameters
- None
Returns
- Validation result
Example
Cancellation Functions¶
$CalculateFullCancellation¶
Calculates a full refund cancellation (typically within cooling-off period).
Signature
Parameters
cancellationFee(number) - Cancellation fee amountrefundAdministrationFee(boolean, optional) - If true, refunds admin fees (default: true)
Environment Variables Used
Ledger- Output cancellation ledger (cleared and rebuilt)MTALedgerHistory- Historical ledger entriesCancellation- Cancellation object (updated with refund details)FinanceDetails- Finance agreement detailsCancellationReason- Reason for cancellation
Returns
- Ledger object with cancellation entries
Non-Refundable Admin Fee
When refundAdministrationFee is false:
- The
Feeledger 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.NonRefundableAdminFeeAmountis 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
Parameters
cancellationFee(number) - Cancellation fee amountrefundAdministrationFee(boolean, optional) - If true, refunds admin fees (default: true)
Environment Variables Used
- Same as
$CalculateFullCancellation Policy- Policy dates for pro-rata calculationCancellationDate- 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
Parameters
cancellationFee(number) - Cancellation fee amount (typically 0)
Environment Variables Used
Ledger- Output cancellation ledgerCancellation- Updated with zero refund detailsCancellationReason- 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
Parameters
referenceDate(date) - Date to calculate age at (typically today or inception date)birthdate(date) - Date of birthtimezone(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
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
Example
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¶
- Ledger Functions - Transaction tracking
- Underwriter Functions - Decision-making
- Examples - Complete MTA workflow