Skip to main content

aggregate.stack()

Stack ledgers’ results, aggregate’s stack_marginal_pnls: one row

Usage

aggregate.stack(
    ledgers,
    impacts=None,
)

per ledger with the mean, standard deviation, coefficient of variation, skewness and quantiles P01 to P99 of its result, then one row per impact, the difference of two stacked rows statistic by statistic.

Parameters

ledgers: dict of str to Ledger

In row order.

impacts: list of tuple of (str, str, str) = None
(label, target, base): the row target less the row base.

Returns

dict
Columns label, EX, SD, CV, Skew and P01 to P99.

Raises

ValueError
If an impact names a row that is not stacked.

Examples

>>> from prospicio.aggregate import Group, Ledger, Leg, stack
>>> src = ([2.0, 8.0], [0.5, 0.5])
>>> a = Ledger(src, [Group("A", "sell", [Leg("P", 10.0)], [Leg("L", lambda x: x)])])
>>> b = Ledger(src, [Group("B", "sell", [Leg("P", 12.0)], [Leg("L", lambda x: x)])])
>>> stack({"a": a, "b": b}, [("b less a", "b", "a")])["EX"]

[5.0, 7.0, 2.0]