3.8. Extensions

Extensions contains optional, nice to have code that extends basic functionality. For example, all CaseStudy material is included here. It is not required for core functionality. It is not included in the default import. It is included in the default build.

3.8.1. Basic

3.8.2. Case Study Support

class aggregate.extensions.case_studies.ClassicalPremium(ports, calibration_premium)[source]

manage classical premium examples

Net, no loading Expected value, constant loading Maximum loss –> no VaR (as proxy for maximum loss) Variance Std Dev Semi-variance (Artzner p. 210) Exponential (zero utility, convex!) Esscher

Originally in hack.py

calibrate(port_name, line_name, calibration_premium, df=None, ob=None, stats=None, mn=None, var=None, sd=None)[source]

calibrate all methods…

distribution(port_name, line_name)[source]

classical methods all depend on the distribution…so pull it out pull the object that will provide q etc. pull the audit stats

illustrate(port_name, line_name, ax, margin, *, p=0, K=0, n_big=10000, n_sample=25, show_bounds=True, padding=2)[source]

illustrate simulations at p level probability probability level determines capital or capital K input margin: premium = (1 + margin) * EL, margin = rho n_big = number of policies - max of horizontal axis n_sample = number of iterations to plot

Theoretic bounds use the actual moments, simulated use those from the process being estimated

From common_scripts Pentagon took out re-computation…

price(param, port_name, line_name, method, df=None, ob=None, stats=None, mn=None, var=None, sd=None)[source]

apply method to port_name, line_name with parameter(s) (all one param) these are all classical methods

method_dict = {method name : param } param = float | [float param, p ge 1 value] latter fro Fischer method

prices(port_name, line_name, method_dict)[source]

run lots of prices

pricing_exhibit(port_name, line_name, calibration_premium, re_line)[source]

calibrate and apply to all other portfolios

aggregate.extensions.case_studies.add_defaults(dict_in, kind='agg')[source]

add default values to dict_inin. Leave existing values unchanged Used to output to a data frame, where you want all columns completed

Parameters
  • dict_in

  • kind

Returns

aggregate.extensions.case_studies.bivariate_density_plots(axi, ports, xmax, contour_scale, biv_log=True, cmap='viridis', levels=30, color_bar=False)[source]

bivarate plots of each line against the others for each portfolio in case arguments as for twelve_plot / bivden plot

axi = iterator with enough exes ports = iterable of ports (list, dict.values(), etc.)

from common_scripts.py

aggregate.extensions.case_studies.extract_sort_order(summaries, _varlist_, classical=False)[source]

Pull out exhibits. Note difference: classical uses net_classical, calibrated to roe non-classical uses pricing calibrated to

aggregate.extensions.case_studies.g_ins_stats(axi, dn0, dist, ls='-')[source]

Six part plot with EL, premium, loss ratio, profit, layer ROE and P:S for g axi = axis iterator

aggregate.extensions.case_studies.macro_market_graphs(axi, port, dn, rp)[source]

Create more succinct 4x4 graph to illustrate macro market structure and result, LR, P:S and ROE, etc.

Use a port object with calibrated distortion

see ch04_macro_market_stats_original

from: common_scripts.py ch04_macro_market_stats updated line colors

June 2022: removed all color=’k’

Parameters
  • dist

  • rp – return period

  • sigma

Returns

aggregate.extensions.case_studies.pricing(port, p, roe, as_dataframe=True)[source]

Make nice stats output for pricing from common_scripts.py

aggregate.extensions.case_studies.universal_renamer(x)[source]
aggregate.extensions.case_studies.urn(df)[source]

apply universal renamer

3.8.3. Pentagon

aggregate.extensions.pentagon.code(r)[source]

determine binary code for row

aggregate.extensions.pentagon.make_possible_pentagons()[source]

enumerate possible and impossible pentagon configurations

class aggregate.extensions.pentagon.pent_ans(L, P, M, a, Q, LR, PQ, COC)
COC

Alias for field number 7

L

Alias for field number 0

LR

Alias for field number 5

M

Alias for field number 2

P

Alias for field number 1

PQ

Alias for field number 6

Q

Alias for field number 4

a

Alias for field number 3

3.8.4. Samples

Warning

All functionality in extensions.samples has been moved into the base package.

3.8.5. Figures

aggregate.extensions.figures.adjusting_layer_losses()[source]

Figure to illustrate the process of adjusting layer losses. TODO: Add reference

aggregate.extensions.figures.discretization_agg_example(outcomes)[source]

For AAS paper. Convergence of sevs with smaller bucket size.

aggregate.extensions.figures.discretization_sev_example(outcomes)[source]

For AAS paper. Convergence of sevs with smaller bucket size.

aggregate.extensions.figures.dual_distortion(dist=None, s=0.3)[source]

Illustrate how the dual distortion relates to the distortion.

aggregate.extensions.figures.g_insurance_statistics(axi, dist, c='C0', ls='-', lw=1, diag=False, grid=False)[source]

Six part plot with EL, premium, loss ratio, profit, layer ROE and P:S for g axi = axis iterator with 6 axes dist = distortion Used to create PIR Figs 11.6 and 11.7

aggregate.extensions.figures.g_risk_appetite(axi, dist, c='C0', ls='-', N=1000, lw=1, grid=False, xlabel=True, title=True, add_tvar=False)[source]

Plot to illustrate the risk appetite associated with a distortion g. Derived from g_insurance_statistics. Plots premium, loss ratio, margin, return (easier to understand than discount), VaR wts and optionally TVaR wts axi = axis iterator with 6 axes dist = distortion Used to create PIR Figs 11.6 and 11.7

aggregate.extensions.figures.gh_example(en)[source]

Code to reproduce GHGrübel and Hermesmeier 1999, Table 1. The function exact_cdf calculates the compound probability that \(x-1/2 < X \le x+1/2\). For AAS paper with en=20.

aggregate.extensions.figures.mixing_convergence(freq_cv, sev_cv, bs=0.015625)[source]

Illustrate convergence of mixed distributions to the mixing distribution.

aggregate.extensions.figures.power_variance_family()[source]

Graph to illustrate the power variance exponential family distributions.

Reference: Jørgensen, Bent. 1997. The theory of dispersion models. CRC Press.

aggregate.extensions.figures.savings_charge()[source]

Figure to illustrate the insurance savings and expense(charge).

3.8.6. PIR Figures

aggregate.extensions.pir_figures.curlyBrace(ax, p1, p2, k_r=0.1, bool_auto=True, str_text='', int_line_num=2, fontdict={}, **kwargs)[source]

Plot an optionally annotated curly bracket on the given axes of the given figure.

Note that the brackets are anti-clockwise by default. To reverse the text position, swap “p1” and “p2”.

Note that, when the axes aspect is not set to “equal”, the axes coordinates need to be transformed to screen coordinates, otherwise the arcs may not be seeable.

Parameters

figmatplotlib figure object

The of the target axes.

axmatplotlib axes object

The target axes.

p1two element numeric list

The coordinates of the starting point.

p2two element numeric list

The coordinates of the end point.

k_rfloat

This is the gain controlling how “curvy” and “pointy” (height) the bracket is.

Note that, if this gain is too big, the bracket would be very strange.

bool_autoboolean

This is a switch controlling wether to use the auto calculation of axes scales.

When the two axes do not have the same aspects, i.e., not “equal” scales, this should be turned on, i.e., True.

When “equal” aspect is used, this should be turned off, i.e., False.

If you do not set this to False when setting the axes aspect to “equal”, the bracket will be in funny shape.

Default = True

str_textstring

The annotation text of the bracket. It would displayed at the mid point of bracket with the same rotation as the bracket.

By default, it follows the anti-clockwise convention. To flip it, swap the end point and the starting point.

The appearance of this string can be set by using “fontdict”, which follows the same syntax as the normal matplotlib syntax for font dictionary.

Default = empty string (no annotation)

int_line_numint

This argument determines how many lines the string annotation is from the summit of the bracket.

The distance would be affected by the font size, since it basically just a number of lines appended to the given string.

Default = 2

fontdictdictionary

This is font dictionary setting the string annotation. It is the same as normal matplotlib font dictionary.

Default = empty dict

**kwargsmatplotlib line setting arguments

This allows the user to set the line arguments using named arguments that are the same as in matplotlib.

Returns

thetafloat

The bracket angle in radians.

summitlist

The positions of the bracket summit.

arc1list of lists

arc1 positions.

arc2list of lists

arc2 positions.

arc3list of lists

arc3 positions.

arc4list of lists

arc4 positions.

Reference

https://uk.mathworks.com/matlabcentral/fileexchange/38716-curly-brace-annotation

aggregate.extensions.pir_figures.fig_10_3(dist=None, s=0.3)[source]

Figure 10.3 Illustrating distortion functions (s, g(s)) with vertical line at s and split loss, premium, margin, and capital labelled

aggregate.extensions.pir_figures.fig_10_5(port=None, dist=None, s=0.3)[source]

three plot version of previous with more explanation of first picture

return_period_max = defines extend of yaxis return_period_x = capital level to illustrate

map from s space into loss space extended version of ch04_s_gs_loss_premium_capital which includes the horizontal bar [ loss ][m][ equity ] plotted on the provided second axis

Suggested figure set up for extended:

f = plt.Figure(figsize=(4,3), tight_layout=True) a = f.add_axes([0, 100/3+1/27, 1, 2/3], label=’a’) b = f.add_axes([0, 0, 1, 1/3], label=’b’)

aggregate.extensions.pir_figures.fig_10_6(port=None, dist=None)[source]

Same distortion and portfolio as 10_5 Slight clarification of the diagram vs. book version.

aggregate.extensions.pir_figures.fig_4_1()[source]

Figure 4.1: illustrating quantiles.

aggregate.extensions.pir_figures.getAxSize(fig, ax)[source]

Get the axes size in pixels.

Reference: https://uk.mathworks.com/matlabcentral/fileexchange/38716-curly-brace-annotation

Parameters
  • fig – matplotlib figure object The of the target axes.

  • ax – matplotlib axes object The target axes.

Returns

ax_width : float, the axes width in pixels; ax_height : float, the axes height in pixels.

aggregate.extensions.pir_figures.natural_scale(port)[source]

For creating Table 9.15

3.8.7. Test Suite