Skip to content

Commit

Permalink
refactor: change back to 4.1 since a lot of people seem to be still u…
Browse files Browse the repository at this point in the history
…sing it
  • Loading branch information
m-muecke committed Jun 13, 2024
1 parent da3451c commit 9c44fb4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ URL: https://m-muecke.github.io/treasury/,
https://github.com/m-muecke/treasury
BugReports: https://github.com/m-muecke/treasury/issues
Depends:
R (>= 4.2.0)
R (>= 4.1.0)
Imports:
httr2,
readxl,
Expand Down
37 changes: 16 additions & 21 deletions R/interest-rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ parse_yield_curve <- function(x) {

clean_yield_curve <- function(data) {
data <- data[data$maturity != "BC_30YEARDISPLAY", ]
data$maturity <- data$maturity |>
tolower() |>
gsub("bc_", "", x = _, fixed = TRUE) |>
gsub("(\\d+)(\\w+)", "\\1 \\2", x = _)
data$maturity <- tolower(data$maturity)
data$maturity <- gsub("bc_", "", data$maturity, fixed = TRUE)
data$maturity <- gsub("(\\d+)(\\w+)", "\\1 \\2", data$maturity)
data
}

Expand Down Expand Up @@ -103,15 +102,13 @@ parse_bill_rates <- function(x) {
}

clean_bill_rates <- function(data) {
data$type <- data$type |>
tolower() |>
gsub("round_b1_", "", x = _, fixed = TRUE) |>
gsub("_2$", "", x = _)
data$type <- tolower(data$type)
data$type <- gsub("round_b1_", "", data$maturity, fixed = TRUE)
data$type <- gsub("_2$", "", data$maturity)
maturity <- strsplit(data$type, "_", fixed = TRUE)
data$type <- vapply(maturity, "[[", NA_character_, 1L)
data$maturity <- maturity |>
vapply("[[", NA_character_, 2L) |>
gsub("wk", " weeks", x = _, fixed = TRUE)
data$type <- vapply(maturity, `[[`, NA_character_, 1L)
maturity <- vapply(maturity, `[[`, NA_character_, 2L)
data$maturity <- gsub("wk", " weeks", maturity, fixed = TRUE)
data[c("date", "type", "maturity", "value")]
}

Expand Down Expand Up @@ -159,11 +156,10 @@ parse_long_term_rate <- function(x) {
}

clean_long_term_rate <- function(data) {
data$rate_type <- data$rate_type |>
tolower() |>
gsub("^bc_", "", x = _) |>
gsub("_", " ", x = _, fixed = TRUE) |>
gsub("(\\d+)(year?)", "\\1 \\2", x = _)
data$rate_type <- tolower(data$rate_type)
data$rate_type <- gsub("^bc_", "", data$rate_type)
data$rate_type <- gsub("_", " ", data$rate_type, fixed = TRUE)
data$rate_type <- gsub("(\\d+)(year?)", "\\1 \\2", data$rate_type)
data
}

Expand Down Expand Up @@ -213,10 +209,9 @@ parse_real_yield_curve <- function(x) {
}

clean_real_yield_curves <- function(data) {
data$maturity <- data$maturity |>
tolower() |>
gsub("tc_", "", x = _, fixed = TRUE) |>
gsub("(\\d+)(\\w+)", "\\1 \\2", x = _)
data$maturity <- tolower(data$maturity)
data$maturity <- gsub("tc_", "", data$maturity, fixed = TRUE)
data$maturity <- gsub("(\\d+)(\\w+)", "\\1 \\2", data$maturity)
data
}

Expand Down

0 comments on commit 9c44fb4

Please sign in to comment.