-
Notifications
You must be signed in to change notification settings - Fork 2
/
cascsim.R
161 lines (139 loc) · 3.45 KB
/
cascsim.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
library(cascsim)
tab_cascsim <- tabPanel(
'cascsim',
fluidRow(
column(
width = 3,
numericInput(
"num_severity_mean",
"Set the severity mean",
min = .01,
step = 5,
value = 10e3
),
numericInput(
"num_severity_cv",
"Set the severity cv",
min = .01,
step = 5,
value = 1.5
),
numericInput(
"num_frequency_mean",
"Set the frequency mean",
min = .01,
step = 5,
value = 10
),
# numericInput(
# "num_frequency_cv",
# "Set the frequency cv",
# min = .01,
# step = 5,
# value = 0.75
# ),
numericInput(
"num_sims_cascsim",
"How many simulations would you like?",
min = 1,
step = 5,
value = 5
)
),
column(
width = 9,
h1("Cascsim data"),
downloadButton('download_cascsim_data', 'Download cascsim data'),
dataTableOutput("tbl_cascsim")
)
)
)
expr_cascsim <- quote({
tbl_cascsim <- reactiveVal(NULL)
start_date <- lubridate::make_date(2000, 1, 1)
obj_claim_type <- new(
"ClaimType",
line = "General Liability",
claimType = "Bodily injury"
)
obj_claim_type@exposureIndex <- setIndex(
new(
"Index",
indexID = "Exposue",
tabulate = FALSE,
startDate = start_date,
annualizedRate = 0)
)
obj_claim_type@severityIndex <- setIndex(
new(
"Index",
indexID = "Severity index",
tabulate = FALSE,
startDate = start_date,
annualizedRate = 0.02)
)
obj_claim_type@p0 <- new(
"DevFac",
meanList = c(0, 0),
volList = c(0, 0)
)
obj_claim_type@reportLag <- new("Exponential", p1 = 0.1)
obj_claim_type@settlementLag <- new("Exponential", p1 = 0.05)
obj_claim_type@iCopula <- FALSE
obj_claim_type@laeDevFac <- new(
"DevFac",
FacID = "F1",
FacModel = TRUE,
fun = "linear",
paras = c(5, 1.5, 0.005, 1.2, 3)
)
obj_claim_type@fIBNER <- new(
"DevFac",
FacID = "D1",
FacModel = FALSE,
meanList = c(1.2, 1.15, 1.1, 1.05, 1),
volList = c(0, 0, 0, 0, 0)
)
observe({
lognormal_sigma <- sqrt(log(input$num_severity_cv^2 + 1))
lognormal_mu <- log(input$num_severity_mean) - lognormal_sigma^2/2
obj_claim_type@frequency <- new("Poisson", p1 = input$num_frequency_mean)
obj_claim_type@severity <- new("Lognormal", p1 = lognormal_mu, p2 = lognormal_sigma)
obj_simulation <- new(
"Simulation",
lines = "General Liability",
types = "Bodily injury",
claimobjs = list(obj_claim_type),
workingFolder = tempdir()
)
obj_simulation@simNo <- input$num_sims_cascsim
obj_simulation@iRBNER <-FALSE
obj_simulation@iROPEN <-FALSE
obj_simulation@iIBNR <-TRUE
obj_simulation@iUPR <-FALSE
tbl_cascsim(
claimSimulation(
obj_simulation,
data.frame(),
startDate = start_date,
evaluationDate = as.Date("2004-12-31"),
futureDate = as.Date("2005-12-31")
)
)
output$download_cascsim_data <- downloadHandler(
filename = function() {
paste0('cascsim-data-', Sys.Date(), '.csv')
},
content = function(con) {
write_csv(tbl_cascsim(), con)
},
contentType = 'text/csv'
)
})
output$tbl_cascsim <- renderDataTable(
tbl_cascsim(),
options = list(
filter = 'top'
)
)
})