PYield 0.29.0__tar.gz → 0.29.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyield-0.29.0 → pyield-0.29.2}/PKG-INFO +12 -10
- {pyield-0.29.0 → pyield-0.29.2}/README.md +11 -9
- pyield-0.29.2/pyield/__about__.py +1 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/bc/__init__.py +2 -0
- pyield-0.29.2/pyield/ibge/__init__.py +13 -0
- pyield-0.29.2/pyield/ibge/ipca.py +190 -0
- pyield-0.29.0/pyield/__about__.py +0 -1
- pyield-0.29.0/pyield/ibge/__init__.py +0 -5
- pyield-0.29.0/pyield/ibge/ipca.py +0 -38
- {pyield-0.29.0 → pyield-0.29.2}/.gitignore +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/LICENSE +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/__init__.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/anbima/__init__.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/anbima/ima.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/anbima/imaq.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/anbima/ipca.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/anbima/tpf.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/b3_futures/__init__.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/b3_futures/common.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/b3_futures/di.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/b3_futures/historical.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/b3_futures/intraday.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/b3_futures/xml.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/bc/auction.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/bc/bcdata.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/bc/ptax.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/bc/repos.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/bc/sec.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/bc/vna.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/bday.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/config.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/conftest.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/data_cache.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/date_converter.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/forwards.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/holidays/__init__.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/holidays/br_holidays_new.txt +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/holidays/br_holidays_old.txt +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/holidays/brholidays.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/interpolator.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/py.typed +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/tpf/__init__.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/tpf/lft.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/tpf/ltn.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/tpf/ntnb.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/tpf/ntnf.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyield/tpf/tools.py +0 -0
- {pyield-0.29.0 → pyield-0.29.2}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PYield
|
|
3
|
-
Version: 0.29.
|
|
3
|
+
Version: 0.29.2
|
|
4
4
|
Summary: A Python library for analysis of fixed income instruments in Brazil
|
|
5
5
|
Project-URL: Source, https://github.com/crdcj/PYield
|
|
6
6
|
Author-email: Carlos Carvalho <cr.cj@outlook.com>
|
|
@@ -193,21 +193,23 @@ TradeDate TickerSymbol ExpirationDate BDaysToExp ... LastRate LastAskRate LastB
|
|
|
193
193
|
|
|
194
194
|
### Indicators Data
|
|
195
195
|
```python
|
|
196
|
-
>>>
|
|
196
|
+
>>> from pyield import bc
|
|
197
197
|
# Fetch the SELIC target rate from the Central Bank of Brazil
|
|
198
|
-
>>>
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
198
|
+
>>> bc.selic_over("26-01-2025") # No data on 26-01-2025 (sunday)
|
|
199
|
+
Date Value
|
|
200
|
+
0 2025-01-27 0.1215
|
|
201
|
+
1 2025-01-28 0.1215
|
|
202
|
+
2 2025-01-29 0.1215
|
|
203
|
+
3 2025-01-30 0.1315
|
|
204
|
+
4 2025-01-31 0.1315
|
|
205
|
+
...
|
|
204
206
|
```
|
|
205
207
|
|
|
206
208
|
### Projections Data
|
|
207
209
|
```python
|
|
208
|
-
>>>
|
|
210
|
+
>>> from pyield import anbima
|
|
209
211
|
# Fetch current month projection for IPCA from IBGE API
|
|
210
|
-
>>> ipca =
|
|
212
|
+
>>> ipca = anbima.ipca_projection()
|
|
211
213
|
>>> print(ipca)
|
|
212
214
|
IndicatorProjection(
|
|
213
215
|
last_updated=Timestamp('2024-04-19 18:55:00'),
|
|
@@ -152,21 +152,23 @@ TradeDate TickerSymbol ExpirationDate BDaysToExp ... LastRate LastAskRate LastB
|
|
|
152
152
|
|
|
153
153
|
### Indicators Data
|
|
154
154
|
```python
|
|
155
|
-
>>>
|
|
155
|
+
>>> from pyield import bc
|
|
156
156
|
# Fetch the SELIC target rate from the Central Bank of Brazil
|
|
157
|
-
>>>
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
>>> bc.selic_over("26-01-2025") # No data on 26-01-2025 (sunday)
|
|
158
|
+
Date Value
|
|
159
|
+
0 2025-01-27 0.1215
|
|
160
|
+
1 2025-01-28 0.1215
|
|
161
|
+
2 2025-01-29 0.1215
|
|
162
|
+
3 2025-01-30 0.1315
|
|
163
|
+
4 2025-01-31 0.1315
|
|
164
|
+
...
|
|
163
165
|
```
|
|
164
166
|
|
|
165
167
|
### Projections Data
|
|
166
168
|
```python
|
|
167
|
-
>>>
|
|
169
|
+
>>> from pyield import anbima
|
|
168
170
|
# Fetch current month projection for IPCA from IBGE API
|
|
169
|
-
>>> ipca =
|
|
171
|
+
>>> ipca = anbima.ipca_projection()
|
|
170
172
|
>>> print(ipca)
|
|
171
173
|
IndicatorProjection(
|
|
172
174
|
last_updated=Timestamp('2024-04-19 18:55:00'),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.29.2"
|
|
@@ -2,6 +2,7 @@ from pyield.bc.auction import auctions
|
|
|
2
2
|
from pyield.bc.bcdata import di_over, selic_over, selic_target
|
|
3
3
|
from pyield.bc.ptax import ptax
|
|
4
4
|
from pyield.bc.repos import repos
|
|
5
|
+
from pyield.bc.sec import sec
|
|
5
6
|
from pyield.bc.vna import vna_lft
|
|
6
7
|
|
|
7
8
|
__all__ = [
|
|
@@ -12,4 +13,5 @@ __all__ = [
|
|
|
12
13
|
"selic_over",
|
|
13
14
|
"selic_target",
|
|
14
15
|
"di_over",
|
|
16
|
+
"sec",
|
|
15
17
|
]
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
from pyield.config import default_retry
|
|
7
|
+
from pyield.date_converter import DateScalar, convert_input_dates
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
IPCA_URL = "https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@default_retry
|
|
14
|
+
def _fetch_series_data(url: str) -> dict[str, str]:
|
|
15
|
+
response = requests.get(url)
|
|
16
|
+
response.raise_for_status() # Raises an exception for HTTP error codes
|
|
17
|
+
data = response.json()
|
|
18
|
+
if not data:
|
|
19
|
+
raise ValueError(f"No data available for the API URL: {url}")
|
|
20
|
+
return data[0]["resultados"][0]["series"][0]["serie"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _process_ipca_dataframe(
|
|
24
|
+
data_dict: dict[str, str], is_in_pct: bool = False
|
|
25
|
+
) -> pd.DataFrame:
|
|
26
|
+
"""
|
|
27
|
+
Process the IPCA data dictionary into a DataFrame with proper formatting.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
data_dict (dict[str, str]): Dictionary containing the raw IPCA data
|
|
31
|
+
is_in_pct (bool, optional): Whether the data represents rates in percentage
|
|
32
|
+
format (True) or indexes (False). Defaults to False.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
pd.DataFrame: DataFrame with columns 'Period' and 'Value'
|
|
36
|
+
"""
|
|
37
|
+
df = pd.DataFrame.from_dict(data_dict, orient="index")
|
|
38
|
+
df = df.reset_index()
|
|
39
|
+
df = df.rename(columns={"index": "Period", 0: "Value"})
|
|
40
|
+
|
|
41
|
+
df["Value"] = pd.to_numeric(df["Value"])
|
|
42
|
+
|
|
43
|
+
# If it's a rate value, divide by 100 and round to 4 decimal places
|
|
44
|
+
if is_in_pct:
|
|
45
|
+
df["Value"] = (df["Value"] / 100).round(4)
|
|
46
|
+
else:
|
|
47
|
+
df["Value"] = df["Value"].round(2)
|
|
48
|
+
|
|
49
|
+
df["Value"] = df["Value"].astype("Float64")
|
|
50
|
+
df["Period"] = pd.to_datetime(df["Period"], format="%Y%m").dt.to_period("M")
|
|
51
|
+
|
|
52
|
+
return df
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def ipca_rates(start: DateScalar, end: DateScalar) -> pd.DataFrame:
|
|
56
|
+
"""
|
|
57
|
+
Retrieves the IPCA monthly rates for a specified date range.
|
|
58
|
+
|
|
59
|
+
Makes an API call to the IBGE's data portal using the format:
|
|
60
|
+
https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/YYYYMM-YYYYMM/variaveis/63?localidades=N1[all]
|
|
61
|
+
|
|
62
|
+
Example: For the date range "01-01-2024" to "31-03-2024", the API URL will be:
|
|
63
|
+
https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/202401-202403/variaveis/63?localidades=N1[all]
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
start (DateScalar): The start date of the date range
|
|
67
|
+
end (DateScalar): The end date of the date range
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
pd.DataFrame: DataFrame with columns 'Period' and 'Rate'
|
|
71
|
+
|
|
72
|
+
Examples:
|
|
73
|
+
>>> from pyield import ibge
|
|
74
|
+
>>> # Get the IPCA rates for the first quarter of 2024
|
|
75
|
+
>>> df = ibge.ipca_rates("01-01-2024", "31-03-2024")
|
|
76
|
+
"""
|
|
77
|
+
start = convert_input_dates(start)
|
|
78
|
+
end = convert_input_dates(end)
|
|
79
|
+
|
|
80
|
+
start_date = start.strftime("%Y%m")
|
|
81
|
+
end_date = end.strftime("%Y%m")
|
|
82
|
+
api_url = f"{IPCA_URL}{start_date}-{end_date}/variaveis/63?localidades=N1[all]"
|
|
83
|
+
data_dict = _fetch_series_data(api_url)
|
|
84
|
+
|
|
85
|
+
return _process_ipca_dataframe(data_dict, is_in_pct=True)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def ipca_last_rates(num_months: int = 1) -> pd.DataFrame:
|
|
89
|
+
"""
|
|
90
|
+
Retrieves the last IPCA monthly rates for a specified number of months.
|
|
91
|
+
|
|
92
|
+
Makes an API call to the IBGE's data portal using the format:
|
|
93
|
+
https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/-N/variaveis/63?localidades=N1[all]
|
|
94
|
+
|
|
95
|
+
Example: For the last 2 months, the API URL will be:
|
|
96
|
+
https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/-2/variaveis/63?localidades=N1[all]
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
num_months (int, optional): Number of months to retrieve. Defaults to 1.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
pd.DataFrame: DataFrame with columns 'Period' and 'Value'
|
|
103
|
+
|
|
104
|
+
Raises:
|
|
105
|
+
ValueError: If num_months is 0
|
|
106
|
+
|
|
107
|
+
Examples:
|
|
108
|
+
>>> from pyield import ibge
|
|
109
|
+
>>> # Get the last month's IPCA rate
|
|
110
|
+
>>> df = ibge.ipca_last_rates(1)
|
|
111
|
+
>>> # Get the last 3 months' IPCA rates
|
|
112
|
+
>>> df = ibge.ipca_last_rates(3)
|
|
113
|
+
"""
|
|
114
|
+
num_months = abs(num_months)
|
|
115
|
+
if num_months == 0:
|
|
116
|
+
raise ValueError("The number of months must be greater than 0.")
|
|
117
|
+
|
|
118
|
+
api_url = f"{IPCA_URL}-{num_months}/variaveis/63?localidades=N1[all]"
|
|
119
|
+
data_dict = _fetch_series_data(api_url)
|
|
120
|
+
|
|
121
|
+
return _process_ipca_dataframe(data_dict, is_in_pct=True)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def ipca_last_indexes(num_months: int = 1) -> pd.DataFrame:
|
|
125
|
+
"""
|
|
126
|
+
Retrieves the last IPCA index values for a specified number of months.
|
|
127
|
+
|
|
128
|
+
Makes an API call to the IBGE's data portal using the format:
|
|
129
|
+
https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/-N/variaveis/2266?localidades=N1[all]
|
|
130
|
+
|
|
131
|
+
Example: For the last 2 months, the API URL will be:
|
|
132
|
+
https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/-2/variaveis/2266?localidades=N1[all]
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
num_months (int, optional): Number of months to retrieve. Defaults to 1.
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
pd.DataFrame: DataFrame with columns 'Period' and 'Value'
|
|
139
|
+
|
|
140
|
+
Raises:
|
|
141
|
+
ValueError: If num_months is 0
|
|
142
|
+
|
|
143
|
+
Examples:
|
|
144
|
+
>>> from pyield import ibge
|
|
145
|
+
>>> # Get the last month's IPCA index
|
|
146
|
+
>>> df = ibge.ipca_last_indexes(1)
|
|
147
|
+
>>> # Get the last 3 months' IPCA indexes
|
|
148
|
+
>>> df = ibge.ipca_last_indexes(3)
|
|
149
|
+
"""
|
|
150
|
+
num_months = abs(num_months)
|
|
151
|
+
if num_months == 0:
|
|
152
|
+
raise ValueError("The number of months must be greater than 0.")
|
|
153
|
+
|
|
154
|
+
api_url = f"{IPCA_URL}-{num_months}/variaveis/2266?localidades=N1[all]"
|
|
155
|
+
data_dict = _fetch_series_data(api_url)
|
|
156
|
+
|
|
157
|
+
return _process_ipca_dataframe(data_dict)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def ipca_indexes(start: DateScalar, end: DateScalar) -> pd.DataFrame:
|
|
161
|
+
"""
|
|
162
|
+
Retrieves the IPCA index values for a specified date range.
|
|
163
|
+
|
|
164
|
+
Makes an API call to the IBGE's data portal using the format:
|
|
165
|
+
https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/YYYYMM-YYYYMM/variaveis/2266?localidades=N1[all]
|
|
166
|
+
|
|
167
|
+
Example: For the date range "01-01-2024" to "31-03-2024", the API URL will be:
|
|
168
|
+
https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/202401-202403/variaveis/2266?localidades=N1[all]
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
start (DateScalar): The start date of the date range
|
|
172
|
+
end (DateScalar): The end date of the date range
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
pd.DataFrame: DataFrame with columns 'Period' and 'Value'
|
|
176
|
+
|
|
177
|
+
Examples:
|
|
178
|
+
>>> from pyield import ibge
|
|
179
|
+
>>> # Get the IPCA indexes for the first quarter of 2024
|
|
180
|
+
>>> df = ibge.ipca_indexes("01-01-2024", "31-03-2024")
|
|
181
|
+
"""
|
|
182
|
+
start = convert_input_dates(start)
|
|
183
|
+
end = convert_input_dates(end)
|
|
184
|
+
|
|
185
|
+
start_date = start.strftime("%Y%m")
|
|
186
|
+
end_date = end.strftime("%Y%m")
|
|
187
|
+
api_url = f"{IPCA_URL}{start_date}-{end_date}/variaveis/2266?localidades=N1[all]"
|
|
188
|
+
data_dict = _fetch_series_data(api_url)
|
|
189
|
+
|
|
190
|
+
return _process_ipca_dataframe(data_dict)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.29.0"
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
|
|
3
|
-
import requests
|
|
4
|
-
|
|
5
|
-
from pyield.config import default_retry
|
|
6
|
-
from pyield.date_converter import DateScalar, convert_input_dates
|
|
7
|
-
|
|
8
|
-
logger = logging.getLogger(__name__)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@default_retry
|
|
12
|
-
def ipca_monthly_rate(date: DateScalar) -> float:
|
|
13
|
-
"""
|
|
14
|
-
The function makes an API call to the IBGE's data portal to retrieve the data.
|
|
15
|
-
An example of the API call: https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/202403/variaveis/63?localidades=N1[all]
|
|
16
|
-
where '202403' is the reference date in 'YYYYMM' format.
|
|
17
|
-
The API URL is constructed dynamically based on the reference date provided.
|
|
18
|
-
|
|
19
|
-
Examples:
|
|
20
|
-
>>> yd.ibge.ipca_monthly_rate("01-04-2024")
|
|
21
|
-
0.0038
|
|
22
|
-
"""
|
|
23
|
-
date = convert_input_dates(date)
|
|
24
|
-
# Format the date as 'YYYYMM' for the API endpoint
|
|
25
|
-
ipca_date = date.strftime("%Y%m")
|
|
26
|
-
|
|
27
|
-
# Construct the API URL using the formatted date
|
|
28
|
-
api_url = f"https://servicodados.ibge.gov.br/api/v3/agregados/6691/periodos/{ipca_date}/variaveis/63?localidades=N1[all]"
|
|
29
|
-
|
|
30
|
-
response = requests.get(api_url)
|
|
31
|
-
response.raise_for_status() # Levanta uma exceção para códigos de erro HTTP
|
|
32
|
-
data = response.json()
|
|
33
|
-
if not data:
|
|
34
|
-
msg = f"No data available for IPCA Monthly Rate on {date}"
|
|
35
|
-
logger.warning(msg)
|
|
36
|
-
return float("nan")
|
|
37
|
-
ipca_str = data[0]["resultados"][0]["series"][0]["serie"][ipca_date]
|
|
38
|
-
return round(float(ipca_str) / 100, 4)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|