migrate
This package is intended to serve as a set of tools to help convert credit risk data at two time points into traditional credit state migration (aka, “transition”) matrices. At a higher level, migrate
is intended to help an analyst understand how risk moved in their credit portfolio over a time interval.
One of the more difficult aspects of making a credit state migration matrix in R (or Python, for that matter) is the fact that the output doesn’t satisfy the structure of a traditional data frame object. Rather, the output needs to be a matrix, which is a data structure that R does support. In the past, there has been difficulty converting a matrix to something more visual-friendly. More recently, however, tools like the kableExtra and gt packages allow us to present visually appealing output that extends the structure of a data frame. Using the matrix-style output of migrate
’s functions with a visual formatting package such as the two mentioned above will hopefully help analysts streamline the presentation of their credit portfolio’s state migration matrices to an audience.
If you haven’t done so already, first install migrate
with the instructions in the README section.
First, load the package & the mock dataset (as a data frame) using library()
We can get a look at the data using dplyr::glimpse()
Note that an important feature of the dataset is that there are exactly two (2) unique values in the date
column variable
To summarize the migration within the data, use the migrate()
function
migrated_df <- migrate(
data = mock_credit,
date = date,
rating = risk_rating,
metric = principal_balance
)
head(migrated_df)
To create the state migration matrix, use the build_matrix()
function
Or, to do it all in one shot, use the %>%