Skip to content

Commit ac3051a

Browse files
committed
corrected annuity time of death and made it so annuity payments are propostional to the length of t
1 parent e3599d5 commit ac3051a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

R/rpv.R

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ setGeneric("rpv",
2525
#' @examples
2626
#' rpv(object = Insuree(m_ = .5, benefit = c(1,1, 1, 1)), n = 5, benefit_type = "annuity")
2727
#' rpv(object = Insuree(x_ = 2, t_ = 3, benefit = c(1, 1, 1, 1), m_ = 0.3), n = 5)
28-
#' rpv(object = Insuree(x_ = 2.2, t_ = 3.4, benefit = c(1, 1, 1, 1), m_ = 0.3), n = 5)
28+
#' rpv(object = Insuree(x_ = 2.2, t_ = 3.4, benefit = c(1, 1, 1, 1), m_ = 0.3), n = 5, benefit_type = "annuity")
2929
#' rpv(object = Insuree(x_ = 2.48, t_ = 3.57, benefit = c(1, 1, 1, 1, 1), m_ = 0), n = 5)
3030
setMethod("rpv", signature("Insuree"), function(object, n, benefit_type = "life") {
3131

@@ -34,11 +34,13 @@ setMethod("rpv", signature("Insuree"), function(object, n, benefit_type = "life"
3434
deaths <- rdeath(object, n = n)
3535
pv <- deaths[["death_table"]]
3636

37+
# returns vector of discount factors
38+
discount <- discount(object, x_ = object@x_, t_ = object@t_, m_ = object@m_)
3739
# convert 1s to 0s if annuity
3840
if (identical(benefit_type, "annuity")) {
3941
# set insuree time of death to t_ + m_ if insuree did not die
4042
tod <- deaths[["death_t"]]
41-
tod[is.na(tod)] <- object@t_ + object@m_
43+
tod[is.na(tod)] <- ceiling(object@x_ %% 1 + object@t_ + object@m_) + 1
4244

4345
# change death_table to 1s for years insuree survives
4446
for (j in seq_along(tod)) {
@@ -52,14 +54,21 @@ setMethod("rpv", signature("Insuree"), function(object, n, benefit_type = "life"
5254
# set all deaths in deferral period equal to 0
5355
pv[1:ceiling((object@x_ %% 1) + object@m_), ] <- 0
5456
# set all deaths in term period equal to the applicable benefit value
55-
pv[ceiling((object@x_ %% 1) + object@m_ + 1):nrow(pv), ] <-
56-
pv[ceiling((object@x_ %% 1) + object@m_ + 1):nrow(pv), ] * object@benefit
57+
if (benefit_type == "life") {
58+
pv[ceiling((object@x_ %% 1) + object@m_ + 1):nrow(pv), ] <-
59+
pv[ceiling((object@x_ %% 1) + object@m_ + 1):nrow(pv), ] * object@benefit
60+
} else {
61+
# for annuities we only pay the portion of the annuity equal
62+
# to the portion of the year in the term
63+
pv[ceiling((object@x_ %% 1) + object@m_ + 1):nrow(pv), ] <-
64+
pv[ceiling((object@x_ %% 1) + object@m_ + 1):nrow(pv), ] *
65+
object@benefit * deaths$t[ceiling((object@x_ %% 1) + object@m_ + 1):nrow(pv)]
66+
}
5767
} else {
5868
pv <- pv * object@benefit
5969
}
6070

61-
# returns vector of discount factors
62-
discount <- discount(object, x_ = object@x_, t_ = object@t_, m_ = object@m_)
71+
6372
pv <- apply(pv, 2, function(j) j * discount)
6473
list(deaths,
6574
discount = discount,

0 commit comments

Comments
 (0)