Read a year loss table
read_ylt.RdYears of events from a vendor's year loss table, one row per non-zero
event loss, checked and expanded to a run's simulations. read_ylt()
reads a CSV or Parquet file (Parquet needs the arrow package);
event_set_from_ylt() takes the columns.
Usage
read_ylt(
path,
year = "year",
loss = "value",
slot = "slot",
time = NULL,
day = NULL,
hour = NULL,
labels = NULL,
n_years = NULL,
n_sims = NULL,
expand = "tile",
seed = 0,
unique_by = NULL,
expected = NULL,
format = NULL,
losses_negative = FALSE
)
event_set_from_ylt(
years,
losses,
slots = NULL,
labels = NULL,
n_years = NULL,
n_sims = NULL,
expand = "tile",
seed = 0,
unique_by = NULL,
expected = NULL,
source_hash = NULL,
times = NULL,
losses_negative = FALSE
)Arguments
- path
The file.
- year, loss
The columns of each row's year, from 1, and its loss.
- slot
The column of each row's event slot, or
NULLto keep the file's order within a year and skip the check for repeats.- time
The column of each row's time of loss, the fraction of its year elapsed, in
[0, 1];NULLfor none. The events then carry times (event_times()), forhours_clause()and reinstatements pro rata as to time.- day, hour
Instead of
time: the columns of each row's day of the year, from 1 to 365, and hour of the day, from 0 to 24 (NULLfor the start of the day); the time is((day - 1) * 24 + hour) / 8760, on the 8,760-hour year of the hours clause.- labels
Columns kept as labels,
c("peril", "class")say, by whichapply_tower()splits its results.- n_years
The table's years, at least its largest year;
NULLfor the largest year.- n_sims
The simulations to expand to;
NULLforn_years.- expand
"tile": the simulations take the table's years in turn, son_simsmust be a multiple ofn_years."resample": each simulation takes a year drawn uniformly with replacement from its own stream ofseed.- seed
The seed of
"resample".- unique_by
With slots, the labels within which a year's slot may not repeat (
"peril": one slot may hit several classes);NULLfor every label.- expected
NULL, or a named list of the values allowed in each label (list(peril = c("WS", "EQ"))).- format
"csv"or"parquet";NULLfor Parquet when the file ends in.parquetor.pq, CSV otherwise.- losses_negative
The losses are stored as negative numbers, money going out, as some vendor and cedent files do: each must be at most 0 and is read with its sign flipped. Without it a negative loss is an error.
- years, losses, slots
Each row's year (from 1), loss and slot (
NULLfor none).- source_hash
NULL, or a hash of the source kept as the events'input_hash.- times
NULL, or each row's time of loss, a fraction of the year.
Value
An event_set.
Details
The rows are checked: losses finite and non-negative, years from 1, no two
rows with the same year, slot and values in the unique_by labels, labels
among the expected values, times within the year. They are ordered by
year, then time of loss when given, then slot, the file's order breaking
ties. Each row is one loss: rows sharing a slot, one
event hitting several classes, stay separate losses, so an occurrence
layer sees each of them. read_ylt() hashes the file's bytes into the
events' input_hash, which results keep in their provenance().
Examples
path <- tempfile(fileext = ".csv")
writeLines(c("year,peril,slot,value", "2,wind,9,5", "1,quake,1,1", "2,wind,3,7"), path)
ev <- read_ylt(path, labels = "peril", n_sims = 4)
events(ev, 2)
#> [1] 7 5
event_labels(ev, 2)
#> peril
#> 1 wind
#> 2 wind
ev@input_hash
#> [1] "blake3:a39fa0312f1bf4d952b2030229d2881784142ee17e8eacb4fd2c55478807de42"
writeLines(c("year,day,hour,value", "1,200,6,5", "1,199,12,1"), path)
timed <- read_ylt(path, slot = NULL, day = "day", hour = "hour")
events(timed, 1)
#> [1] 1 5
event_times(timed, 1)
#> [1] 0.5438356 0.5458904