PYield 0.23.3__tar.gz → 0.23.4__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.
Files changed (34) hide show
  1. {pyield-0.23.3 → pyield-0.23.4}/PKG-INFO +1 -1
  2. pyield-0.23.4/pyield/__about__.py +1 -0
  3. {pyield-0.23.3 → pyield-0.23.4}/pyield/bday.py +2 -2
  4. {pyield-0.23.3 → pyield-0.23.4}/pyield/date_converter.py +2 -2
  5. {pyield-0.23.3 → pyield-0.23.4}/pyield/indicators.py +36 -18
  6. pyield-0.23.3/pyield/__about__.py +0 -1
  7. {pyield-0.23.3 → pyield-0.23.4}/.gitignore +0 -0
  8. {pyield-0.23.3 → pyield-0.23.4}/LICENSE +0 -0
  9. {pyield-0.23.3 → pyield-0.23.4}/README.md +0 -0
  10. {pyield-0.23.3 → pyield-0.23.4}/pyield/__init__.py +0 -0
  11. {pyield-0.23.3 → pyield-0.23.4}/pyield/anbima.py +0 -0
  12. {pyield-0.23.3 → pyield-0.23.4}/pyield/b3_futures/__init__.py +0 -0
  13. {pyield-0.23.3 → pyield-0.23.4}/pyield/b3_futures/common.py +0 -0
  14. {pyield-0.23.3 → pyield-0.23.4}/pyield/b3_futures/historical.py +0 -0
  15. {pyield-0.23.3 → pyield-0.23.4}/pyield/b3_futures/intraday.py +0 -0
  16. {pyield-0.23.3 → pyield-0.23.4}/pyield/b3_futures/xml.py +0 -0
  17. {pyield-0.23.3 → pyield-0.23.4}/pyield/bonds/__init__.py +0 -0
  18. {pyield-0.23.3 → pyield-0.23.4}/pyield/bonds/bond_tools.py +0 -0
  19. {pyield-0.23.3 → pyield-0.23.4}/pyield/bonds/lft.py +0 -0
  20. {pyield-0.23.3 → pyield-0.23.4}/pyield/bonds/ltn.py +0 -0
  21. {pyield-0.23.3 → pyield-0.23.4}/pyield/bonds/ntnb.py +0 -0
  22. {pyield-0.23.3 → pyield-0.23.4}/pyield/bonds/ntnf.py +0 -0
  23. {pyield-0.23.3 → pyield-0.23.4}/pyield/conftest.py +0 -0
  24. {pyield-0.23.3 → pyield-0.23.4}/pyield/data_cache.py +0 -0
  25. {pyield-0.23.3 → pyield-0.23.4}/pyield/di.py +0 -0
  26. {pyield-0.23.3 → pyield-0.23.4}/pyield/holidays/__init__.py +0 -0
  27. {pyield-0.23.3 → pyield-0.23.4}/pyield/holidays/br_holidays_new.txt +0 -0
  28. {pyield-0.23.3 → pyield-0.23.4}/pyield/holidays/br_holidays_old.txt +0 -0
  29. {pyield-0.23.3 → pyield-0.23.4}/pyield/holidays/brholidays.py +0 -0
  30. {pyield-0.23.3 → pyield-0.23.4}/pyield/interpolator.py +0 -0
  31. {pyield-0.23.3 → pyield-0.23.4}/pyield/projections.py +0 -0
  32. {pyield-0.23.3 → pyield-0.23.4}/pyield/py.typed +0 -0
  33. {pyield-0.23.3 → pyield-0.23.4}/pyield/tools.py +0 -0
  34. {pyield-0.23.3 → pyield-0.23.4}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: PYield
3
- Version: 0.23.3
3
+ Version: 0.23.4
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>
@@ -0,0 +1 @@
1
+ __version__ = "0.23.4"
@@ -7,8 +7,8 @@ import pyield.date_converter as dc
7
7
  import pyield.holidays as hl
8
8
  from pyield.date_converter import ArrayDateTypes, ScalarDateTypes
9
9
 
10
- type ArrayIntTypes = np.ndarray | pd.Series | list | tuple
11
- type ScalarIntTypes = int | np.integer
10
+ ArrayIntTypes = np.ndarray | pd.Series | list | tuple
11
+ ScalarIntTypes = int | np.integer
12
12
 
13
13
  # Initialize Brazilian holidays data
14
14
  br_holidays = hl.BrHolidays()
@@ -4,8 +4,8 @@ from typing import overload
4
4
  import numpy as np
5
5
  import pandas as pd
6
6
 
7
- type ScalarDateTypes = str | np.datetime64 | pd.Timestamp | dt.datetime | dt.date
8
- type ArrayDateTypes = pd.Series | pd.DatetimeIndex | np.ndarray | list | tuple
7
+ ScalarDateTypes = str | np.datetime64 | pd.Timestamp | dt.datetime | dt.date
8
+ ArrayDateTypes = pd.Series | pd.DatetimeIndex | np.ndarray | list | tuple
9
9
 
10
10
 
11
11
  def validate_date_format(date_str):
@@ -44,6 +44,7 @@ def indicator(
44
44
 
45
45
  Raises:
46
46
  ValueError: If an invalid `indicator_code` is provided.
47
+ ValueError: After all retries, if the indicator value cannot be fetched.
47
48
 
48
49
  Examples:
49
50
  >>> yd.indicator("IPCA_MR", "01-04-2024")
@@ -102,7 +103,7 @@ def ipca_monthly_rate(reference_date: pd.Timestamp) -> float:
102
103
  data = response.json()
103
104
 
104
105
  if not data:
105
- return float("nan")
106
+ raise ValueError("No data available for the specified date")
106
107
  # Extract and return the IPCA monthly growth rate if data is available
107
108
  ipca_str = data[0]["resultados"][0]["series"][0]["serie"][ipca_date]
108
109
  return round(float(ipca_str) / 100, 4)
@@ -146,8 +147,8 @@ def _selic_target(reference_date: pd.Timestamp) -> float:
146
147
  attempt += 1
147
148
  time.sleep(1.5**attempt) # Exponential backoff: 1.5, 2.3, 3.9, 5.1, 7.6 seconds
148
149
 
149
- # After all retries, return NaN
150
- return float("nan")
150
+ # After all retries, raise an error
151
+ raise ValueError("Failed to fetch SELIC Target rate after maximum attempts")
151
152
 
152
153
 
153
154
  def _selic_over(reference_date: pd.Timestamp) -> float:
@@ -191,8 +192,8 @@ def _selic_over(reference_date: pd.Timestamp) -> float:
191
192
  attempt += 1
192
193
  time.sleep(1.5**attempt) # Exponential backoff: 1.5, 2.3, 3.9, 5.1, 7.6 seconds
193
194
 
194
- # After all retries, return NaN
195
- return float("nan")
195
+ # After all retries, raise an error
196
+ raise ValueError("Failed to fetch SELIC Over rate after maximum attempts")
196
197
 
197
198
 
198
199
  def _di(reference_date: pd.Timestamp) -> float:
@@ -210,22 +211,13 @@ def _di(reference_date: pd.Timestamp) -> float:
210
211
  return round((1 + value) ** 252 - 1, 4)
211
212
 
212
213
 
213
- def _vna_lft(reference_date: pd.Timestamp) -> float:
214
- # url example: https://www3.bcb.gov.br/novoselic/rest/arquivosDiarios/pub/download/3/20240418APC238
215
- url_base = "https://www3.bcb.gov.br/novoselic/rest/arquivosDiarios/pub/download/3/"
216
- url_file = f"{reference_date.strftime('%Y%m%d')}APC238"
217
- url_vna = url_base + url_file
218
-
219
- response = requests.get(url_vna, timeout=TIMEOUT)
220
- response.raise_for_status()
221
- file_text = response.text
222
-
214
+ def _extract_vna_value(text: str) -> float:
223
215
  # Finding the part that contains the table
224
- start_of_table = file_text.find("EMISSAO")
225
- end_of_table = file_text.find("99999999*")
216
+ start_of_table = text.find("EMISSAO")
217
+ end_of_table = text.find("99999999*")
226
218
 
227
219
  # Extracting the table
228
- table_text = file_text[start_of_table:end_of_table].strip()
220
+ table_text = text[start_of_table:end_of_table].strip()
229
221
  table_lines = table_text.splitlines()
230
222
 
231
223
  # Remove empty lines
@@ -246,3 +238,29 @@ def _vna_lft(reference_date: pd.Timestamp) -> float:
246
238
  raise ValueError(f"VNA values are not the same. Please check data at {bcb_url}")
247
239
 
248
240
  return vna_value
241
+
242
+
243
+ def _vna_lft(reference_date: pd.Timestamp) -> float:
244
+ # url example: https://www3.bcb.gov.br/novoselic/rest/arquivosDiarios/pub/download/3/20240418APC238
245
+ url_base = "https://www3.bcb.gov.br/novoselic/rest/arquivosDiarios/pub/download/3/"
246
+ url_file = f"{reference_date.strftime('%Y%m%d')}APC238"
247
+ url_vna = url_base + url_file
248
+ session = requests.Session()
249
+
250
+ attempt = 0
251
+ while attempt < MAX_ATTEMPTS:
252
+ try:
253
+ response = session.get(url_vna, timeout=TIMEOUT)
254
+ response.raise_for_status()
255
+ return _extract_vna_value(response.text)
256
+
257
+ except (RequestException, KeyError, IndexError, ValueError) as e:
258
+ msg = f"Error fetching SELIC Over rate (attempt {attempt + 1}): {e}"
259
+ logging.error(msg)
260
+
261
+ # Increment attempt count and add backoff delay
262
+ attempt += 1
263
+ time.sleep(1.5**attempt) # Exponential backoff: 1.5, 2.3, 3.9, 5.1, 7.6 seconds
264
+
265
+ # After all retries, raise an error
266
+ raise ValueError("Failed to fetch VNA LFT value after maximum attempts")
@@ -1 +0,0 @@
1
- __version__ = "0.23.3"
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