P&L ledger
pnl_ledger.RdA treaty's profit and loss as distributions, as the Python package
aggregate's PnL: a source (a grid_distribution, or list(values, probs)) and its groups, each a book that sells cover ("sell": books
+consideration - obligation) or buys it ("buy": pays premium and
receives recoveries and commission). Every row (each leg, each side's
total, each group's result, running nets, tier and net-of blocks, and
with several groups the grand rows and the total impact) is a sum of
signed legs at each atom, with its exact distribution.
Usage
pnl_ledger(
source,
groups,
name = "ledger",
result_name = "result",
spans = NULL,
force_tower = FALSE
)
pnl_leg(label, value, kind = NULL, step = NULL)
pnl_group(
label,
role = c("sell", "buy"),
consideration = list(),
obligation = list(),
margin_label = NULL
)
ledger_sheet(ledger)
ledger_marginal(ledger)
ledger_card(ledger)
ledger_legs(ledger)
ledger_validation(ledger)
ledger_ratios(ledger)
ledger_stack(ledgers, impacts = NULL)
ledger_result(ledger)
ledger_row(ledger, row)Arguments
- source
A grid_distribution or
list(values, probs).- groups
A list of
pnl_group()s.- name
The ledger's name.
- result_name
The result row's name.
- spans
NULLor a list oflist(label, lo, hi): groupslotohi - 1(counting from 0, asaggregate) with a subtotal block, and a net-of block when a later group follows.- force_tower
Present one group as a tower.
- label
A leg's or group's label; leg labels are unique across the ledger.
- value
A number, or a function of the source's values.
- kind
NULLor one of"premium","loss","expense","recovery","commission".- step
NULL, or the step of a grid for the leg's own distribution.- role
"sell"or"buy".- consideration, obligation
Lists of
pnl_leg()s.- margin_label
A seller's own margin label on a ledger that also buys cover;
"Gross"by default.- ledger
A
pnl_ledger().- ledgers
A named list of
pnl_ledger()s, in row order.- impacts
NULLor a list ofc(label, target, base).- row
A row's label.
Value
pnl_leg() and pnl_group() lists; pnl_ledger() a ledger;
ledger_sheet(), ledger_marginal(), ledger_card() and
ledger_legs(), ledger_validation(), ledger_ratios() and
ledger_stack() data frames; ledger_result() and ledger_row() a
discrete_distribution.
Details
pnl_leg() is one cash flow, a number or a function of the source's
values (called once with all of them and returning one value each),
written as a positive magnitude. ledger_sheet() is aggregate's
economic_df: each row's mean, standard deviation, coefficient of
variation, skewness and scenario columns k01 to k99, its conditional
mean given that the grand result equals its quantile at that level, so a
column is one state of the world and foots down the sheet (k01 is the
bad year). ledger_marginal() gives each row's own quantiles,
ledger_card() the card (summary_df), ledger_legs() the declared
legs, ledger_result() and ledger_row() a row's distribution as a
discrete_distribution. The source's probabilities are rescaled to 1.
A leg with a step has its own distribution put on a grid of that step
(aggregate's bs), each value scattered linearly to its two
neighbours, which keeps its mean; only its marginal quantiles change, and
ledger_validation() compares the exact and grid means.
ledger_ratios() is aggregate's economic_ratios_df: for each group,
span, net-of block and All, premium P, loss L net of recoveries,
expense E net of commission and result M, the result's SD, ratios
of means LR, ER, CR, means of ratios E_LR, E_ER, E_CR, and
P_share and M_share of the first block; a leg without a kind counts
as premium on the consideration side and loss on the other.
ledger_stack() is stack_marginal_pnls: each ledger's result
statistics, then each impact c(label, target, base) as the difference
of two stacked rows, statistic by statistic.
Examples
book <- pnl_group("Book", "sell", list(pnl_leg("Premium", 10)), list(pnl_leg("Loss", identity)))
pnl <- pnl_ledger(list(c(2, 8), c(0.5, 0.5)), list(book), name = "Book")
mean(ledger_result(pnl))
#> [1] 5
ledger_sheet(pnl)[, c("label", "EX", "k01", "k99")]
#> label EX k01 k99
#> 1 Premium 10 10 10
#> 2 Loss -5 -8 -2
#> 3 Total 5 2 8