Title: | Actuarial Loss Development |
---|---|
Description: | Actuarial Loss Development. |
Authors: | Jimmy Briggs [cre, aut] |
Maintainer: | Jimmy Briggs <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-08-30 22:15:02 UTC |
Source: | https://github.com/jimbrig/lossdevtapp |
Aggregate Loss data
aggregate_loss_data(claim_dat, limit = NA)
aggregate_loss_data(claim_dat, limit = NA)
claim_dat |
claims data |
limit |
optional limit |
df
Shiny App Dashboard's Header Function
Functions that build the Shiny App's UI:
- 'app_ui': Main UI function
- 'app_header': wrapper around [shinydashboard::dashboardHeader()]
- 'app_sidebar': wrapper around [shinydashboard::dashboardSidebar()]
- 'app_body': wrapper around [shinydashboard::dashboardBody()]
Shiny App's User Interface Function.
app_header(title = "Loss Development", ...) app_ui(request, ...)
app_header(title = "Loss Development", ...) app_ui(request, ...)
title |
App title to be placed in the header, above the sidebar. |
... |
Arguments passed on to
|
request |
Internal parameter for 'shiny'. |
a [shinydashboard::dashboardHeader()]
The user interface definition, without modifications or side effects.
[shiny::shinyUI], [shinydashboard::dashboardPage()]
Access files for the shiny app from the package installation directory.
app_sys(...)
app_sys(...)
... |
character vectors, specifying subdirectory and file(s) within your package. The default, none, returns the root of the app. |
# Note If you manually change your package name in the 'DESCRIPTION', don't forget to change it here too, and in the config file ('inst/config.yml').
For a safer name change mechanism, use the 'golem::set_golem_name()' function.
Create a "bundle" of triangle related items from an input loss dataset. The function returns a list of class "triangle_bundle" and an attribute describing which metric the bundle describes (i.e. paid, reported, counts, etc.).
The resulting list contains:
- aggregated data filtered for ages of maturity from the 'age_increment' argument
- triangle data derived off the aggregated data
- the actual spread out triangle
- age_to_age data
- the age_to_age spread out triangle
- averages (currently only straight and weighted)
- initial selections for the LDF's and derived CDF's.
create_triangle_bundle( loss_data, age_increment = 12, origin_col = "accident_year", age_col = "devt", value_col = "paid" )
create_triangle_bundle( loss_data, age_increment = 12, origin_col = "accident_year", age_col = "devt", value_col = "paid" )
loss_data |
initial aggregated loss data as a 'data.frame' |
age_increment |
increment in months between subsequent maturity periods |
origin_col , age_col , value_col
|
column names as strings |
list of class "triangle_bundle" with an added attribute describing which metric the bundle describes (i.e. paid, reported, counts, etc.)
# create default paid triangle bundle tri_paid_bundle <- create_triangle_bundle(loss_data_all) # check out the structure str(tri_paid_bundle) # derive a similar bundle for reported dollars and counts tri_rept_bundle <- create_triangle_bundle(loss_data_all, value_col = "reported") tri_cnts_bundle <- create_triangle_bundle(loss_data_all, value_col = "n_claims")
# create default paid triangle bundle tri_paid_bundle <- create_triangle_bundle(loss_data_all) # check out the structure str(tri_paid_bundle) # derive a similar bundle for reported dollars and counts tri_rept_bundle <- create_triangle_bundle(loss_data_all, value_col = "reported") tri_cnts_bundle <- create_triangle_bundle(loss_data_all, value_col = "n_claims")
Date utility helpers for deriving start/end dates.
end_of_month(date) beg_of_month(date) start_of_month(date)
end_of_month(date) beg_of_month(date) start_of_month(date)
date |
Character string or Date representing the date to manipulate. |
Returns the Start or End Date as a Date.
# end_of_month ------------------------------------------------------------ # character input end_of_month("2020-08-13") # date input end_of_month(as.Date("2020-08-13")) # beg_of_month ------------------------------------------------------------ # character input beg_of_month("2020-08-13") # date input beg_of_month(as.Date("2020-08-13")) # start_of_month ---------------------------------------------------------- # character input start_of_month("2020-08-13") # date input start_of_month(as.Date("2020-08-13"))
# end_of_month ------------------------------------------------------------ # character input end_of_month("2020-08-13") # date input end_of_month(as.Date("2020-08-13")) # beg_of_month ------------------------------------------------------------ # character input beg_of_month("2020-08-13") # date input beg_of_month(as.Date("2020-08-13")) # start_of_month ---------------------------------------------------------- # character input start_of_month("2020-08-13") # date input start_of_month(as.Date("2020-08-13"))
Derive Triangles
derive_triangles( loss_dat, type = c("paid", "reported", "case", "n_claims"), limit = NULL )
derive_triangles( loss_dat, type = c("paid", "reported", "case", "n_claims"), limit = NULL )
loss_dat |
loss data |
type |
paid, reported, case, or n_claims |
limit |
optinal limit |
list of triangle data
Development Triangle Class
dev_tri(origin, age, value, value_label = NULL, latest_eval_date = NULL)
dev_tri(origin, age, value, value_label = NULL, latest_eval_date = NULL)
origin , age , value
|
columns necessary to generate a 'dev_tri' |
value_label |
optional label for the values (i.e. paid, incurred) |
latest_eval_date |
optional - specify latest val date |
library(lossdevtapp) my_triangle <- dev_tri( origin = loss_data$accident_year, age = loss_data$devt, value = loss_data$payment, value_label = "paid", latest_eval_date = max(loss_data$eval_date) ) class(my_triangle) str(my_triangle) print(my_triangle)
library(lossdevtapp) my_triangle <- dev_tri( origin = loss_data$accident_year, age = loss_data$devt, value = loss_data$payment, value_label = "paid", latest_eval_date = max(loss_data$eval_date) ) class(my_triangle) str(my_triangle) print(my_triangle)
Creates skeleton to document datasets via 'roxygen2'.
doc_data( obj, title = deparse(substitute(obj)), description = "DATASET_DESCRIPTION", write_to_file = TRUE, ... )
doc_data( obj, title = deparse(substitute(obj)), description = "DATASET_DESCRIPTION", write_to_file = TRUE, ... )
obj |
object to document |
title |
Title |
description |
Description |
write_to_file |
Logical |
... |
N/A |
silently returns the doc_string
data("loss_data") string <- doc_data(losses, "Loss Data", "Claims Data", FALSE) cat(string)
data("loss_data") string <- doc_data(losses, "Loss Data", "Claims Data", FALSE) cat(string)
A set of helper functions for providing verbose feedback to the developer using this packages functions.
msg_field(x) msg_value(x) msg_done(x) msg_bullet(x, bullet = cli::symbol$bullet) msg_err(x) msg_path(x) msg_info(x) msg_code(x) msg_feedback(x)
msg_field(x) msg_value(x) msg_done(x) msg_bullet(x, bullet = cli::symbol$bullet) msg_err(x) msg_path(x) msg_info(x) msg_code(x) msg_feedback(x)
x |
The string passed to various 'msg_' functions. |
bullet |
What to use for the message's 'bullet'. Defaults to 'cli::symbol$bullet' |
- [usethis::ui-questions()] - [cli::list_symbols()]
Other Feedback Utilities:
indent()
,
inform()
Indentation around various 'msg_' feedback functions.
indent(x, first = " ", indent = first)
indent(x, first = " ", indent = first)
x |
The string passed to various 'msg_' functions. |
first |
what to indent with - defaults to '" "'. |
indent |
indentation of next line - defaults to 'first' |
string
Other Feedback Utilities:
feedback
,
inform()
A wrapper around [rlang::inform()] for providing feedback to developers using this packages functions.
inform(...)
inform(...)
... |
Arguments passed on to
|
feedback in console
[rlang::inform()]
Other Feedback Utilities:
feedback
,
indent()
Actuarial claims loss data.
loss_data
loss_data
A data frame with 70331 rows and 22 variables:
eval_date
double. DESCRIPTION.
claim_num
integer. DESCRIPTION.
claim_id
character. DESCRIPTION.
accident_date
double. DESCRIPTION.
state
character. DESCRIPTION.
claimant
character. DESCRIPTION.
report_date
double. DESCRIPTION.
status
character. DESCRIPTION.
payment
double. DESCRIPTION.
case
double. DESCRIPTION.
transaction_date
double. DESCRIPTION.
trans_num
integer. DESCRIPTION.
paid
double. DESCRIPTION.
reported
double. DESCRIPTION.
accident_year
double. DESCRIPTION.
report_year
double. DESCRIPTION.
eval_year
double. DESCRIPTION.
ay_start
double. DESCRIPTION.
ay_end
double. DESCRIPTION.
ay_avg
double. DESCRIPTION.
devt_in_days
double. DESCRIPTION.
devt
double. DESCRIPTION.
Actuarial claims loss data.
loss_data_all
loss_data_all
A data frame with 888864 rows and 22 variables:
eval_date
double. DESCRIPTION.
claim_num
integer. DESCRIPTION.
claim_id
character. DESCRIPTION.
accident_date
double. DESCRIPTION.
state
character. DESCRIPTION.
claimant
character. DESCRIPTION.
report_date
double. DESCRIPTION.
status
character. DESCRIPTION.
payment
double. DESCRIPTION.
case
double. DESCRIPTION.
transaction_date
double. DESCRIPTION.
trans_num
integer. DESCRIPTION.
paid
double. DESCRIPTION.
reported
double. DESCRIPTION.
accident_year
double. DESCRIPTION.
report_year
double. DESCRIPTION.
eval_year
double. DESCRIPTION.
ay_start
double. DESCRIPTION.
ay_end
double. DESCRIPTION.
ay_avg
double. DESCRIPTION.
devt_in_days
double. DESCRIPTION.
devt
double. DESCRIPTION.
Run the Shiny Application
run_app( onStart = NULL, options = list(), enableBookmarking = NULL, uiPattern = "/", ... )
run_app( onStart = NULL, options = list(), enableBookmarking = NULL, uiPattern = "/", ... )
onStart |
A function that will be called before the app is actually run.
This is only needed for |
options |
Named options that should be passed to the |
enableBookmarking |
Can be one of |
uiPattern |
A regular expression that will be applied to each |
... |
arguments to pass to golem_opts. See '?golem::get_golem_options' for more details. |
A function to simulate *transactional* actuarial claims/loss data for Property Casualty Insurance.
simulate_claims( n_claims = 1000, start_date = "2015-01-01", end_date = Sys.Date(), seed = 12345, loss_distribution = "lnorm", params = list(mean_log = 7.5, sd_log = 1.5), status_prob_open = 0.96, cache = FALSE, ... )
simulate_claims( n_claims = 1000, start_date = "2015-01-01", end_date = Sys.Date(), seed = 12345, loss_distribution = "lnorm", params = list(mean_log = 7.5, sd_log = 1.5), status_prob_open = 0.96, cache = FALSE, ... )
n_claims |
Numeric - Number of claims to be simulated. |
start_date , end_date
|
Character/Date - Start and End dates for simulation to create claims within (experience_period). |
seed |
Numeric - the seed is used to isolate randomness during statistical simulations. |
loss_distribution |
Character - must be one of the distributions mentioned in the details below. Defaults to lognormal. |
params |
Parameters associated with the specified 'loss_distribution' in a list (i.e. 'list(mean_log = 7.5, sd_log = 1.5)' for lognormal distribution). |
status_prob_open |
Numeric - must be within '0 < x < 1' and represents probability a claim is open when running binomial simulations for claims' status. |
cache |
Boolean/Logical - enable caching? |
... |
If needed |
Severity/Loss Distributions: - Normal: 'norm' - Parameters are 'mean' and 'sd'. - Lognormal: 'lnorm' - Parameters are 'meanlog' and 'sdlog'. - Gamma: 'gamma' - Shape, Rate, Scale - LogGamma: 'lgamma' - Shapelog, Ratelog - Pareto: 'pareto' - Shape and Scale - Weibull: 'weibull' - Shape and Scale - Generalized Beta: 'genbeta' - Shape1, Shape2, Shape3, Rate, Scale
The return value, if any, from executing the function.
Shiny module containing 'mod_triangles_ui' and 'mod_triangles_server', respectively.
This module renders a user interface for displaying and analyzing actuarial loss data in the form of loss development triangles.
A shiny Module.
mod_triangles_ui(id, loss_data = loss_data_all) mod_triangles_server(id, loss_data, selected_eval)
mod_triangles_ui(id, loss_data = loss_data_all) mod_triangles_server(id, loss_data, selected_eval)
id |
ID associated with UI counterpart |
loss_data |
loss data |
selected_eval |
selected evaluation date |