PYield 0.8.2__tar.gz → 0.8.3__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 (32) hide show
  1. {pyield-0.8.2 → pyield-0.8.3}/PKG-INFO +1 -1
  2. pyield-0.8.3/pyield/__about__.py +1 -0
  3. pyield-0.8.2/pyield/tn_bonds.py → pyield-0.8.3/pyield/anbima.py +16 -25
  4. {pyield-0.8.2 → pyield-0.8.3}/pyield/data_access.py +3 -3
  5. {pyield-0.8.2 → pyield-0.8.3}/pyield/spreads.py +2 -2
  6. {pyield-0.8.2 → pyield-0.8.3}/pyproject.toml +1 -1
  7. pyield-0.8.2/pyield/__about__.py +0 -1
  8. {pyield-0.8.2 → pyield-0.8.3}/LICENSE +0 -0
  9. {pyield-0.8.2 → pyield-0.8.3}/README.md +0 -0
  10. {pyield-0.8.2 → pyield-0.8.3}/pyield/__init__.py +0 -0
  11. {pyield-0.8.2 → pyield-0.8.3}/pyield/bday.py +0 -0
  12. {pyield-0.8.2 → pyield-0.8.3}/pyield/date_validator.py +0 -0
  13. {pyield-0.8.2 → pyield-0.8.3}/pyield/futures/__init__.py +0 -0
  14. {pyield-0.8.2 → pyield-0.8.3}/pyield/futures/common.py +0 -0
  15. {pyield-0.8.2 → pyield-0.8.3}/pyield/futures/historical.py +0 -0
  16. {pyield-0.8.2 → pyield-0.8.3}/pyield/futures/intraday.py +0 -0
  17. {pyield-0.8.2 → pyield-0.8.3}/pyield/futures/xml.py +0 -0
  18. {pyield-0.8.2 → pyield-0.8.3}/pyield/holidays/__init__.py +0 -0
  19. {pyield-0.8.2 → pyield-0.8.3}/pyield/holidays/br_holidays_new.txt +0 -0
  20. {pyield-0.8.2 → pyield-0.8.3}/pyield/holidays/br_holidays_old.txt +0 -0
  21. {pyield-0.8.2 → pyield-0.8.3}/pyield/holidays/core.py +0 -0
  22. {pyield-0.8.2 → pyield-0.8.3}/pyield/indicators.py +0 -0
  23. {pyield-0.8.2 → pyield-0.8.3}/pyield/interpolator.py +0 -0
  24. {pyield-0.8.2 → pyield-0.8.3}/pyield/ntnb.py +0 -0
  25. {pyield-0.8.2 → pyield-0.8.3}/pyield/projections.py +0 -0
  26. {pyield-0.8.2 → pyield-0.8.3}/pyield/py.typed +0 -0
  27. {pyield-0.8.2 → pyield-0.8.3}/tests/__init__.py +0 -0
  28. {pyield-0.8.2 → pyield-0.8.3}/tests/data/SPRD231222.zip +0 -0
  29. {pyield-0.8.2 → pyield-0.8.3}/tests/data/SPRD240426.zip +0 -0
  30. {pyield-0.8.2 → pyield-0.8.3}/tests/test_bday.py +0 -0
  31. {pyield-0.8.2 → pyield-0.8.3}/tests/test_futures.py +0 -0
  32. {pyield-0.8.2 → pyield-0.8.3}/tests/test_futures_xml.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PYield
3
- Version: 0.8.2
3
+ Version: 0.8.3
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.8.3"
@@ -8,14 +8,15 @@ ANBIMA_NON_MEMBER_URL = "https://www.anbima.com.br/informacoes/merc-sec/arqs/"
8
8
  ANBIMA_MEMBER_URL = "http://www.anbima.associados.rtm/merc_sec/arqs/"
9
9
 
10
10
 
11
- def _get_anbima_content(reference_date: pd.Timestamp) -> str:
11
+ def _get_file_content(reference_date: pd.Timestamp, headers: dict = None) -> str:
12
+ headers = headers or {} # Default empty headers
12
13
  url_date = reference_date.strftime("%y%m%d")
13
14
  member_url = f"{ANBIMA_MEMBER_URL}ms{url_date}.txt"
14
15
  non_member_url = f"{ANBIMA_NON_MEMBER_URL}ms{url_date}.txt"
15
16
 
16
17
  # Tries to access the member URL first
17
18
  try:
18
- response = requests.get(member_url, timeout=5)
19
+ response = requests.get(member_url, headers=headers, timeout=5)
19
20
  # Checks if the response was successful (status code 200)
20
21
  response.raise_for_status()
21
22
  return response.text
@@ -33,14 +34,9 @@ def _get_anbima_content(reference_date: pd.Timestamp) -> str:
33
34
  return ""
34
35
 
35
36
 
36
- def _get_raw_df(reference_date: pd.Timestamp) -> pd.DataFrame:
37
- url_content = _get_anbima_content(reference_date)
38
- if url_content == "":
39
- date_str = reference_date.strftime("%d-%m-%Y")
40
- raise ValueError(f"Could not fetch ANBIMA data for {date_str}.")
41
-
42
- df = pd.read_csv(
43
- io.StringIO(url_content),
37
+ def _read_raw_df(file_content: str) -> pd.DataFrame:
38
+ return pd.read_csv(
39
+ io.StringIO(file_content),
44
40
  sep="@",
45
41
  encoding="latin-1",
46
42
  skiprows=2,
@@ -49,7 +45,6 @@ def _get_raw_df(reference_date: pd.Timestamp) -> pd.DataFrame:
49
45
  na_values=["--"],
50
46
  dtype_backend="numpy_nullable",
51
47
  )
52
- return df
53
48
 
54
49
 
55
50
  def _process_raw_df(df_raw: pd.DataFrame) -> pd.DataFrame:
@@ -95,31 +90,27 @@ def _process_raw_df(df_raw: pd.DataFrame) -> pd.DataFrame:
95
90
  return df.sort_values(["BondType", "MaturityDate"], ignore_index=True)
96
91
 
97
92
 
98
- def fetch_bonds(reference_date: pd.Timestamp, return_raw=False) -> pd.DataFrame:
93
+ def fetch_bonds(reference_date: pd.Timestamp, headers: dict = None) -> pd.DataFrame:
99
94
  """
100
95
  Fetches indicative treasury rates from ANBIMA for a specified reference date.
101
96
 
102
97
  This function retrieves the indicative rates for Brazilian treasury securities
103
98
  from ANBIMA, processing them into a structured pandas DataFrame.
104
- There is an option to return raw data directly from the source without processing.
105
99
 
106
100
  Parameters:
107
- reference_date (str | pd.Timestamp, optional): The date for which to fetch the
108
- indicative rates. If None or not provided, the function defaults to the
109
- previous business day.
110
- return_raw (bool, optional): Flag to return raw data without processing.
111
- Defaults to False.
101
+ reference_date (pd.Timestamp): The date for which to fetch the indicative rates.
112
102
 
113
103
  Returns:
114
104
  pd.DataFrame: A DataFrame containing the processed indicative rates for the
115
- given reference date, or raw data if `return_raw` is True. The processed
116
- data includes bond type, reference date, maturity date and various rates
117
- (bid, ask, indicative) among others, depending on the `return_raw` flag.
105
+ given reference date.
118
106
 
119
107
  """
120
- df = _get_raw_df(reference_date)
108
+ file_content = _get_file_content(reference_date, headers)
109
+
110
+ if file_content == "":
111
+ date_str = reference_date.strftime("%d-%m-%Y")
112
+ raise ValueError(f"Could not fetch ANBIMA data for {date_str}.")
121
113
 
122
- if not return_raw:
123
- df = _process_raw_df(df)
114
+ df = _read_raw_df(file_content)
124
115
 
125
- return df
116
+ return _process_raw_df(df)
@@ -1,11 +1,11 @@
1
1
  import pandas as pd
2
2
 
3
+ from . import anbima as an
3
4
  from . import date_validator as dv
4
5
  from . import futures as ft
5
6
  from . import indicators as it
6
7
  from . import projections as pr
7
8
  from . import spreads as sp
8
- from . import tn_bonds as tb
9
9
 
10
10
 
11
11
  def fetch_asset(
@@ -55,10 +55,10 @@ def fetch_asset(
55
55
  return ft.fetch_intraday_df(future_code=asset_code.upper())
56
56
 
57
57
  if asset_code.upper() == "TRB":
58
- return tb.fetch_bonds(reference_date=normalized_date)
58
+ return an.fetch_bonds(reference_date=normalized_date)
59
59
 
60
60
  if asset_code.upper() in SUPPORTED_BONDS:
61
- df_bond = tb.fetch_bonds(reference_date=normalized_date)
61
+ df_bond = an.fetch_bonds(reference_date=normalized_date)
62
62
  df_bond.query(f"BondType == '{asset_code.upper()}'", inplace=True)
63
63
  # Return the DataFrame sorted by maturity date
64
64
  return df_bond.sort_values("MaturityDate", ignore_index=True)
@@ -1,6 +1,6 @@
1
1
  import pandas as pd
2
2
 
3
- from . import tn_bonds as tb
3
+ from . import anbima as an
4
4
  from .futures import historical as fh
5
5
 
6
6
  # Constant for conversion to basis points
@@ -38,7 +38,7 @@ def calculate_di_spreads(reference_date: pd.Timestamp) -> pd.DataFrame:
38
38
  df_di["MaturityDate"] = df_di["MaturityDate"].dt.to_period("M").dt.to_timestamp()
39
39
 
40
40
  # Fetch bond rates, filtering for LTN and NTN-F types
41
- df_anbima = tb.fetch_bonds(reference_date, False)
41
+ df_anbima = an.fetch_bonds(reference_date, False)
42
42
  df_anbima.query("BondType in ['LTN', 'NTN-F']", inplace=True)
43
43
 
44
44
  # Merge bond and DI rates by maturity date to calculate spreads
@@ -32,7 +32,7 @@ dependencies = [
32
32
  "requests>=2.31.0",
33
33
  ]
34
34
  dynamic = []
35
- version = "0.8.2"
35
+ version = "0.8.3"
36
36
 
37
37
  [project.license]
38
38
  file = "LICENSE"
@@ -1 +0,0 @@
1
- __version__ = "0.8.2"
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