PYield 0.20.0__tar.gz → 0.20.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.
Files changed (34) hide show
  1. {pyield-0.20.0 → pyield-0.20.2}/PKG-INFO +1 -1
  2. pyield-0.20.2/pyield/__about__.py +1 -0
  3. {pyield-0.20.0 → pyield-0.20.2}/pyield/b3_futures/__init__.py +13 -1
  4. {pyield-0.20.0 → pyield-0.20.2}/pyield/b3_futures/common.py +3 -3
  5. {pyield-0.20.0 → pyield-0.20.2}/pyield/b3_futures/historical.py +1 -1
  6. pyield-0.20.2/pyield/date_converter.py +78 -0
  7. {pyield-0.20.0 → pyield-0.20.2}/pyield/indicators.py +4 -4
  8. {pyield-0.20.0 → pyield-0.20.2}/pyield/projections.py +1 -5
  9. {pyield-0.20.0 → pyield-0.20.2}/pyproject.toml +1 -1
  10. pyield-0.20.0/pyield/__about__.py +0 -1
  11. pyield-0.20.0/pyield/date_converter.py +0 -82
  12. {pyield-0.20.0 → pyield-0.20.2}/LICENSE +0 -0
  13. {pyield-0.20.0 → pyield-0.20.2}/README.md +0 -0
  14. {pyield-0.20.0 → pyield-0.20.2}/pyield/__init__.py +0 -0
  15. {pyield-0.20.0 → pyield-0.20.2}/pyield/anbima.py +0 -0
  16. {pyield-0.20.0 → pyield-0.20.2}/pyield/b3_futures/intraday.py +0 -0
  17. {pyield-0.20.0 → pyield-0.20.2}/pyield/b3_futures/xml.py +0 -0
  18. {pyield-0.20.0 → pyield-0.20.2}/pyield/bday.py +0 -0
  19. {pyield-0.20.0 → pyield-0.20.2}/pyield/bonds/__init__.py +0 -0
  20. {pyield-0.20.0 → pyield-0.20.2}/pyield/bonds/bond_tools.py +0 -0
  21. {pyield-0.20.0 → pyield-0.20.2}/pyield/bonds/lft.py +0 -0
  22. {pyield-0.20.0 → pyield-0.20.2}/pyield/bonds/ltn.py +0 -0
  23. {pyield-0.20.0 → pyield-0.20.2}/pyield/bonds/ntnb.py +0 -0
  24. {pyield-0.20.0 → pyield-0.20.2}/pyield/bonds/ntnf.py +0 -0
  25. {pyield-0.20.0 → pyield-0.20.2}/pyield/conftest.py +0 -0
  26. {pyield-0.20.0 → pyield-0.20.2}/pyield/data_cache.py +0 -0
  27. {pyield-0.20.0 → pyield-0.20.2}/pyield/di.py +0 -0
  28. {pyield-0.20.0 → pyield-0.20.2}/pyield/holidays/__init__.py +0 -0
  29. {pyield-0.20.0 → pyield-0.20.2}/pyield/holidays/br_holidays_new.txt +0 -0
  30. {pyield-0.20.0 → pyield-0.20.2}/pyield/holidays/br_holidays_old.txt +0 -0
  31. {pyield-0.20.0 → pyield-0.20.2}/pyield/holidays/brholidays.py +0 -0
  32. {pyield-0.20.0 → pyield-0.20.2}/pyield/interpolator.py +0 -0
  33. {pyield-0.20.0 → pyield-0.20.2}/pyield/py.typed +0 -0
  34. {pyield-0.20.0 → pyield-0.20.2}/pyield/tools.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PYield
3
- Version: 0.20.0
3
+ Version: 0.20.2
4
4
  Summary: A Python library for analysis of fixed income instruments in Brazil
5
5
  Keywords: fixed-income, brazil, finance, analysis, bonds
6
6
  Author-Email: Carlos Carvalho <cr.cj@outlook.com>
@@ -0,0 +1 @@
1
+ __version__ = "0.20.2"
@@ -41,7 +41,19 @@ def futures(
41
41
 
42
42
  Examples:
43
43
  >>> futures("DI1", "31-05-2024")
44
- >>> futures("DDI", "31-05-2024")
44
+ TradeDate TickerSymbol ... CloseBidRate CloseRate
45
+ 0 2024-05-31 DI1M24 ... 0.10404 0.10404
46
+ 1 2024-05-31 DI1N24 ... 0.1039 0.10386
47
+ 2 2024-05-31 DI1Q24 ... 0.10374 0.10374
48
+ 3 2024-05-31 DI1U24 ... 0.10365 0.10355
49
+ ...
50
+ >>> futures("DAP", "31-05-2024")
51
+ TradeDate TickerSymbol ... CloseBidRate CloseRate
52
+ 0 2024-05-31 DAPM24 ... <NA> <NA>
53
+ 1 2024-05-31 DAPN24 ... <NA> <NA>
54
+ 2 2024-05-31 DAPQ24 ... <NA> 0.0885
55
+ 3 2024-05-31 DAPU24 ... <NA> 0.0865
56
+ ...
45
57
  """
46
58
  contract_code = contract_code.upper()
47
59
  if contract_code not in SUPPORTED_FUTURES:
@@ -23,13 +23,13 @@ def get_expiration_date(expiration_code: str, expiration_day: int = 1) -> pd.Tim
23
23
 
24
24
  Examples:
25
25
  >>> get_expiration_date("F23")
26
- pd.Timestamp('2023-01-01')
26
+ Timestamp('2023-01-02 00:00:00')
27
27
 
28
28
  >>> get_expiration_date("Z33")
29
- pd.Timestamp('2033-12-01')
29
+ Timestamp('2033-12-01 00:00:00')
30
30
 
31
31
  >>> get_expiration_date("A99")
32
- pd.NaT
32
+ NaT
33
33
 
34
34
  Notes:
35
35
  The expiration date is calculated based on the format change introduced by B3 on
@@ -37,7 +37,7 @@ def get_old_expiration_date(
37
37
 
38
38
  Examples:
39
39
  >>> get_old_expiration_date("JAN3", pd.Timestamp("2001-05-21"))
40
- pd.Timestamp('2003-01-01')
40
+ Timestamp('2003-01-02 00:00:00')
41
41
 
42
42
  Notes:
43
43
  - In 22-05-2006, B3 changed the format of the DI contract codes. Before that
@@ -0,0 +1,78 @@
1
+ import datetime as dt
2
+ from typing import overload
3
+
4
+ import numpy as np
5
+ import pandas as pd
6
+
7
+ type ScalarDateTypes = str | np.datetime64 | pd.Timestamp | dt.datetime | dt.date
8
+ type ArrayDateTypes = pd.Series | pd.DatetimeIndex | np.ndarray | list | tuple
9
+
10
+
11
+ def validate_date_format(date_str):
12
+ # Primeiro tenta com hífen (-)
13
+ for fmt in ["%d-%m-%Y", "%d/%m/%Y"]:
14
+ try:
15
+ dt.datetime.strptime(date_str, fmt)
16
+ return
17
+ except ValueError:
18
+ continue
19
+ raise ValueError(
20
+ f"Invalid format: {date_str}. Day first is required (e.g. '31-05-2024')."
21
+ )
22
+
23
+
24
+ @overload
25
+ def convert_input_dates(dates: ScalarDateTypes) -> pd.Timestamp: ...
26
+ @overload
27
+ def convert_input_dates(dates: ArrayDateTypes) -> pd.Series: ...
28
+
29
+
30
+ def convert_input_dates(
31
+ dates: ScalarDateTypes | ArrayDateTypes,
32
+ ) -> pd.Timestamp | pd.Series:
33
+ match dates:
34
+ case None:
35
+ raise ValueError("'dates' cannot be None.")
36
+
37
+ case str():
38
+ validate_date_format(dates)
39
+ return pd.to_datetime(dates, dayfirst=True)
40
+
41
+ case dt.datetime() | dt.date() | np.datetime64() | pd.Timestamp():
42
+ return pd.Timestamp(dates).normalize()
43
+
44
+ case pd.Series() | np.ndarray() | list() | tuple():
45
+ result = pd.Series(dates)
46
+
47
+ if result.empty:
48
+ raise ValueError("'dates' cannot be an empty Array.")
49
+
50
+ if pd.api.types.is_string_dtype(result):
51
+ # Check first element to validate date format
52
+ validate_date_format(result[0])
53
+
54
+ return pd.to_datetime(result, dayfirst=True).astype("datetime64[ns]")
55
+
56
+ case pd.DatetimeIndex():
57
+ return pd.Series(dates).astype("datetime64[ns]")
58
+
59
+ case _:
60
+ raise ValueError("Invalid input type for 'dates'.")
61
+
62
+
63
+ def convert_to_numpy_date(
64
+ dates: pd.Timestamp | pd.Series,
65
+ ) -> np.datetime64 | np.ndarray:
66
+ """
67
+ Converts the input dates to a numpy datetime64[D] format.
68
+
69
+ Args:
70
+ dates (Timestamp | Series): A single date or a Series of dates.
71
+
72
+ Returns:
73
+ np.datetime64 | np.ndarray: The input dates in a numpy datetime64[D] format.
74
+ """
75
+ if isinstance(dates, pd.Timestamp):
76
+ return np.datetime64(dates, "D")
77
+ else:
78
+ return dates.to_numpy().astype("datetime64[D]")
@@ -6,11 +6,12 @@ import requests
6
6
 
7
7
  from pyield import date_converter as dc
8
8
 
9
+ type IndicatorCode = Literal["IPCA_MR", "SELIC_TARGET", "SELIC_OVER", "DI", "VNA_LFT"]
9
10
  TIMEOUT = 10
10
11
 
11
12
 
12
13
  def indicator(
13
- indicator_code: Literal["IPCA_MR", "SELIC_TARGET", "SELIC_OVER", "DI", "VNA_LFT"],
14
+ indicator_code: IndicatorCode,
14
15
  reference_date: str | pd.Timestamp,
15
16
  ) -> float:
16
17
  """
@@ -22,9 +23,8 @@ def indicator(
22
23
  correct API is dynamically chosen based on the indicator code provided.
23
24
 
24
25
  Args:
25
- indicator_code (Literal["IPCA_MR", "SELIC_TARGET", "SELIC_OVER", "DI",
26
- "VNA_LFT"]):
27
- The code for the desired economic indicator:
26
+ indicator_code (IndicatorCode): The code of the economic indicator to fetch.
27
+ The available options are:
28
28
  - "IPCA_MR": IPCA Monthly Rate (inflation).
29
29
  - "SELIC_TARGET": SELIC Target rate.
30
30
  - "SELIC_OVER": SELIC Over (overnight) rate.
@@ -38,11 +38,7 @@ def projection(projection_code: Literal["IPCA_CM"]) -> IndicatorProjection:
38
38
 
39
39
  Example:
40
40
  >>> projection("IPCA_CM")
41
- IndicatorProjection(
42
- reference_period=Period('2024-09', 'M'),
43
- projected_value=0.0046,
44
- last_updated=Timestamp('2024-09-27 18:42:00')
45
- )
41
+ IndicatorProjection(reference_period=Period(...), projected_value=..., ...)
46
42
 
47
43
  """
48
44
  proj_type = str(projection_code).upper()
@@ -32,7 +32,7 @@ dependencies = [
32
32
  "types-requests",
33
33
  ]
34
34
  dynamic = []
35
- version = "0.20.0"
35
+ version = "0.20.2"
36
36
 
37
37
  [project.license]
38
38
  file = "LICENSE"
@@ -1 +0,0 @@
1
- __version__ = "0.20.0"
@@ -1,82 +0,0 @@
1
- import datetime as dt
2
- import re
3
- from typing import overload
4
-
5
- import numpy as np
6
- import pandas as pd
7
-
8
- type ScalarDateTypes = str | np.datetime64 | pd.Timestamp | dt.datetime | dt.date
9
- type PandasArrayDateTypes = pd.Series | pd.DatetimeIndex | pd.Index
10
- type ArrayDateTypes = PandasArrayDateTypes | np.ndarray | list | tuple
11
-
12
-
13
- def validate_year_format(value):
14
- """If the input date is a string, it validates the year format."""
15
- if not isinstance(value, str):
16
- return
17
-
18
- value = value.strip().lower()
19
- if value in {"today", "now"}:
20
- return
21
-
22
- if re.match(r"^\d{4}-", value):
23
- error_msg = f"Invalid format: {value}. Day first format is required. Example: '31-05-2024'." # noqa
24
- raise ValueError(error_msg)
25
-
26
-
27
- def check_first_value(dates):
28
- match dates:
29
- case None:
30
- raise ValueError("Date cannot be None.")
31
- case str():
32
- validate_year_format(dates)
33
- case list() | tuple() | np.ndarray() | pd.Series():
34
- validate_year_format(dates[0])
35
-
36
-
37
- @overload
38
- def convert_input_dates(dates: ScalarDateTypes) -> pd.Timestamp: ...
39
- @overload
40
- def convert_input_dates(dates: ArrayDateTypes) -> pd.Series: ...
41
-
42
-
43
- def convert_input_dates(
44
- dates: ScalarDateTypes | ArrayDateTypes,
45
- ) -> pd.Timestamp | pd.Series:
46
- check_first_value(dates)
47
-
48
- result = pd.to_datetime(dates, dayfirst=True)
49
-
50
- match result:
51
- case pd.Timestamp():
52
- result = result.normalize()
53
- case dt.datetime() | dt.date() | np.datetime64():
54
- result = pd.Timestamp(result).normalize()
55
- case pd.Series():
56
- result = result.astype("datetime64[ns]")
57
- case pd.DatetimeIndex():
58
- result = pd.Series(result).astype("datetime64[ns]")
59
- case None:
60
- raise ValueError("Date cannot be None.")
61
- case _:
62
- raise ValueError("Invalid date input type.")
63
-
64
- return result
65
-
66
-
67
- def convert_to_numpy_date(
68
- dates: pd.Timestamp | pd.Series,
69
- ) -> np.datetime64 | np.ndarray:
70
- """
71
- Converts the input dates to a numpy datetime64[D] format.
72
-
73
- Args:
74
- dates (Timestamp | Series): A single date or a Series of dates.
75
-
76
- Returns:
77
- np.datetime64 | np.ndarray: The input dates in a numpy datetime64[D] format.
78
- """
79
- if isinstance(dates, pd.Timestamp):
80
- return np.datetime64(dates, "D")
81
- else:
82
- return dates.to_numpy().astype("datetime64[D]")
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