Name | PYield JSON |
Version |
0.25.4
JSON |
| download |
home_page | None |
Summary | A Python library for analysis of fixed income instruments in Brazil |
upload_time | 2024-12-13 21:37:36 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.12 |
license | MIT License Copyright (c) 2023 Carlos Carvalho Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
fixed-income
brazil
finance
analysis
bonds
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[![PyPI version](https://img.shields.io/pypi/v/pyield.svg)](https://pypi.python.org/pypi/pyield)
[![Made with Python](https://img.shields.io/badge/Python->=3.12-blue?logo=python&logoColor=white)](https://python.org "Go to Python homepage")
[![License](https://img.shields.io/badge/License-MIT-blue)](https://github.com/crdcj/PYield/blob/main/LICENSE)
# PYield: Brazilian Fixed Income Toolkit
PYield is a Python library designed for the analysis of Brazilian fixed income instruments. Leveraging the power of popular Python libraries like Pandas and Requests, PYield simplifies the process of obtaining and processing data from key sources such as ANBIMA, BCB, IBGE and B3.
Documentation: [https://crdcj.github.io/PYield/](https://crdcj.github.io/PYield/)
Source Code: [https://github.com/crdcj/PYield](https://github.com/crdcj/PYield)
## Key Features
- **Data Collection**: Automated fetching of data from ANBIMA and B3.
- **Data Processing**: Efficient processing and normalization of fixed income data.
- **Analysis Tools**: Built-in functions for common analysis tasks in fixed income markets.
- **Easy Integration**: Seamless integration with pandas data analysis workflows.
- **Type Hints**: Full support for static type checking, enhancing development experience and code quality.
## Installation
You can install PYield using pip:
```sh
pip install pyield
```
## Custom Types
### DateScalar
`DateScalar` and `DateArray` are a type alias used across PYield to represent different types of date inputs. It includes several common date formats, allowing for flexible date handling within the library.
The accepted formats in `DateScalar` are:
- `datetime.date`
- `datetime.datetime`
- `str` (in the format `DD-MM-YYYY` as used in Brazil)
- `np.datetime64`
- `pd.Timestamp`
### DateArray
The accepted formats in `DateArray` are:
- `pd.Series`
- `pd.DatetimeIndex`
- `np.ndarray`
- `list[DateScalar]`
- `tuple[DateScalar]`
Referencing `DateScalar` and `DateArray` in function arguments simplifies the code by allowing any of these date formats to be used interchangeably.
### Important Note on Date Formats
When using date strings in PYield functions, please ensure that the **date format is day-first** (e.g., "31-05-2024"). This format was chosen to be consistent with the Brazilian date convention.
For production code, it is recommended to parse date strings with `pandas.to_datetime` using an **explicit format** to avoid ambiguity and ensure consistency. For example:
```python
import pandas as pd
# Converting a date string to a pandas Timestamp with a specific format
date = pd.to_datetime("2024/31/05", format="%Y/%d/%m")
date = pd.to_datetime("05-31-2024", format="%m-%d-%Y")
```
## How to use PYield
### Brazilian Treasury Bonds Tools
```python
>>> from pyield import ntnb, ntnf, ltn
# Calculate the quotation of a NTN-B bond as per ANBIMA's rules
>>> ntnb.quotation("31-05-2024", "15-05-2035", 0.061490)
99.3651
>>> ntnb.quotation("31-05-2024", "15-08-2060", 0.061878)
99.5341
# Calculate the DI Spread of NTN-F bonds in a given date
>>> ntnf.di_spreads("17-07-2024")
2025-01-01 -2.31
2027-01-01 -1.88
2029-01-01 -3.26
2031-01-01 3.61
2033-01-01 -3.12
2035-01-01 -1.00
Name: DISpread, dtype: Float64
# Get ANBIMA's indicative rates for LTN bonds
>>> ltn.anbima_rates("17-07-2024")
2024-10-01 0.104236
2025-01-01 0.105400
2025-04-01 0.107454
2025-07-01 0.108924
2025-10-01 0.110751
2026-01-01 0.111753
2026-04-01 0.112980
2026-07-01 0.113870
2026-10-01 0.114592
2027-07-01 0.116090
2028-01-01 0.117160
2028-07-01 0.118335
2030-01-01 0.120090
Name: IndicativeRate, dtype: Float64
```
### Business Days Tools (Brazilian holidays are automatically considered)
```python
>>> from pyield import bday
# Count the number of business days between two dates
# Start date is included, end date is excluded
>>> bday.count(start='29-12-2023', end='02-01-2024')
1
# Get the next business day after a given date (offset=1)
>>> bday.offset(dates="29-12-2023", offset=1)
Timestamp('2024-01-02 00:00:00')
# Get the next business day if it is not a business day (offset=0)
>>> bday.offset(dates="30-12-2023", offset=0)
Timestamp('2024-01-02 00:00:00')
# Since 29-12-2023 is a business day, it returns the same date (offset=0)
>>> bday.offset(dates="29-12-2023", offset=0)
Timestamp('2023-12-29 00:00:00')
# Generate a pandas series with the business days between two dates
>>> bday.generate(start='29-12-2023', end='03-01-2024')
0 2023-12-29
1 2024-01-02
2 2024-01-03
dtype: datetime64[ns]
```
### Futures Data
```python
>>> import pyield as yd
# Fetch current DI Futures data from B3 (15 minutes delay)
>>> yd.futures(contract_code="DI1")
TradeTime TickerSymbol ExpirationDate BDaysToExp ... MaxRate LastAskRate LastBidRate LastRate
2024-04-21 13:37:39 DI1K24 2024-05-02 7 ... 0.10660 0.10652 0.10660 0.10660
2024-04-21 13:37:39 DI1M24 2024-06-03 28 ... 0.10518 0.10510 0.10516 0.10518
2024-04-21 13:37:39 DI1N24 2024-07-01 48 ... 0.10480 0.10456 0.10462 0.10460
... ... ... ... ... ... ... ... ...
2024-04-21 13:37:39 DI1F37 2037-01-02 3183 ... <NA> <NA> 0.11600 <NA>
2024-04-21 13:37:39 DI1F38 2038-01-04 3432 ... <NA> <NA> 0.11600 <NA>
2024-04-21 13:37:39 DI1F39 2039-01-03 3683 ... <NA> <NA> <NA> <NA>
# Fetch historical DI Futures data from B3
>>> yd.futures(contract_code="DI1", reference_date='08-03-2024')
TradeDate TickerSymbol ExpirationDate BDaysToExp ... LastRate LastAskRate LastBidRate SettlementRate
2024-03-08 DI1J24 2024-04-01 15 ... 10.952 10.952 10.956 10.956
2024-03-08 DI1K24 2024-05-02 37 ... 10.776 10.774 10.780 10.777
2024-03-08 DI1M24 2024-06-03 58 ... 10.604 10.602 10.604 10.608
... ... ... ... ... ... ... ... ...
2024-03-08 DI1F37 2037-01-02 3213 ... <NA> <NA> <NA> 10.859
2024-03-08 DI1F38 2038-01-04 3462 ... <NA> <NA> <NA> 10.859
2024-03-08 DI1F39 2039-01-03 3713 ... <NA> <NA> <NA> 10.85
```
### Indicators Data
```python
>>> import pyield as yd
# Fetch the SELIC target rate from the Central Bank of Brazil
>>> yd.indicator(indicator_code="SELIC_TARGET", reference_date='12-04-2024')
0.1075 # 10.75%
# Fetch the IPCA monthly inflation rate from IBGE
>>> yd.indicator(indicator_code="IPCA_MR", reference_date='18-03-2024')
0.0016 # 0.16%
```
### Projections Data
```python
>>> import pyield as yd
# Fetch current month projection for IPCA from IBGE API
>>> ipca = yd.projection(projection_code="IPCA_CM")
>>> print(ipca)
IndicatorProjection(
last_updated=Timestamp('2024-04-19 18:55:00'),
reference_month_ts=Timestamp('2024-04-01 00:00:00'),
reference_month_br='ABR/2024',
projected_value=0.0035 # 0.35%
)
>>> ipca.projected_value
0.0035 # 0.35%
```
### Interpolation Tools
```python
>>> from pyield import Interpolator
# Interpolate interest rates for specific business days using the Interpolator class.
# Initialize the Interpolator with known business days and interest rates.
>>> known_bdays = [30, 60, 90]
>>> known_rates = [0.045, 0.05, 0.055]
>>> linear_interpolator = Interpolator("linear", known_bdays, known_rates)
# Interpolate the interest rate for a given number of business days.
>>> linear_interpolator(45)
0.0475
# Use the flat forward method for interpolation.
>>> ff_interpolator = Interpolator("flat_forward", known_bdays, known_rates)
>>> ff_interpolator(45)
0.04833068080970859
```
Raw data
{
"_id": null,
"home_page": null,
"name": "PYield",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "fixed-income, brazil, finance, analysis, bonds",
"author": null,
"author_email": "Carlos Carvalho <cr.cj@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/a4/9c/d87c55e2c3d06a27e3992d04bf56e9e7de0c25bed903b17eba40a4dfc888/pyield-0.25.4.tar.gz",
"platform": null,
"description": "[![PyPI version](https://img.shields.io/pypi/v/pyield.svg)](https://pypi.python.org/pypi/pyield)\n[![Made with Python](https://img.shields.io/badge/Python->=3.12-blue?logo=python&logoColor=white)](https://python.org \"Go to Python homepage\")\n[![License](https://img.shields.io/badge/License-MIT-blue)](https://github.com/crdcj/PYield/blob/main/LICENSE)\n\n# PYield: Brazilian Fixed Income Toolkit\n\nPYield is a Python library designed for the analysis of Brazilian fixed income instruments. Leveraging the power of popular Python libraries like Pandas and Requests, PYield simplifies the process of obtaining and processing data from key sources such as ANBIMA, BCB, IBGE and B3.\n\nDocumentation: [https://crdcj.github.io/PYield/](https://crdcj.github.io/PYield/)\n\nSource Code: [https://github.com/crdcj/PYield](https://github.com/crdcj/PYield)\n\n## Key Features\n\n- **Data Collection**: Automated fetching of data from ANBIMA and B3.\n- **Data Processing**: Efficient processing and normalization of fixed income data.\n- **Analysis Tools**: Built-in functions for common analysis tasks in fixed income markets.\n- **Easy Integration**: Seamless integration with pandas data analysis workflows.\n- **Type Hints**: Full support for static type checking, enhancing development experience and code quality.\n\n## Installation\n\nYou can install PYield using pip:\n```sh\npip install pyield\n```\n## Custom Types\n\n### DateScalar\n`DateScalar` and `DateArray` are a type alias used across PYield to represent different types of date inputs. It includes several common date formats, allowing for flexible date handling within the library. \n\nThe accepted formats in `DateScalar` are:\n\n- `datetime.date`\n- `datetime.datetime`\n- `str` (in the format `DD-MM-YYYY` as used in Brazil)\n- `np.datetime64`\n- `pd.Timestamp`\n\n### DateArray\nThe accepted formats in `DateArray` are:\n- `pd.Series`\n- `pd.DatetimeIndex`\n- `np.ndarray`\n- `list[DateScalar]`\n- `tuple[DateScalar]`\n\nReferencing `DateScalar` and `DateArray` in function arguments simplifies the code by allowing any of these date formats to be used interchangeably.\n\n### Important Note on Date Formats\nWhen using date strings in PYield functions, please ensure that the **date format is day-first** (e.g., \"31-05-2024\"). This format was chosen to be consistent with the Brazilian date convention.\n\nFor production code, it is recommended to parse date strings with `pandas.to_datetime` using an **explicit format** to avoid ambiguity and ensure consistency. For example:\n```python\nimport pandas as pd\n# Converting a date string to a pandas Timestamp with a specific format\ndate = pd.to_datetime(\"2024/31/05\", format=\"%Y/%d/%m\")\ndate = pd.to_datetime(\"05-31-2024\", format=\"%m-%d-%Y\")\n```\n## How to use PYield\n### Brazilian Treasury Bonds Tools\n```python\n>>> from pyield import ntnb, ntnf, ltn\n\n# Calculate the quotation of a NTN-B bond as per ANBIMA's rules\n>>> ntnb.quotation(\"31-05-2024\", \"15-05-2035\", 0.061490)\n99.3651\n>>> ntnb.quotation(\"31-05-2024\", \"15-08-2060\", 0.061878)\n99.5341\n\n# Calculate the DI Spread of NTN-F bonds in a given date\n>>> ntnf.di_spreads(\"17-07-2024\")\n2025-01-01 -2.31\n2027-01-01 -1.88\n2029-01-01 -3.26\n2031-01-01 3.61\n2033-01-01 -3.12\n2035-01-01 -1.00\nName: DISpread, dtype: Float64\n\n# Get ANBIMA's indicative rates for LTN bonds\n>>> ltn.anbima_rates(\"17-07-2024\")\n2024-10-01 0.104236\n2025-01-01 0.105400\n2025-04-01 0.107454\n2025-07-01 0.108924\n2025-10-01 0.110751\n2026-01-01 0.111753\n2026-04-01 0.112980\n2026-07-01 0.113870\n2026-10-01 0.114592\n2027-07-01 0.116090\n2028-01-01 0.117160\n2028-07-01 0.118335\n2030-01-01 0.120090\nName: IndicativeRate, dtype: Float64\n```\n\n### Business Days Tools (Brazilian holidays are automatically considered)\n```python\n>>> from pyield import bday\n# Count the number of business days between two dates\n# Start date is included, end date is excluded\n>>> bday.count(start='29-12-2023', end='02-01-2024')\n1\n\n# Get the next business day after a given date (offset=1)\n>>> bday.offset(dates=\"29-12-2023\", offset=1)\nTimestamp('2024-01-02 00:00:00')\n\n# Get the next business day if it is not a business day (offset=0)\n>>> bday.offset(dates=\"30-12-2023\", offset=0)\nTimestamp('2024-01-02 00:00:00')\n\n# Since 29-12-2023 is a business day, it returns the same date (offset=0)\n>>> bday.offset(dates=\"29-12-2023\", offset=0)\nTimestamp('2023-12-29 00:00:00')\n\n# Generate a pandas series with the business days between two dates\n>>> bday.generate(start='29-12-2023', end='03-01-2024')\n0 2023-12-29\n1 2024-01-02\n2 2024-01-03\ndtype: datetime64[ns]\n```\n\n### Futures Data\n```python\n>>> import pyield as yd\n# Fetch current DI Futures data from B3 (15 minutes delay)\n>>> yd.futures(contract_code=\"DI1\")\nTradeTime TickerSymbol ExpirationDate BDaysToExp ... MaxRate LastAskRate LastBidRate LastRate\n2024-04-21 13:37:39 DI1K24 2024-05-02 7 ... 0.10660 0.10652 0.10660 0.10660\n2024-04-21 13:37:39 DI1M24 2024-06-03 28 ... 0.10518 0.10510 0.10516 0.10518\n2024-04-21 13:37:39 DI1N24 2024-07-01 48 ... 0.10480 0.10456 0.10462 0.10460\n ... ... ... ... ... ... ... ... ...\n2024-04-21 13:37:39 DI1F37 2037-01-02 3183 ... <NA> <NA> 0.11600 <NA>\n2024-04-21 13:37:39 DI1F38 2038-01-04 3432 ... <NA> <NA> 0.11600 <NA>\n2024-04-21 13:37:39 DI1F39 2039-01-03 3683 ... <NA> <NA> <NA> <NA>\n\n# Fetch historical DI Futures data from B3\n>>> yd.futures(contract_code=\"DI1\", reference_date='08-03-2024')\nTradeDate TickerSymbol ExpirationDate BDaysToExp ... LastRate LastAskRate LastBidRate SettlementRate\n2024-03-08 DI1J24 2024-04-01 15 ... 10.952 10.952 10.956 10.956\n2024-03-08 DI1K24 2024-05-02 37 ... 10.776 10.774 10.780 10.777\n2024-03-08 DI1M24 2024-06-03 58 ... 10.604 10.602 10.604 10.608\n ... ... ... ... ... ... ... ... ...\n2024-03-08 DI1F37 2037-01-02 3213 ... <NA> <NA> <NA> 10.859\n2024-03-08 DI1F38 2038-01-04 3462 ... <NA> <NA> <NA> 10.859\n2024-03-08 DI1F39 2039-01-03 3713 ... <NA> <NA> <NA> 10.85\n```\n\n### Indicators Data\n```python\n>>> import pyield as yd\n# Fetch the SELIC target rate from the Central Bank of Brazil\n>>> yd.indicator(indicator_code=\"SELIC_TARGET\", reference_date='12-04-2024')\n0.1075 # 10.75%\n\n# Fetch the IPCA monthly inflation rate from IBGE\n>>> yd.indicator(indicator_code=\"IPCA_MR\", reference_date='18-03-2024')\n0.0016 # 0.16%\n```\n\n### Projections Data\n```python\n>>> import pyield as yd\n# Fetch current month projection for IPCA from IBGE API\n>>> ipca = yd.projection(projection_code=\"IPCA_CM\")\n>>> print(ipca)\nIndicatorProjection(\n last_updated=Timestamp('2024-04-19 18:55:00'),\n reference_month_ts=Timestamp('2024-04-01 00:00:00'),\n reference_month_br='ABR/2024',\n projected_value=0.0035 # 0.35%\n)\n>>> ipca.projected_value\n0.0035 # 0.35%\n```\n\n### Interpolation Tools\n```python\n>>> from pyield import Interpolator\n# Interpolate interest rates for specific business days using the Interpolator class.\n\n# Initialize the Interpolator with known business days and interest rates.\n>>> known_bdays = [30, 60, 90]\n>>> known_rates = [0.045, 0.05, 0.055]\n>>> linear_interpolator = Interpolator(\"linear\", known_bdays, known_rates)\n\n# Interpolate the interest rate for a given number of business days.\n>>> linear_interpolator(45)\n0.0475\n\n# Use the flat forward method for interpolation.\n>>> ff_interpolator = Interpolator(\"flat_forward\", known_bdays, known_rates)\n>>> ff_interpolator(45)\n0.04833068080970859\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2023 Carlos Carvalho Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "A Python library for analysis of fixed income instruments in Brazil",
"version": "0.25.4",
"project_urls": {
"Source": "https://github.com/crdcj/PYield"
},
"split_keywords": [
"fixed-income",
" brazil",
" finance",
" analysis",
" bonds"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "1cae5cb28861ee9bb4acbbac8c56ad56167632cb05c0f0d3ebb7f6748f2d7a0c",
"md5": "9db5bd8e6913e9e8f99d4597162a06f6",
"sha256": "f9355c2e6758ff391fafbf46fa585cf4bba4b108ba52ca5812da34e38e5fcabd"
},
"downloads": -1,
"filename": "pyield-0.25.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9db5bd8e6913e9e8f99d4597162a06f6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 61808,
"upload_time": "2024-12-13T21:37:33",
"upload_time_iso_8601": "2024-12-13T21:37:33.612338Z",
"url": "https://files.pythonhosted.org/packages/1c/ae/5cb28861ee9bb4acbbac8c56ad56167632cb05c0f0d3ebb7f6748f2d7a0c/pyield-0.25.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a49cd87c55e2c3d06a27e3992d04bf56e9e7de0c25bed903b17eba40a4dfc888",
"md5": "54f1518ce022ec6cd14ab30a55d824b7",
"sha256": "a2df1188cf5d373a2a7599d58445b1516fec98118bba7f461dbe3e78100e13ef"
},
"downloads": -1,
"filename": "pyield-0.25.4.tar.gz",
"has_sig": false,
"md5_digest": "54f1518ce022ec6cd14ab30a55d824b7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 46096,
"upload_time": "2024-12-13T21:37:36",
"upload_time_iso_8601": "2024-12-13T21:37:36.626511Z",
"url": "https://files.pythonhosted.org/packages/a4/9c/d87c55e2c3d06a27e3992d04bf56e9e7de0c25bed903b17eba40a4dfc888/pyield-0.25.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-13 21:37:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "crdcj",
"github_project": "PYield",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyield"
}