In [1]:
import chainladder as cl
cl.__version__
Out[1]:
chainladder
relies on the xlcompose
library to produce rich spreadsheet outputs. These are accessed by calling on cl.load_template
which is similar to how we load sample data with cl.load_dataset
. A template is a YAML file that specifies the layout of an Excel file. Anyone can write a custom template and pass it to the cl.load_template
function. You can view the template files included with chainladder
here. To make your own custom templates it is worth reading the xlcompose templating docs.
In [2]:
triangle=cl.load_dataset('usauto')['incurred']
triangle
Out[2]:
load_template
will generate an Excel template object to which you can pass data. We will be using the 'triangle' template which requires (at a minimum) a Triangle
object that is a single index/column representation.
In this example, our template is given one object, out Triangle
. From the one Triangle, we can infer a lot of information that we can represent in our exhibit.
In [3]:
cl.load_template('triangle', triangle=triangle).to_excel('example.xlsx')
Note also that loading the template creates an xlcompose
object, but it does not actually create an Excel file. To do that, you must call the to_excel
method on the object.
If we transform our triangle by a Development
estimator, let's see how the same template acknowledges this additional information.
In [4]:
cl.load_template(
template='triangle',
triangle=cl.Development().fit_transform(triangle)
).to_excel('example.xlsx')
Anyone can examine the YAML template to see what options are available. Let's explore all available options in out 'triangle' template.
In [5]:
cl.load_template(
template='triangle',
triangle=cl.Development().fit_transform(triangle),
scenarios={'Simple (All)': cl.Development(average='simple'),
'Volume (All)': cl.Development(),
'Volume (5Yr)': cl.Development(n_periods=5),
'Volume (3Yr)': cl.Development(n_periods=3)},
triangle_name = 'US Auto Industry',
sheet_name='US Auto',
set_header=['&RExhbit 1', 'Sheet 1'],
index_label='Accident Year'
).to_excel('example.xlsx')
By using xlcompose
for rendering spreadsheets, you do not need to concern yourself with the shapes of your triangles. The Excel template dynamically resizes to smaller or larger triangles. Let's try the same template on a smaller triangle.
In [6]:
triangle = cl.load_dataset('ukmotor')
In [7]:
cl.load_template(
template='triangle',
triangle=cl.Development(average=['volume']*3+['simple']*3).fit_transform(triangle),
scenarios={'Simple (All)': cl.Development(average='simple'),
'Volume (All)': cl.Development(),
'Volume (5Yr)': cl.Development(n_periods=5),
'Volume (3Yr)': cl.Development(n_periods=3)},
triangle_name = 'UK Motor',
sheet_name='Motor',
set_header=['&RExhbit 1', 'Sheet 1'],
index_label='Accident Year'
).to_excel('example.xlsx')
In [ ]: