View source: R/rating_to_numeric.R
rating_to_numeric | R Documentation |
This function takes a vector of bond credit ratings and returns a vector of their numeric equivalents or, optionally, a statistical summary of the translated values. The package currently supports long term credit ratings from Moody's, S&P, Fitch, Kroll, & DBRS/Morningstar. All mappings are stored in creditor:::cr_imp. Short term ratings are assigned the floor rounded value of their long term equivalents. By default, NA and unrecognized ratings are not assigned a value. This setting can be changed to assign the highest numeric value (23) to missing or unrated bonds.
rating_to_numeric(
credit_rating,
nr_as_na = TRUE,
summary_fun = NULL,
...,
summarize_numeric = FALSE
)
credit_rating |
A character vector of bond credit ratings |
summary_fun |
Function input to summarize vector |
... |
Additional arguments passed to summary_fun |
summarize_numeric |
Return a numeric summary value. Defaults to FALSE to return letter rating equivalent. |
na_as_nr |
Assign missing or unrecognized ratings highest numeric value, defaults to TRUE |
Returns a vector of numeric credit rating equivalents.
# convert bond credit ratings to numeric values
x <- c("AAA", "Baa2", "A(low)")
rating_to_numeric(x)
# summarize ratings
x <- c("AAA", "Baa2", "A(low)")
rating_to_numeric(x, summary_fun = weighted.mean, w = c(0.15, 0.60, 0.25))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.