Skip to contents

This S3 method converts a ChainLadder triangle object to a reporting_triangle object, enabling use of baselinenowcast's nowcasting methods.

Usage

# S3 method for class 'triangle'
as_reporting_triangle(data, delays_unit = "days", reference_dates = NULL, ...)

Arguments

data

A ChainLadder triangle object (class "triangle").

delays_unit

Character string specifying the temporal granularity of the delays. Options are "days", "weeks", "months", "years". Default is "days".

reference_dates

Vector of dates corresponding to the rows of the triangle. If not provided, will attempt to coerce row names to dates. If row names cannot be coerced to dates and this is not provided, an error will be raised.

...

Additional arguments passed to as_reporting_triangle.matrix().

Value

A reporting_triangle object. See reporting_triangle for details on the structure.

Details

This method converts a ChainLadder triangle back to baselinenowcast's reporting_triangle format. If reference_dates is not provided, the function will attempt to extract dates from the triangle's row names.

The ChainLadder package must be installed to use this function.

The conversion uses as_reporting_triangle.matrix() internally after extracting the matrix from the ChainLadder triangle object.

Examples

# Create a reporting triangle
data_as_of_df <- syn_nssp_df[syn_nssp_df$report_date <= "2026-04-01", ]
rep_tri <- as_reporting_triangle(data = data_as_of_df)
#>  Using max_delay = 154 from data

# Convert to ChainLadder triangle
cl_triangle <- as_ChainLadder_triangle(rep_tri)

# Convert back to reporting_triangle (seamless round-trip)
# max_delay is inferred from the ChainLadder triangle dimensions
rep_tri_2 <- as_reporting_triangle(data = cl_triangle)
print(rep_tri_2)
#> Reporting Triangle
#> Delays unit: days
#> Reference dates: 2025-10-25 to 2026-04-01
#> Max delay: 154
#> Structure: 1
#> 
#> Showing last 10 of 159 rows
#> Showing first 10 of 155 columns
#> 
#>              0   1  2  3  4  5  6  7  8  9
#> 2026-03-23 210 131 34 50 35 12  1 25 20  6
#> 2026-03-24 221  96 22 10 13  6  0  5  9 NA
#> 2026-03-25 291 129 17 26 42 29 23 25 NA NA
#> 2026-03-26 179  96 22 50  9  8 18 NA NA NA
#> 2026-03-27 284  40 41 54 28 12 NA NA NA NA
#> 2026-03-28 217  78 46 14 39 NA NA NA NA NA
#> 2026-03-29 336 161 62 13 NA NA NA NA NA NA
#> 2026-03-30 296  53 55 NA NA NA NA NA NA NA
#> 2026-03-31 210 108 NA NA NA NA NA NA NA NA
#> 2026-04-01 236  NA NA NA NA NA NA NA NA NA
#> 
#> Use print(x, n_rows = NULL, n_cols = NULL) to see all data