PYield 0.9.1__tar.gz → 0.9.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.
- {pyield-0.9.1 → pyield-0.9.3}/PKG-INFO +1 -1
- pyield-0.9.3/pyield/__about__.py +1 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/bday.py +2 -2
- {pyield-0.9.1 → pyield-0.9.3}/pyield/fetchers/anbima.py +11 -12
- {pyield-0.9.1 → pyield-0.9.3}/pyield/fetchers/indicators.py +6 -6
- {pyield-0.9.1 → pyield-0.9.3}/pyield/fetchers/projections.py +3 -3
- {pyield-0.9.1 → pyield-0.9.3}/pyield/ntnb.py +6 -14
- {pyield-0.9.1 → pyield-0.9.3}/pyield/spreads.py +2 -2
- {pyield-0.9.1 → pyield-0.9.3}/pyproject.toml +1 -1
- pyield-0.9.1/pyield/__about__.py +0 -1
- {pyield-0.9.1 → pyield-0.9.3}/LICENSE +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/README.md +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/__init__.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/date_validator.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/fetchers/__init__.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/fetchers/futures/__init__.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/fetchers/futures/common.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/fetchers/futures/historical.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/fetchers/futures/intraday.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/fetchers/futures/xml.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/holidays/__init__.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/holidays/br_holidays_new.txt +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/holidays/br_holidays_old.txt +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/holidays/holidays_manager.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/interpolators.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/pyield/py.typed +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/tests/__init__.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/tests/data/SPRD231222.zip +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/tests/data/SPRD240426.zip +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/tests/test_bday.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/tests/test_futures.py +0 -0
- {pyield-0.9.1 → pyield-0.9.3}/tests/test_futures_xml.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.9.3"
|
|
@@ -176,9 +176,9 @@ def offset(
|
|
|
176
176
|
# Force to datetime[ns] if the input was a single date
|
|
177
177
|
result = result.as_unit("ns")
|
|
178
178
|
else:
|
|
179
|
-
|
|
179
|
+
result_dti = pd.to_datetime(offsetted_dates_np)
|
|
180
180
|
# Force the result to be a Series if the input was not a single date
|
|
181
|
-
result = pd.Series(
|
|
181
|
+
result = pd.Series(result_dti).astype("datetime64[ns]")
|
|
182
182
|
|
|
183
183
|
return result
|
|
184
184
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import io
|
|
2
|
+
import os
|
|
2
3
|
|
|
3
4
|
import pandas as pd
|
|
4
5
|
import requests
|
|
@@ -10,21 +11,22 @@ ANBIMA_URL = "https://www.anbima.com.br/informacoes/merc-sec/arqs/"
|
|
|
10
11
|
# URL example: https://www.anbima.com.br/informacoes/merc-sec/arqs/ms240614.txt
|
|
11
12
|
|
|
12
13
|
|
|
13
|
-
def _get_file_content(reference_date: pd.Timestamp
|
|
14
|
+
def _get_file_content(reference_date: pd.Timestamp) -> str:
|
|
14
15
|
url_date = reference_date.strftime("%y%m%d")
|
|
15
16
|
filename = f"ms{url_date}.txt"
|
|
16
17
|
|
|
17
18
|
# Tries to access the member URL first
|
|
18
19
|
try:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
anbima_base_url = os.getenv("ANBIMA_URL")
|
|
21
|
+
if anbima_base_url:
|
|
22
|
+
anbima_member_url = f"{anbima_base_url}/merc_sec/arqs/"
|
|
23
|
+
anbima_headers = {"private-token": os.getenv("ANBIMA_TOEKN")}
|
|
22
24
|
else:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
anbima_member_url = "http://www.anbima.associados.rtm/merc_sec/arqs/"
|
|
26
|
+
anbima_headers = None
|
|
25
27
|
|
|
26
|
-
file_url = f"{
|
|
27
|
-
response = requests.get(file_url, headers=
|
|
28
|
+
file_url = f"{anbima_member_url}{filename}"
|
|
29
|
+
response = requests.get(file_url, headers=anbima_headers, timeout=5)
|
|
28
30
|
# Checks if the response was successful (status code 200)
|
|
29
31
|
response.raise_for_status()
|
|
30
32
|
return response.text
|
|
@@ -90,7 +92,6 @@ def _process_raw_df(df_raw: pd.DataFrame) -> pd.DataFrame:
|
|
|
90
92
|
def anbima(
|
|
91
93
|
reference_date: str | pd.Timestamp | None = None,
|
|
92
94
|
bond_type: str | list[str] | None = None,
|
|
93
|
-
remote_access: dict = None,
|
|
94
95
|
) -> pd.DataFrame:
|
|
95
96
|
"""
|
|
96
97
|
Fetches indicative treasury rates from ANBIMA for a specified reference date.
|
|
@@ -103,8 +104,6 @@ def anbima(
|
|
|
103
104
|
fetch the indicative rates. If a string is provided, it should be in the
|
|
104
105
|
format 'dd-mm-yyyy'. Defaults last business day if None.
|
|
105
106
|
bond_type (str, optional): The type of bond to filter by. Defaults to None.
|
|
106
|
-
remote_access (dict, optional): Dictionary containing remote access parameters.
|
|
107
|
-
Defaults to None.
|
|
108
107
|
|
|
109
108
|
Returns:
|
|
110
109
|
pd.DataFrame: A DataFrame containing the processed indicative rates for the
|
|
@@ -122,7 +121,7 @@ def anbima(
|
|
|
122
121
|
"""
|
|
123
122
|
# Normalize the reference date
|
|
124
123
|
normalized_date = dv.normalize_date(reference_date)
|
|
125
|
-
file_content = _get_file_content(normalized_date
|
|
124
|
+
file_content = _get_file_content(normalized_date)
|
|
126
125
|
|
|
127
126
|
if not file_content:
|
|
128
127
|
date_str = normalized_date.strftime("%d-%m-%Y")
|
|
@@ -10,17 +10,17 @@ def indicator(
|
|
|
10
10
|
indicator_type: Literal["IPCA_MR", "SELIC_TARGET", "DI", "VNA_LFT"],
|
|
11
11
|
reference_date: str | pd.Timestamp | None = None,
|
|
12
12
|
) -> float | None:
|
|
13
|
-
|
|
14
|
-
if
|
|
13
|
+
ind_type = str(indicator_type).upper()
|
|
14
|
+
if ind_type == "IPCA_MR":
|
|
15
15
|
return ipca_monthly_rate(reference_date)
|
|
16
|
-
elif
|
|
16
|
+
elif ind_type == "SELIC_TARGET":
|
|
17
17
|
return selic_target(reference_date)
|
|
18
|
-
elif
|
|
18
|
+
elif ind_type == "DI":
|
|
19
19
|
return di(reference_date)
|
|
20
|
-
elif
|
|
20
|
+
elif ind_type == "VNA_LFT":
|
|
21
21
|
return vna_lft(reference_date)
|
|
22
22
|
else:
|
|
23
|
-
raise ValueError(f"Invalid indicator type: {
|
|
23
|
+
raise ValueError(f"Invalid indicator type: {ind_type}")
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
def ipca_monthly_rate(reference_date: str | pd.Timestamp | None = None) -> float | None:
|
|
@@ -17,11 +17,11 @@ class IndicatorProjection:
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def projection(projection_type: Literal["IPCA_CM"]) -> IndicatorProjection:
|
|
20
|
-
|
|
21
|
-
if
|
|
20
|
+
proj_type = str(projection_type).upper()
|
|
21
|
+
if proj_type == "IPCA_CM":
|
|
22
22
|
return ipca_current_month()
|
|
23
23
|
else:
|
|
24
|
-
raise ValueError(f"Invalid projection type: {
|
|
24
|
+
raise ValueError(f"Invalid projection type: {proj_type}")
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def ipca_current_month() -> IndicatorProjection:
|
|
@@ -87,14 +87,12 @@ def coupon_dates_map(
|
|
|
87
87
|
# Generate coupon dates
|
|
88
88
|
dates = pd.date_range(start=first_coupon_date, end=end, freq="3MS")
|
|
89
89
|
|
|
90
|
-
# Convert to pandas Series since pd.date_range returns a DatetimeIndex
|
|
91
|
-
dates = pd.Series(dates)
|
|
92
|
-
|
|
93
90
|
# Offset dates by 14 in order to have day 15 of the month
|
|
94
91
|
dates += pd.Timedelta(days=14)
|
|
95
92
|
|
|
96
93
|
# First coupon date must be after the reference date
|
|
97
|
-
|
|
94
|
+
dates = dates[dates >= start]
|
|
95
|
+
return pd.Series(dates).reset_index(drop=True)
|
|
98
96
|
|
|
99
97
|
|
|
100
98
|
def coupon_dates(
|
|
@@ -128,14 +126,8 @@ def coupon_dates(
|
|
|
128
126
|
# Move the coupon date back 6 months
|
|
129
127
|
coupon_date -= pd.DateOffset(months=6)
|
|
130
128
|
|
|
131
|
-
#
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
# Sort the coupon dates in ascending order
|
|
135
|
-
coupon_dates = coupon_dates.sort_values(ignore_index=True)
|
|
136
|
-
|
|
137
|
-
# Force a index reset to avoid issues with the index
|
|
138
|
-
return coupon_dates.reset_index(drop=True)
|
|
129
|
+
# Return the coupon dates as a sorted Series
|
|
130
|
+
return pd.Series(coupon_dates).sort_values(ignore_index=True)
|
|
139
131
|
|
|
140
132
|
|
|
141
133
|
def quotation(
|
|
@@ -309,7 +301,7 @@ def _get_nsr_df(reference_date: pd.Timestamp) -> pd.DataFrame:
|
|
|
309
301
|
Returns:
|
|
310
302
|
pd.DataFrame: DataFrame containing the NIR data for NTN-B bonds.
|
|
311
303
|
"""
|
|
312
|
-
df = futures
|
|
304
|
+
df = futures(contract_code="DI1", reference_date=reference_date)
|
|
313
305
|
if "CurrentRate" in df.columns:
|
|
314
306
|
df = df.rename(columns={"CurrentRate": "NSR_DI"})
|
|
315
307
|
keep_cols = [
|
|
@@ -342,7 +334,7 @@ def _get_nsr_df(reference_date: pd.Timestamp) -> pd.DataFrame:
|
|
|
342
334
|
if reference_date == today:
|
|
343
335
|
# If the reference date is today, use the previous business day
|
|
344
336
|
anbima_date = bday.offset(reference_date, -1)
|
|
345
|
-
df_pre = spread
|
|
337
|
+
df_pre = spread(spread_type="DI_PRE", reference_date=anbima_date)
|
|
346
338
|
df_pre.query("BondType == 'LTN'", inplace=True)
|
|
347
339
|
df_pre["MaturityDate"] = bday.offset(df_pre["MaturityDate"], 0)
|
|
348
340
|
df_pre["DISpread"] /= 10_000 # Remove BPS (basis points) from the spread
|
|
@@ -38,9 +38,9 @@ def spread(
|
|
|
38
38
|
Example:
|
|
39
39
|
>>> spread("DI_PRE", "2024-06-18")
|
|
40
40
|
"""
|
|
41
|
-
|
|
41
|
+
spread_type_cap = str(spread_type).upper()
|
|
42
42
|
normalized_date = dv.normalize_date(reference_date)
|
|
43
|
-
if
|
|
43
|
+
if spread_type_cap == "DI_PRE":
|
|
44
44
|
return di_pre(normalized_date)
|
|
45
45
|
else:
|
|
46
46
|
raise ValueError(f"Unsupported spread type: {spread_type}")
|
pyield-0.9.1/pyield/__about__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.9.1"
|
|
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
|