Output Functions¶
Functions for formatting and structuring quote results.
Overview¶
The Output object holds the final quote results and is automatically populated by calculation functions like $CalculatePremiumAdditive.
Output Structure¶
{
"Premium": 644.00, // Final premium amount
"IptApplied": 0.12, // IPT rate applied
"Message": "", // Quote message
"Monthly": { // Monthly payment breakdown (11 instalments)
"Enabled": true, // Monthly payments offered
"MonthlyAmount": 56.50, // Monthly instalment
"Deposit": 112.00, // Initial deposit
"FirstPayment": 56.50, // First instalment
"TotalRepayment": 733.50, // Total with finance charges
"CreditCharge": 89.50, // Finance charge
"CreditChargePercentage": 13.9,
"APR": 19.9
},
"UnderwriterDecisions": [], // Decisions added by $Decline, $Referral, ...
"Endorsements": [] // Endorsements added by $AddEndorsement
}
Automatic Population¶
The Output object is automatically updated when calling premium calculation functions:
// Initialize pricing
$SetCurrencyToPricingMatrix("GBP");
$SetCommissionRateToPricingMatrix(0.15);
$SetIptRateToPricingMatrix(0.12);
$AddItemToPricingMatrix("Base Premium", 500.00, 1.0);
// Calculate - Output is automatically populated
$CalculatePremiumAdditive("NewBusiness");
// Access output values
totalPremium = Output.Premium; // 644.00
iptRate = Output.IptApplied; // 0.12
monthlyAmount = Output.Monthly.MonthlyAmount; // ~56.50
Output Fields¶
Premium¶
The final total premium including all calculations:
finalPremium = Output.Premium;
// Premium includes:
// - Base items
// - Applied factors
// - Discounts
// - Commission
// - IPT
// - Fees
IPT Applied¶
The IPT rate used in calculations:
iptRate = Output.IptApplied; // 0.12 (12%)
// Display to customer
iptAmount = finalPremium * (iptRate / (1 + iptRate));
Monthly Payments¶
When monthly payments are enabled, the Monthly object contains the payment breakdown:
monthly = Output.Monthly;
// Payment structure
monthlyPayment = monthly.MonthlyAmount; // e.g., 56.50
deposit = monthly.Deposit; // e.g., 112.00 (2x monthly)
totalPayable = monthly.TotalRepayment; // e.g., 733.50
// There are always 11 instalments; the count isn't part of Output
Accessing Output Values¶
Direct Access¶
// After calculation
$CalculatePremiumAdditive("NewBusiness");
// Read output
premium = Output.Premium;
monthly = Output.Monthly.MonthlyAmount;
Conditional Monthly Payments¶
// Check if monthly payments are available
if (Output.Monthly != null && Output.Monthly.MonthlyAmount > 0) {
// Display monthly option
$Log("Pay monthly: £" + Output.Monthly.MonthlyAmount.ToString());
$Log("Deposit: £" + Output.Monthly.Deposit.ToString());
} else {
// Single payment only
$Log("Total premium: £" + Output.Premium.ToString());
}
Formatting for Display¶
// Format premium with currency
function FormatCurrency(amount) {
return "£" + ($Round(amount, 2)).ToString();
}
// Create customer-facing output
function FormatQuoteOutput() {
result = {
"AnnualPremium": FormatCurrency(Output.Premium),
"IPTRate": (Output.IptApplied * 100).ToString() + "%",
"MonthlyOption": null
};
if (Output.Monthly != null) {
result.MonthlyOption = {
"Deposit": FormatCurrency(Output.Monthly.Deposit),
"MonthlyPayment": FormatCurrency(Output.Monthly.MonthlyAmount),
"TotalRepayment": FormatCurrency(Output.Monthly.TotalRepayment)
};
}
return result;
}
displayOutput = FormatQuoteOutput();
Integration with Ledger¶
The Output object summarizes the detailed Ledger:
$CalculatePremiumAdditive("NewBusiness");
// Output.Premium equals sum of ledger gross amounts
ledgerTotal = $Sum(Ledger, "GrossAmount");
outputPremium = Output.Premium;
// Should match (within rounding)
matches = $Abs(ledgerTotal - outputPremium) < 0.01;
MTA Output¶
For mid-term adjustments, output shows the adjustment premium:
$CalculateMTAPremium(15.00);
// Output shows adjustment difference
adjustmentPremium = Output.Premium; // Additional premium due
// Can also access from environment variable
additionalPremium = AdditionalPremium; // Set by $CalculateMTAPremium
Cancellation Output¶
For cancellations, refund information is in the Cancellation object:
$CalculateProRataCancellation(25.00, false);
// Refund details
refundAmount = Cancellation.RefundAmount;
refundMessage = Cancellation.RefundMessage;
// Ledger shows cancellation entries
cancellationEntries = Ledger.Filter((e) =>
e.LedgerSection == "Cancellation");
Complete Quote Response¶
// Generate complete quote response
function GenerateQuoteResponse() {
// Calculate premium
$CalculatePremiumAdditive("NewBusiness");
// Build response
response = {
"Status": "Success",
"QuoteReference": GenerateQuoteReference(),
"Premium": {
"Annual": Output.Premium,
"IPTRate": Output.IptApplied,
"IPTAmount": Output.Premium * (Output.IptApplied / (1 + Output.IptApplied))
},
"Ledger": Ledger,
"UnderwriterDecisions": UnderwriterDecisions,
"Endorsements": Endorsements
};
// Add monthly option if available
if (Output.Monthly != null && Output.Monthly.MonthlyAmount > 0) {
response.Premium.Monthly = {
"Deposit": Output.Monthly.Deposit,
"MonthlyPayment": Output.Monthly.MonthlyAmount,
"TotalRepayment": Output.Monthly.TotalRepayment,
"APR": Output.Monthly.APR
};
}
return response;
}
quoteResponse = GenerateQuoteResponse();
Best Practices¶
1. Always Calculate Before Accessing Output¶
// ✅ Good - calculate first
$CalculatePremiumAdditive("NewBusiness");
premium = Output.Premium;
// ❌ Poor - output may be stale/empty
premium = Output.Premium; // Before calculation
2. Check for Null Values¶
// Monthly payments may not be available
if (Output.Monthly != null) {
monthly = Output.Monthly.MonthlyAmount;
} else {
// Single payment only
}
3. Use Output for Final Values Only¶
// ✅ Good - use PricingMatrix during build-up
$AddItemToPricingMatrix("Base", 500.00, 1.0);
$AddFactorToPricingMatrix("Age", 1.20, true, 0);
// Calculate once when done
$CalculatePremiumAdditive("NewBusiness");
final = Output.Premium;
// ❌ Poor - don't recalculate repeatedly
$AddItemToPricingMatrix("Base", 500.00, 1.0);
$CalculatePremiumAdditive("NewBusiness");
$AddFactorToPricingMatrix("Age", 1.20, true, 0);
$CalculatePremiumAdditive("NewBusiness"); // Wasteful
4. Preserve Output for Comparison¶
// Save output before MTA
OriginalPremium = Output.Premium;
// Calculate MTA
$CalculateMTAPremium(15.00);
NewPremium = Output.Premium;
Difference = NewPremium - OriginalPremium;
Environment Variables¶
| Variable | Type | Description |
|---|---|---|
Output |
Object | Main output structure with Premium, IPTApplied, Monthly |
PricingMatrix |
Object | Source data for Output.Premium |
Ledger |
Array | Detailed breakdown of Output.Premium |
Next Steps¶
- Pricing Matrix Functions - Build up to Output
- Quote Calculation Functions - Functions that populate Output
- Examples - See Output in complete workflows