pyratings


Namepyratings JSON
Version 0.6.0 PyPI version JSON
download
home_page
SummaryWorking with credit ratings, professionally and efficiently
upload_time2023-01-18 12:03:02
maintainer
docs_urlNone
author
requires_python>=3.9
license
keywords ratings credit ratings rating scores
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyratings — Working with credit ratings, professionally and efficiently
  
![img](https://img.shields.io/pypi/v/pyratings) ![img](https://img.shields.io/pypi/pyversions/pyratings) ![img](https://img.shields.io/github/license/hsbc/pyratings) ![img](https://img.shields.io/github/issues/hsbc/pyratings) ![img](https://img.shields.io/github/stars/hsbc/pyratings) ![img](https://img.shields.io/badge/code%20style-black-black)

**Documentation**: [https://hsbc.github.io/pyratings/](https://hsbc.github.io/pyratings/)

**Source Code**: [https://github.com/hsbc/pyratings/](https://github.com/hsbc/pyratings/)

---

## What is it all about?
Do you work in the investment industry?
Do you work with fixed income instruments, such as bonds and credit securities?
Then you are probably concerned with credit ratings, too?

This Python library will be useful for portfolio managers, credit analysts, as well 
as anybody who is working with credit ratings.
It provides functions, which will be helpful in order to work with ratings in 
a professional and efficient way.

## Table of contents
- [What has _pyratings_ to offer and how might it help you?](#what-has-pyratings-to-offer-and-how-might-it-help-you)
- [How to install _pyratings_?](#how-to-install-pyratings)
- [Getting started with _pyratings_](#getting-started-with-pyratings)
    - [Cleaning ratings](#cleaning-ratings)
    - [Consolidating ratings](#consolidating-ratings)
    - [Translating ratings](#translating-ratings)
- [Support](#support)
- [Contributing](#contributing)
- [Acknowlegdements](#acknowledgements)
- [License](#license)


## What has _pyratings_ to offer and how might it help you?
Do you need to compute the average credit rating of an investment portfolio?
Do you need to compute the worst rating for individual securities', given these 
securities have ratings attached from more than one rating agency?
Do you need to compute the Weighted Average Rating Factor (WARF)?

If yes, you might want to take a look at **pyratings** and its offerings in the credit 
ratings space.

**pyratings** offers the following capabilities:

- Cleaning ratings for further processing, e.g. stripping off of rating watches.
- Transform long- and short-term ratings into rating scores and vice versa.
- Compute the best/second best/worst ratings on a security level basis within a
  portfolio context.
- Compute average ratings/rating scores on a portfolio level.
- Compute Weighted Average Rating Factor (WARF) on a portfolio level.
- Compute WARF buffer, i.e. distance from current WARF to the next maxWARF.

**pyratings** supports 
[long-term ratings](https://hsbc.github.io/pyratings/long_term_ratings) as well as 
[short-term ratings](https://hsbc.github.io/pyratings/short_term_ratings).
Currently, the following rating agencies will be supported:

- Moody's (long-term / short-term)
- Standard & Poors (long-term / short-term)
- Fitch (long-term / short-term)
- DBRS Morningstar (long-term / short-term)
- Bloomberg (long-term)


## How to install _pyratings_?
**pyratings** is listed on [pypi](https://pypi.org/project/pyratings/).
Make sure to have Python 3.9+ installed on your machine.

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install **pyratings**.

```bash
pip install pyratings
```

You can also use [poetry](https://python-poetry.org/).

```bash
poetry add pyratings
```

## Getting started with _pyratings_
Here are some very basic code snippets to get you up and running.

### Cleaning ratings
Sometimes, a rating has a credit watch or an outlook attached to it.
In order to work with this rating, it is usually necessary to get rid of it.

```bash
>>> import pyratings as rtg

>>> rtg.get_pure_ratings("AA- *+")
"AA-"
```
Cleaning a pandas datraframe, which comprises several securities with ratings from S&P 
and Fitch:

```bash
>>> import numpy as np
>>> import pandas as pd

>>> import pyratings as rtg


>>> rtg_df = pd.DataFrame(
...    data={
...        "rtg_SP": [
...            "BB+ *-",
...            "BBB *+",
...            np.nan,
...            "AA- (Developing)",
...            np.nan,
...            "CCC+ (CwPositive)",
...            "BB+u",
...        ],
...        "rtg_Fitch": [
...            "BB+ *-",
...            "BBB *+",
...            np.nan,
...            "AA- (Developing)",
...            np.nan,
...            "CCC+ (CwPositive)",
...            "BB+u",
...        ],
...    },
... )
  
>>> rtg_df
              rtg_SP          rtg_Fitch
0             BB+ *-             BB+ *-
1             BBB *+             BBB *+
2                NaN                NaN
3   AA- (Developing)   AA- (Developing)
4                NaN                NaN
5  CCC+ (CwPositive)  CCC+ (CwPositive)
6               BB+u               BB+u

# Get rid of all the noise.

>>> rtg.get_pure_ratings(rtg_df)
  rtg_SP_clean rtg_Fitch_clean
0          BB+             BB+
1          BBB             BBB
2          NaN             NaN
3          AA-             AA-
4          NaN             NaN
5         CCC+            CCC+
6          BB+             BB+
```

### Consolidating ratings
It is quite common that an individual credit security has been rated by several 
credit agencies.
In this case, you may want to compute the best or worst rating. 

```bash
>>> import pandas as pd

>>> import pyratings as rtg

>>> ratings_df = pd.DataFrame(
...     data=(
...         {
...             "rating_S&P": ['AAA', 'AA-', 'AA+', 'BB-', 'C'],
...             "rating_Moody": ['Aa1', 'Aa3', 'Aa2', 'Ba3', 'Ca'],
...             "rating_Fitch": ['AA-', 'AA-', 'AA-', 'B+', 'C'],
...         }
...     )
... )
  
>>>  ratings_df
  rating_S&P rating_Moody rating_Fitch
0        AAA          Aa1          AA-
1        AA-          Aa3          AA-
2        AA+          Aa2          AA-
3        BB-          Ba3           B+
4          C           Ca            C

# Return a pd.Series with the worst ratings.

>>> rtg.get_worst_ratings(
...   ratings_df, rating_provider_input=["S&P", "Moody", "Fitch"]
... )
0    AA-
1    AA-
2    AA-
3     B+
4      C
Name: worst_rtg, dtype: object
```

### Translating ratings
To work with ratings, it's sometimes necessary to translate human-readable ratings 
into numerical rating scores and vice versa.
**pyratings** offers a number of functions on that front.

The [documentation](https://hsbc.github.io/pyratings/user_guide/translation) shows 
in detail how **pyratings** translates human-readable ratings into numerical rating 
scores.<br>
Here's an example how to translate a pandas series from ratings to scores and vice 
versa. 

```bash
>>> import pandas as pd

>>> import pyratings as rtg


>>> ratings_series = pd.Series(
...     data=["Baa1", "C", "NR", "WD", "D", "B1", "SD"], name='Moody'
... )
>>> scores_series = rtg.get_scores_from_ratings(
...     ratings=ratings_series, rating_provider="Moody's", tenor="long-term"
... )
>>> scores_series
0     8.0
1    21.0
2     NaN
3     NaN
4    22.0
5    14.0
6    22.0
Name: rtg_score_Moody, dtype: float64

# Translate these rating scores back, but this time use DBRS' rating scale

>>> rtg.get_ratings_from_scores(
...     rating_scores=scores_series, rating_provider="DBRS", tenor="long-term"
... )
0    BBBH
1       C
2     NaN
3     NaN
4       D
5      BH
6       D
Name: rtg_DBRS, dtype: object
```


## Support
If you need help or have any questions, the first step should be to take a look at the 
[docs](https://hsbc.github.io/pyratings/).
If you can't find an answer, please open an issue on 
[GitHub](https://github.com/hsbc/pyratings//issues/new), or send an email to 
<opensource@hsbc.de>.
The subject line should contain '#pyratings'


## Contributing
We very much welcome contributions!
Before you begin, please read our 
[contributing guideliens](https://hsbc.github.io/pyratings/contributing/).


## Acknowledgements
Thanks to

- [Andreas Vester](https://github.com/a-vester), project creator and lead developer
- [Deepak Parashar](https://github.com/deepakparashar1987), for their help with 
  testing the code and working on all kinds of PRs.
- [Sander Cohen](https://github.com/sander2825), for their help to improve the 
  documentation as well as the intense discussion on how to best implement 
  short-term ratings into the project.
- [Marco Erling](https://github.com/MarcoGER), for actively participating in 
  discussions on how to best incorporate short-term ratings.
- [Thomas Steenbergen](https://github.com/tsteenbe), for their
  [code contribution](https://github.com/hsbc/pyratings/pull/1) regarding the 
  improvement of metadata in setup.py.
- [Ekow Folson](https://github.com/MEFolson), for their help of setting up this 
  repository and make it possible to become the very first open source contribution 
  from [HSBC](https://github.com/hsbc).


## License
This project is licensed under the Apache 2.0 License – please see the
[LICENSE](https://hsbc.github.io/pyratings/license) file.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pyratings",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "ratings,credit ratings,rating scores",
    "author": "",
    "author_email": "HSBC <opensource@hsbc.com>",
    "download_url": "https://files.pythonhosted.org/packages/46/c5/2df5d695cf9cb85fb53d75a099b0ad251e6a881543e105165f78bc41b1a8/pyratings-0.6.0.tar.gz",
    "platform": null,
    "description": "# pyratings \u2014 Working with credit ratings, professionally and efficiently\n  \n![img](https://img.shields.io/pypi/v/pyratings) ![img](https://img.shields.io/pypi/pyversions/pyratings) ![img](https://img.shields.io/github/license/hsbc/pyratings) ![img](https://img.shields.io/github/issues/hsbc/pyratings) ![img](https://img.shields.io/github/stars/hsbc/pyratings) ![img](https://img.shields.io/badge/code%20style-black-black)\n\n**Documentation**: [https://hsbc.github.io/pyratings/](https://hsbc.github.io/pyratings/)\n\n**Source Code**: [https://github.com/hsbc/pyratings/](https://github.com/hsbc/pyratings/)\n\n---\n\n## What is it all about?\nDo you work in the investment industry?\nDo you work with fixed income instruments, such as bonds and credit securities?\nThen you are probably concerned with credit ratings, too?\n\nThis Python library will be useful for portfolio managers, credit analysts, as well \nas anybody who is working with credit ratings.\nIt provides functions, which will be helpful in order to work with ratings in \na professional and efficient way.\n\n## Table of contents\n- [What has _pyratings_ to offer and how might it help you?](#what-has-pyratings-to-offer-and-how-might-it-help-you)\n- [How to install _pyratings_?](#how-to-install-pyratings)\n- [Getting started with _pyratings_](#getting-started-with-pyratings)\n    - [Cleaning ratings](#cleaning-ratings)\n    - [Consolidating ratings](#consolidating-ratings)\n    - [Translating ratings](#translating-ratings)\n- [Support](#support)\n- [Contributing](#contributing)\n- [Acknowlegdements](#acknowledgements)\n- [License](#license)\n\n\n## What has _pyratings_ to offer and how might it help you?\nDo you need to compute the average credit rating of an investment portfolio?\nDo you need to compute the worst rating for individual securities', given these \nsecurities have ratings attached from more than one rating agency?\nDo you need to compute the Weighted Average Rating Factor (WARF)?\n\nIf yes, you might want to take a look at **pyratings** and its offerings in the credit \nratings space.\n\n**pyratings** offers the following capabilities:\n\n- Cleaning ratings for further processing, e.g. stripping off of rating watches.\n- Transform long- and short-term ratings into rating scores and vice versa.\n- Compute the best/second best/worst ratings on a security level basis within a\n  portfolio context.\n- Compute average ratings/rating scores on a portfolio level.\n- Compute Weighted Average Rating Factor (WARF) on a portfolio level.\n- Compute WARF buffer, i.e. distance from current WARF to the next maxWARF.\n\n**pyratings** supports \n[long-term ratings](https://hsbc.github.io/pyratings/long_term_ratings) as well as \n[short-term ratings](https://hsbc.github.io/pyratings/short_term_ratings).\nCurrently, the following rating agencies will be supported:\n\n- Moody's (long-term / short-term)\n- Standard & Poors (long-term / short-term)\n- Fitch (long-term / short-term)\n- DBRS Morningstar (long-term / short-term)\n- Bloomberg (long-term)\n\n\n## How to install _pyratings_?\n**pyratings** is listed on [pypi](https://pypi.org/project/pyratings/).\nMake sure to have Python 3.9+ installed on your machine.\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install **pyratings**.\n\n```bash\npip install pyratings\n```\n\nYou can also use [poetry](https://python-poetry.org/).\n\n```bash\npoetry add pyratings\n```\n\n## Getting started with _pyratings_\nHere are some very basic code snippets to get you up and running.\n\n### Cleaning ratings\nSometimes, a rating has a credit watch or an outlook attached to it.\nIn order to work with this rating, it is usually necessary to get rid of it.\n\n```bash\n>>> import pyratings as rtg\n\n>>> rtg.get_pure_ratings(\"AA- *+\")\n\"AA-\"\n```\nCleaning a pandas datraframe, which comprises several securities with ratings from S&P \nand Fitch:\n\n```bash\n>>> import numpy as np\n>>> import pandas as pd\n\n>>> import pyratings as rtg\n\n\n>>> rtg_df = pd.DataFrame(\n...    data={\n...        \"rtg_SP\": [\n...            \"BB+ *-\",\n...            \"BBB *+\",\n...            np.nan,\n...            \"AA- (Developing)\",\n...            np.nan,\n...            \"CCC+ (CwPositive)\",\n...            \"BB+u\",\n...        ],\n...        \"rtg_Fitch\": [\n...            \"BB+ *-\",\n...            \"BBB *+\",\n...            np.nan,\n...            \"AA- (Developing)\",\n...            np.nan,\n...            \"CCC+ (CwPositive)\",\n...            \"BB+u\",\n...        ],\n...    },\n... )\n  \n>>> rtg_df\n              rtg_SP          rtg_Fitch\n0             BB+ *-             BB+ *-\n1             BBB *+             BBB *+\n2                NaN                NaN\n3   AA- (Developing)   AA- (Developing)\n4                NaN                NaN\n5  CCC+ (CwPositive)  CCC+ (CwPositive)\n6               BB+u               BB+u\n\n# Get rid of all the noise.\n\n>>> rtg.get_pure_ratings(rtg_df)\n  rtg_SP_clean rtg_Fitch_clean\n0          BB+             BB+\n1          BBB             BBB\n2          NaN             NaN\n3          AA-             AA-\n4          NaN             NaN\n5         CCC+            CCC+\n6          BB+             BB+\n```\n\n### Consolidating ratings\nIt is quite common that an individual credit security has been rated by several \ncredit agencies.\nIn this case, you may want to compute the best or worst rating. \n\n```bash\n>>> import pandas as pd\n\n>>> import pyratings as rtg\n\n>>> ratings_df = pd.DataFrame(\n...     data=(\n...         {\n...             \"rating_S&P\": ['AAA', 'AA-', 'AA+', 'BB-', 'C'],\n...             \"rating_Moody\": ['Aa1', 'Aa3', 'Aa2', 'Ba3', 'Ca'],\n...             \"rating_Fitch\": ['AA-', 'AA-', 'AA-', 'B+', 'C'],\n...         }\n...     )\n... )\n  \n>>>  ratings_df\n  rating_S&P rating_Moody rating_Fitch\n0        AAA          Aa1          AA-\n1        AA-          Aa3          AA-\n2        AA+          Aa2          AA-\n3        BB-          Ba3           B+\n4          C           Ca            C\n\n# Return a pd.Series with the worst ratings.\n\n>>> rtg.get_worst_ratings(\n...   ratings_df, rating_provider_input=[\"S&P\", \"Moody\", \"Fitch\"]\n... )\n0    AA-\n1    AA-\n2    AA-\n3     B+\n4      C\nName: worst_rtg, dtype: object\n```\n\n### Translating ratings\nTo work with ratings, it's sometimes necessary to translate human-readable ratings \ninto numerical rating scores and vice versa.\n**pyratings** offers a number of functions on that front.\n\nThe [documentation](https://hsbc.github.io/pyratings/user_guide/translation) shows \nin detail how **pyratings** translates human-readable ratings into numerical rating \nscores.<br>\nHere's an example how to translate a pandas series from ratings to scores and vice \nversa. \n\n```bash\n>>> import pandas as pd\n\n>>> import pyratings as rtg\n\n\n>>> ratings_series = pd.Series(\n...     data=[\"Baa1\", \"C\", \"NR\", \"WD\", \"D\", \"B1\", \"SD\"], name='Moody'\n... )\n>>> scores_series = rtg.get_scores_from_ratings(\n...     ratings=ratings_series, rating_provider=\"Moody's\", tenor=\"long-term\"\n... )\n>>> scores_series\n0     8.0\n1    21.0\n2     NaN\n3     NaN\n4    22.0\n5    14.0\n6    22.0\nName: rtg_score_Moody, dtype: float64\n\n# Translate these rating scores back, but this time use DBRS' rating scale\n\n>>> rtg.get_ratings_from_scores(\n...     rating_scores=scores_series, rating_provider=\"DBRS\", tenor=\"long-term\"\n... )\n0    BBBH\n1       C\n2     NaN\n3     NaN\n4       D\n5      BH\n6       D\nName: rtg_DBRS, dtype: object\n```\n\n\n## Support\nIf you need help or have any questions, the first step should be to take a look at the \n[docs](https://hsbc.github.io/pyratings/).\nIf you can't find an answer, please open an issue on \n[GitHub](https://github.com/hsbc/pyratings//issues/new), or send an email to \n<opensource@hsbc.de>.\nThe subject line should contain '#pyratings'\n\n\n## Contributing\nWe very much welcome contributions!\nBefore you begin, please read our \n[contributing guideliens](https://hsbc.github.io/pyratings/contributing/).\n\n\n## Acknowledgements\nThanks to\n\n- [Andreas Vester](https://github.com/a-vester), project creator and lead developer\n- [Deepak Parashar](https://github.com/deepakparashar1987), for their help with \n  testing the code and working on all kinds of PRs.\n- [Sander Cohen](https://github.com/sander2825), for their help to improve the \n  documentation as well as the intense discussion on how to best implement \n  short-term ratings into the project.\n- [Marco Erling](https://github.com/MarcoGER), for actively participating in \n  discussions on how to best incorporate short-term ratings.\n- [Thomas Steenbergen](https://github.com/tsteenbe), for their\n  [code contribution](https://github.com/hsbc/pyratings/pull/1) regarding the \n  improvement of metadata in setup.py.\n- [Ekow Folson](https://github.com/MEFolson), for their help of setting up this \n  repository and make it possible to become the very first open source contribution \n  from [HSBC](https://github.com/hsbc).\n\n\n## License\nThis project is licensed under the Apache 2.0 License \u2013 please see the\n[LICENSE](https://hsbc.github.io/pyratings/license) file.\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Working with credit ratings, professionally and efficiently",
    "version": "0.6.0",
    "split_keywords": [
        "ratings",
        "credit ratings",
        "rating scores"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "36d430265ac989c1652e0299d4b758eb39de5693375e635b2ad22a2e638ef602",
                "md5": "149ffbce5bc573ed9a7c75023e9816e8",
                "sha256": "1fe9153262270e102aac09cbb34170151ff406c11a97ba2690e686b0bbb450d0"
            },
            "downloads": -1,
            "filename": "pyratings-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "149ffbce5bc573ed9a7c75023e9816e8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 39491,
            "upload_time": "2023-01-18T12:03:00",
            "upload_time_iso_8601": "2023-01-18T12:03:00.821281Z",
            "url": "https://files.pythonhosted.org/packages/36/d4/30265ac989c1652e0299d4b758eb39de5693375e635b2ad22a2e638ef602/pyratings-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46c52df5d695cf9cb85fb53d75a099b0ad251e6a881543e105165f78bc41b1a8",
                "md5": "25868596b5cca1914974deaf2af7f510",
                "sha256": "371a228a61e21b7ed5cbce7fe798b07609cdcd836dc23237519c4c71623502d7"
            },
            "downloads": -1,
            "filename": "pyratings-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "25868596b5cca1914974deaf2af7f510",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 34993,
            "upload_time": "2023-01-18T12:03:02",
            "upload_time_iso_8601": "2023-01-18T12:03:02.547626Z",
            "url": "https://files.pythonhosted.org/packages/46/c5/2df5d695cf9cb85fb53d75a099b0ad251e6a881543e105165f78bc41b1a8/pyratings-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-18 12:03:02",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "pyratings"
}
        
Elapsed time: 0.02980s