Skip to content

Commit 5c21740

Browse files
committed
refactor: reuse more
1 parent fef7e53 commit 5c21740

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

R/yield-curve.R

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,27 @@ tr_curve_rates <- function(x = c("hqm", "tnc", "trc", "tbi"),
7171
do.call(rbind, res)
7272
}
7373

74-
tr_hqm_pars <- function(x = c("monthly", "end-of-month")) {
75-
x <- match.arg(x)
76-
x <- if (x == "monthly") "hqm_qh_pars" else "hqmeom_qh_pars"
77-
nms <- c("yearmonth", "tmp", "2 years", "5 years", "10 years", "30 years")
78-
download_data(x, nms, 6L, "maturity", "par_yield")
79-
}
80-
81-
tr_par_yield <- function(x = c("tnc", "trc"), type = c("monthly", "end-of-month")) {
74+
tr_par_yield <- function(x = c("hqm", "tnc", "trc"),
75+
type = c("monthly", "end-of-month")) {
8276
x <- match.arg(x)
8377
type <- match.arg(type)
8478

79+
if (x == "hqm") {
80+
nms <- c("yearmonth", "tmp", "2 years", "5 years", "10 years", "30 years")
81+
} else {
82+
nms <- c(
83+
"yearmonth", "tmp", "2 years", "3 years", "5 years", "7 years", "10 years",
84+
"20 years", "30 years"
85+
)
86+
}
87+
8588
if (type == "monthly") {
8689
sfx <- if (x == "tnc") "_qh_pars_1" else "_qh_pars"
8790
} else {
8891
sfx <- "eom_qh_pars"
8992
}
9093
x <- paste0(x, sfx)
9194

92-
nms <- c(
93-
"yearmonth", "tmp", "2 years", "3 years", "5 years", "7 years", "10 years",
94-
"20 years", "30 years"
95-
)
9695
download_data(x, nms, 6L, "maturity", "par_yield")
9796
}
9897

0 commit comments

Comments
 (0)