Translating ratings¶
When working with ratings, you pretty fast come to the point where you need to do some computations, e.g. calculating the average rating of a portfolio.
In these cases, you can't simply use human-readable ratings. You first need to translate these ratings into numerical rating scores. And when you are done with your computations and want to present your results, you have to translate rating scores back into human-readable ratings.
When translating ratings into scores and vice versa, there's a difference between long-term and short-term ratings and pyratings actually uses different translation tables.
Ratings vs. numerical scores¶
pyratings provides a number of functions that help to translate ratings into scores and vice versa. The respective API Reference holds a number of concrete examples of how to apply these functions.
get_scores_from_ratings
: Convert regular ratings into numerical rating scores.get_ratings_from_scores
: Convert numerical rating scores into regular ratings.
For example, we can convert ratings_df
into scores as follows:
import pandas as pd
import numpy as np
import pyratings as rtg
ratings_df = pd.DataFrame(
data=(
{
"rating_S&P": ['AAA', 'AA-', 'AA+', 'BB-', 'C'],
"rating_Moody's": ['Aa1', 'Aa3', 'Aa2', 'Ba3', 'Ca'],
"rating_Fitch": ['AA-', 'AA-', 'AA-', 'B+', 'C'],
}
),
index=[f'security_{i}' for i in range(5)]
)
ratings_df
rating_S&P | rating_Moody's | rating_Fitch | |
---|---|---|---|
security_0 | AAA | Aa1 | AA- |
security_1 | AA- | Aa3 | AA- |
security_2 | AA+ | Aa2 | AA- |
security_3 | BB- | Ba3 | B+ |
security_4 | C | Ca | C |
scores_df = rtg.get_scores_from_ratings(
ratings=ratings_df,
rating_provider=["SP", "Moody", "Fitch"]
)
scores_df
rtg_score_rating_S&P | rtg_score_rating_Moody's | rtg_score_rating_Fitch | |
---|---|---|---|
security_0 | 1 | 2 | 4 |
security_1 | 4 | 4 | 4 |
security_2 | 2 | 3 | 4 |
security_3 | 13 | 13 | 14 |
security_4 | 21 | 20 | 21 |
Converting the numerical scores back into human-readable ratings is as easy as:
rtg.get_ratings_from_scores(
rating_scores=scores_df,
rating_provider=["SP", "Moody", "Fitch"]
)
rtg_SP | rtg_Moody | rtg_Fitch | |
---|---|---|---|
security_0 | AAA | Aa1 | AA- |
security_1 | AA- | Aa3 | AA- |
security_2 | AA+ | Aa2 | AA- |
security_3 | BB- | Ba3 | B+ |
security_4 | C | Ca | C |
Ratings vs. WARF¶
pyratings also offers the possibility to translate ratings (or even rating scores) into WARF's and vice versa. Again, take a look at the individual function's references and study the examples.
get_warf_from_ratings
: Convert regular rating(s) to numerical WARF(s).get_ratings_from_warf
: Convert WARFs into regular ratings.
For example, we can convert ratings_df
into WARFs as follows:
rtg.get_warf_from_ratings(ratings=ratings_df)
warf_rating_S&P | warf_rating_Moody's | warf_rating_Fitch | |
---|---|---|---|
security_0 | 1 | 10 | 40 |
security_1 | 40 | 40 | 40 |
security_2 | 10 | 20 | 40 |
security_3 | 1766 | 1766 | 2220 |
security_4 | 9999 | 9998 | 9999 |
Again, when not specifying rating_provider
, pyratings tries to extract the
appropriate rating provider automatically.