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
Monthly: { // Monthly payment breakdown
MonthlyPayment: 56.50, // Monthly installment
Deposit: 112.00, // Initial deposit
NumberOfPayments: 11, // Number of monthly payments
TotalPayable: 733.50 // Total with finance charges
}
}
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
let totalPremium = Output.Premium; // 644.00
let iptRate = Output.IptApplied; // 0.12
let monthlyAmount = Output.Monthly.MonthlyPayment; // ~56.50
Output Fields¶
Premium¶
The final total premium including all calculations:
let finalPremium = Output.Premium;
// Premium includes:
// - Base items
// - Applied factors
// - Discounts
// - Commission
// - IPT
// - Fees
IPT Applied¶
The IPT rate used in calculations:
let iptRate = Output.IptApplied; // 0.12 (12%)
// Display to customer
let iptAmount = finalPremium * (iptRate / (1 + iptRate));
Monthly Payments¶
When monthly payments are enabled, the Monthly object contains the payment breakdown:
let monthly = Output.Monthly;
// Payment structure
let monthlyPayment = monthly.MonthlyPayment; // e.g., 56.50
let deposit = monthly.Deposit; // e.g., 112.00 (2x monthly)
let numPayments = monthly.NumberOfPayments; // e.g., 11
let totalPayable = monthly.TotalPayable; // e.g., 733.50
Accessing Output Values¶
Direct Access¶
// After calculation
$CalculatePremiumAdditive("NewBusiness");
// Read output
let premium = Output.Premium;
let monthly = Output.Monthly.MonthlyPayment;
Conditional Monthly Payments¶
// Check if monthly payments are available
if (Output.Monthly != null && Output.Monthly.MonthlyPayment > 0) {
// Display monthly option
$Log("Pay monthly: £" + $ToString(Output.Monthly.MonthlyPayment));
$Log("Deposit: £" + $ToString(Output.Monthly.Deposit));
} else {
// Single payment only
$Log("Total premium: £" + $ToString(Output.Premium));
}
Formatting for Display¶
// Format premium with currency
fn FormatCurrency(amount) {
return "£" + $ToString($Round(amount, 2));
}
// Create customer-facing output
fn FormatQuoteOutput() {
let result = {
AnnualPremium: FormatCurrency(Output.Premium),
IPTRate: $ToString(Output.IptApplied * 100) + "%",
MonthlyOption: null
};
if (Output.Monthly != null) {
result.MonthlyOption = {
Deposit: FormatCurrency(Output.Monthly.Deposit),
MonthlyPayment: FormatCurrency(Output.Monthly.MonthlyPayment),
NumberOfPayments: Output.Monthly.NumberOfPayments,
TotalPayable: FormatCurrency(Output.Monthly.TotalPayable)
};
}
return result;
}
let displayOutput = FormatQuoteOutput();
Integration with Ledger¶
The Output object summarizes the detailed Ledger:
$CalculatePremiumAdditive("NewBusiness");
// Output.Premium equals sum of ledger gross amounts
let ledgerTotal = $Sum($Map(Ledger, fn(e) => e.GrossAmount));
let outputPremium = Output.Premium;
// Should match (within rounding)
let matches = $Abs(ledgerTotal - outputPremium) < 0.01;
MTA Output¶
For mid-term adjustments, output shows the adjustment premium:
$CalculateMTAPremium(15.00);
// Output shows adjustment difference
let adjustmentPremium = Output.Premium; // Additional premium due
// Can also access from environment variable
let additionalPremium = AdditionalPremium; // Set by $CalculateMTAPremium
Cancellation Output¶
For cancellations, refund information is in the Cancellation object:
$CalculateProRataCancellation(25.00, false);
// Refund details
let refundAmount = Cancellation.RefundAmount;
let refundMessage = Cancellation.RefundMessage;
// Ledger shows cancellation entries
let cancellationEntries = $Filter(Ledger, fn(e) =>
e.LedgerSection == "Cancellation"
);
Complete Quote Response¶
// Generate complete quote response
fn GenerateQuoteResponse() {
// Calculate premium
$CalculatePremiumAdditive("NewBusiness");
// Build response
let 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.MonthlyPayment > 0) {
response.Premium.Monthly = {
Deposit: Output.Monthly.Deposit,
MonthlyPayment: Output.Monthly.MonthlyPayment,
NumberOfPayments: Output.Monthly.NumberOfPayments,
TotalPayable: Output.Monthly.TotalPayable,
APR: 9.9 // Example APR
};
}
return response;
}
let quoteResponse = GenerateQuoteResponse();
Best Practices¶
1. Always Calculate Before Accessing Output¶
// ✅ Good - calculate first
$CalculatePremiumAdditive("NewBusiness");
let premium = Output.Premium;
// ❌ Poor - output may be stale/empty
let premium = Output.Premium; // Before calculation
2. Check for Null Values¶
// Monthly payments may not be available
if (Output.Monthly != null) {
let monthly = Output.Monthly.MonthlyPayment;
} 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");
let 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
let OriginalPremium = Output.Premium;
// Calculate MTA
$CalculateMTAPremium(15.00);
let NewPremium = Output.Premium;
let 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