Display labels on statements, layers, reinsurance, expenses, and premium with the DecL as clause

DecL
output
P&L
Author

Stephen J. Mildenhall

Published

2026-10-30

Every DecL statement that defines an object has a name, the bare word after its kind, which identifies the object and is the handle another program uses to refer to it. A label is the text shown for it in output. The clause as LABEL follows the item it labels: the name of a statement, an occurrence layer, a reinsurance layer, an expense group, or a premium. A label is presentation only and changes no computed value. The label property returns the label, or a default, or the name, so it is never blank, and qd shows it in the heading of its description.

A label that is a single word, such as as GWP, needs no quotes. A label with spaces or punctuation is quoted, as "Motor Deal", and may contain any character except a double quote or a line break; a reserved word such as premium must also be quoted. Without a label the output uses a default: Gross for the first step of a P&L walk, Premium and Loss for its premium and loss legs, the basis for an expense group, such as fixed expense, and the layer, such as occ 1750 xs 250, for a reinsurance step.

xpnl Deal as "Motor Deal" 10000 premium as GWP less ...     # statement and premium
agg Deal.Book as "Motor Book" ...                           # the wrapped aggregate
2000 xs 0 as "Policy Limit"                                 # occurrence layer
occurrence net of 1750 xs 250 rate 0.325 as "Occ Re"        # reinsurance layer
0.15 premium expenses as Acquisition                        # expense group
Code
import re
from aggregate import build, qd, __version__
from style import wprint, GT, figures
figures()
print(__version__)
1.43.1

Labels in a P&L walk

The example is the ceding commission treaty of Using pnl and xpnl, with a label at every site and the expense split into two groups. In the qd description the first step is the label of the xpnl, Motor Deal, and the cover step is the label of the reinsurance layer, Occ Re.

Code
program = '''xpnl Deal as "Motor Deal"
  10000 premium as GWP
  less
    agg Deal.Book as "Motor Book"
      10000 premium at 0.7 lr
      2000 xs 0 as "Policy Limit"
      sev lognorm 150 cv 2.5
      occurrence net of
        1750 xs 250 rate 0.325 cede 0.1 as "Occ Re"
      mixed gamma 0.25
  less
    0.15 premium expenses as Acquisition
    1000 fixed expenses as "General Expense"'''
x = build(program)
qd(x)
print(x.name, x.label, sep=', ')
PnL('Motor Deal': 2 groups, 7 legs -> 'margin')

                             EX     SD       CV     Skew    P01  Median   P99
Step       Side                                                              
Motor Deal Consideration  10000      0        0           10000   10000 10000
           Obligation     -9500 2706.5 -0.28489 -0.67617 -17060   -9180 -4620
           Margin           500 2706.5   5.4129 -0.67617  -7060     820  5380
Occ Re     Consideration  -3250      0        0           -3250   -3250 -3250
           Obligation      2844 1619.5  0.56944  0.94221    405    2605  7645
           Margin          -406 1619.5  -3.9889  0.94221  -2845    -645  4395
           Net           93.999 1426.7   15.178  -0.5251  -3745     215  2855
All        Consideration   6750      0        0            6750    6750  6750
           Obligation     -6656 1426.7 -0.21435  -0.5251 -10495   -6535 -3895
           Margin        93.999 1426.7   15.178  -0.5251  -3745     215  2855
           Impact          -406 1619.5  -3.9889  0.94221  -2845    -645  4395
Deal, Motor Deal

The ledger economic_df shows the labels in its Label level. The premium leg is GWP, the loss leg and the margin of the first step take the label of the wrapped aggregate, Motor Book, each expense group is its own leg, and the legs of the cover are Occ Re premium, Occ Re recovery, and Occ Re commission. The rows Total, Net, and Impact are derived and keep their names. The rows of economic_ratios_df are the steps, under the same labels.

Code
GT(x.economic_df[['EX', 'SD']], float_format=',.0f')
StepSideLabelEXSD
Motor DealConsiderationGWP10,0000
ObligationMotor Book-7,0002,706
Acquisition-1,5000
General Expense-1,0000
Total-9,5002,706
MarginMotor Book5002,706
Occ ReConsiderationOcc Re premium-3,2500
ObligationOcc Re recovery2,5191,619
Occ Re commission3250
Total2,8441,619
MarginTotal-4061,619
Net941,427
AllConsiderationNet6,7500
ObligationNet-6,6561,427
MarginNet941,427
Impact-4061,619
Code
GT(x.economic_ratios_df[['P', 'L', 'E', 'M', 'LR', 'CR']],
   float_format=',.0f', ratio_cols=['LR', 'CR'])
StepPLEMLRCR
Motor Deal10,0007,0002,50050070.0%95.0%
Occ Re-3,250-2,519-325-40677.5%87.5%
All6,7504,4812,1759466.4%98.6%

Default labels and labels on the wrapped aggregate

The same program with every as clause removed shows the defaults, first for the steps and then in the Label level of the ledger. The labels of the occurrence layer and of the reinsurance layer are stored on the wrapped aggregate, in its labels.

Code
plain = build(re.sub(r' as ("[^"]*"|\w+)', '', program).replace('Deal', 'Plain'))
print(list(plain.economic_ratios_df.index))
wprint(list(plain.economic_df.index.get_level_values('Label').unique()))
print(x.engine.labels)
['Gross', 'occ 1750 xs 250', 'All']
['Premium', 'Loss', 'premium expense', 'fixed expense', 'Total', 'Gross', 'occ
1750 xs 250 premium', 'occ 1750 xs 250 recovery', 'occ 1750 xs 250 commission',
'Net', 'Impact']
labels({'layer': 'Policy Limit', 'occ_reins': {0: 'Occ Re'}})