Learn R Programming

baselinenowcast (version 0.2.0)

as_reporting_triangle.triangle: Convert ChainLadder triangle to reporting_triangle format

Description

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

Usage

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

Value

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

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().

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.

See Also

  • as_ChainLadder_triangle() for converting to ChainLadder

  • as_reporting_triangle.matrix() for the underlying method

  • as_reporting_triangle.data.frame() for creating from data frames

Reporting triangle construction and validation [.reporting_triangle(), [<-.reporting_triangle(), as.data.frame.reporting_triangle(), as.matrix.reporting_triangle(), as_ChainLadder_triangle(), as_reporting_triangle(), as_reporting_triangle.data.frame(), as_reporting_triangle.matrix(), assert_reporting_triangle(), get_delays_from_dates(), get_delays_unit(), get_max_delay(), get_mean_delay(), get_quantile_delay(), get_reference_dates(), get_report_dates(), get_reporting_structure(), head.reporting_triangle(), is_reporting_triangle(), new_reporting_triangle(), print.reporting_triangle(), reporting_triangle-class, summary.reporting_triangle(), tail.reporting_triangle(), truncate_to_delay(), truncate_to_quantile(), validate_reporting_triangle()

Examples

Run this code
if (FALSE) { # requireNamespace("ChainLadder", quietly = TRUE)
# 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)

# 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)
}

Run the code above in your browser using DataLab