tidyactuarial is a comprehensive R package for financial mathematics and life contingencies. It bridges the gap between classical actuarial notation (SOA/CAS standards) and the modern tidyverse workflow.
The package is designed for actuaries, students, and researchers who need reproducible, vectorized, and “tidy” actuarial calculations.
tibble objects and are compatible with the native R pipe
|> or %>%.Once the package is on CRAN, you can install it with:
install.packages("tidyactuarial")
#> Installing package into 'C:/Users/LENOVO/AppData/Local/Temp/RtmpG8Qiyo/temp_libpath3c505756476c'
#> (as 'lib' is unspecified)
#> Warning: package 'tidyactuarial' is not available for this version of R
#>
#> A version of this package for your version of R might be available elsewhere,
#> see the ideas at
#> https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packagesAlternatively, you can install the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("julian.fajardo1908/tidyactuarial")Building a life table and calculating a net level premium for a 20-year endowment insurance:
library(tidyactuarial)
# 1. Create a life table (ensure qx has the same length as x)
ages <- 0:110
probs <- rep(0.002, length(ages))
lt <- lifetable(x = ages, qx = probs, radix = 100000)
# 2. Calculate net premium for a 35-year-old (20-year endowment)
# Added benefit = 100000
premium_x(
lt = lt,
x = 35,
n = 20,
i = 0.05,
product = "endowment",
benefit = 100000,
tidy = TRUE
)
#> # A tibble: 1 x 15
#> x m n product benefit k frac premium_timing prem_start n_prem
#> <int> <int> <int> <chr> <dbl> <int> <chr> <chr> <chr> <int>
#> 1 35 0 20 endowm... 100000 1 UDD due issue 20
#> # i 5 more variables: woolhouse <chr>, premium <dbl>, premium_annual <dbl>,
#> # apv_benefits <dbl>, apv_premiums <dbl>Generate a tidy schedule for a coupon bond:
bond_cash_flows(
face = 1000,
coupon_rate = 0.06,
years_to_maturity = 5,
coupons_per_year = 2
)
#> # A tibble: 11 x 5
#> cashflow_id period time cash_flow type
#> <int> <int> <dbl> <dbl> <chr>
#> 1 1 1 0.5 30 coupon
#> 2 2 2 1 30 coupon
#> 3 3 3 1.5 30 coupon
#> 4 4 4 2 30 coupon
#> 5 5 5 2.5 30 coupon
#> 6 6 6 3 30 coupon
#> 7 7 7 3.5 30 coupon
#> 8 8 8 4 30 coupon
#> 9 9 9 4.5 30 coupon
#> 10 10 10 5 30 coupon
#> 11 11 10 5 1000 redemptionMathematical formulas and actuarial notation follow: