PYield 0.35.8__tar.gz → 0.35.9__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.35.8 → pyield-0.35.9}/PKG-INFO +1 -1
- pyield-0.35.9/pyield/__about__.py +1 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/bday.py +128 -95
- pyield-0.35.8/pyield/__about__.py +0 -1
- {pyield-0.35.8 → pyield-0.35.9}/.gitignore +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/LICENSE +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/README.md +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/__init__.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/anbima/__init__.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/anbima/ettj.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/anbima/ima.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/anbima/imaq.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/anbima/ipca.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/anbima/tpf.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/b3/__init__.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/b3/di1.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/b3/di_over.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/b3/futures/__init__.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/b3/futures/common.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/b3/futures/historical.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/b3/futures/intraday.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/b3/futures/xml.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/bc/__init__.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/bc/auction.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/bc/bcdata.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/bc/ptax.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/bc/repo.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/bc/trades_intraday.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/bc/trades_monthly.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/bc/vna.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/conftest.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/data_cache.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/date_converter.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/fwd.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/holidays/__init__.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/holidays/br_holidays_new.txt +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/holidays/br_holidays_old.txt +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/holidays/brholidays.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/ibge/__init__.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/ibge/ipca.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/interpolator.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/py.typed +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/retry.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/tn/__init__.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/tn/auction.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/tn/lft.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/tn/ltn.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/tn/ntnb.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/tn/ntnc.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/tn/ntnf.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyield/tn/tools.py +0 -0
- {pyield-0.35.8 → pyield-0.35.9}/pyproject.toml +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.35.9"
|
|
@@ -44,7 +44,7 @@ def offset(
|
|
|
44
44
|
) -> pd.Series: ...
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
def offset(
|
|
47
|
+
def offset( # noqa
|
|
48
48
|
dates: DateScalar | DateArray,
|
|
49
49
|
offset: IntegerScalar | IntegerArray,
|
|
50
50
|
roll: Literal["forward", "backward"] = "forward",
|
|
@@ -56,8 +56,11 @@ def offset(
|
|
|
56
56
|
dates. It is a wrapper for `numpy.busday_offset` adapted for Pandas data types and
|
|
57
57
|
brazilian holidays.
|
|
58
58
|
|
|
59
|
-
**Important Note:**
|
|
60
|
-
holidays applies to the calculation.
|
|
59
|
+
**Important Note:** Each date in the `dates` input is evaluated individually to
|
|
60
|
+
determine which list of holidays applies to the calculation. Transition date
|
|
61
|
+
is 2023-12-26, which means:
|
|
62
|
+
- Dates before 2023-12-26 use the old holiday list.
|
|
63
|
+
- Dates on or after 2023-12-26 use the new holiday list.
|
|
61
64
|
|
|
62
65
|
Args:
|
|
63
66
|
dates (DateScalar | DateArray): The date(s) to offset. Can be a scalar date type
|
|
@@ -150,6 +153,18 @@ def offset(
|
|
|
150
153
|
1 NaT
|
|
151
154
|
dtype: datetime64[ns]
|
|
152
155
|
|
|
156
|
+
Original pandas index is preserved
|
|
157
|
+
|
|
158
|
+
>>> dates = pd.Series(
|
|
159
|
+
... ["19-09-2024", "20-09-2024", "21-09-2024"],
|
|
160
|
+
... index=["a", "b", "c"],
|
|
161
|
+
... )
|
|
162
|
+
>>> bday.offset(dates, 1)
|
|
163
|
+
a 2024-09-20
|
|
164
|
+
b 2024-09-23
|
|
165
|
+
c 2024-09-24
|
|
166
|
+
dtype: datetime64[ns]
|
|
167
|
+
|
|
153
168
|
Note:
|
|
154
169
|
This function uses `numpy.busday_offset` under the hood, which means it follows
|
|
155
170
|
the same conventions and limitations for business day calculations. For detailed
|
|
@@ -157,70 +172,89 @@ def offset(
|
|
|
157
172
|
documentation:
|
|
158
173
|
https://numpy.org/doc/stable/reference/generated/numpy.busday_offset.html
|
|
159
174
|
"""
|
|
175
|
+
# Padroniza as entradas para objetos do Pandas
|
|
160
176
|
dates_pd = dc.convert_input_dates(dates)
|
|
177
|
+
offset_pd = pd.Series(offset) if isinstance(offset, IntegerArray) else offset
|
|
178
|
+
|
|
179
|
+
# 1. VALIDAÇÃO ESTRUTURAL
|
|
180
|
+
if isinstance(dates_pd, pd.Series) and isinstance(offset_pd, pd.Series):
|
|
181
|
+
if not dates_pd.index.equals(offset_pd.index):
|
|
182
|
+
raise ValueError("Input dates have different indices!")
|
|
183
|
+
|
|
184
|
+
is_scalar_input = not (
|
|
185
|
+
isinstance(dates_pd, pd.Series) or isinstance(offset_pd, pd.Series)
|
|
186
|
+
)
|
|
161
187
|
|
|
162
|
-
#
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
else:
|
|
188
|
+
# 2. LÓGICA PRINCIPAL
|
|
189
|
+
|
|
190
|
+
# --- CASO 1: AMBOS OS INPUTS SÃO ESCALARES
|
|
191
|
+
if is_scalar_input:
|
|
192
|
+
if pd.isna(dates_pd) or pd.isna(offset_pd):
|
|
168
193
|
return pd.NaT
|
|
169
194
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
new_dates = dates_pd[dates_pd >= br_holidays.TRANSITION_DATE]
|
|
174
|
-
# nat = NaT = Not a Time = missing value
|
|
175
|
-
nat_dates = dates_pd[dates_pd.isna()]
|
|
176
|
-
|
|
177
|
-
offsetted_old_dates = np.busday_offset(
|
|
178
|
-
dc.to_numpy_date_type(old_dates),
|
|
179
|
-
offsets=offset,
|
|
195
|
+
offsetted_date_np = np.busday_offset(
|
|
196
|
+
dc.to_numpy_date_type(dates_pd),
|
|
197
|
+
offsets=offset_pd,
|
|
180
198
|
roll=roll,
|
|
181
|
-
holidays=
|
|
199
|
+
holidays=br_holidays.get_holiday_array(dates_pd),
|
|
182
200
|
)
|
|
183
201
|
|
|
184
|
-
|
|
185
|
-
dc.to_numpy_date_type(new_dates),
|
|
186
|
-
offsets=offset,
|
|
187
|
-
roll=roll,
|
|
188
|
-
holidays=NEW_HOLIDAYS_ARRAY,
|
|
189
|
-
)
|
|
202
|
+
return pd.Timestamp(offsetted_date_np).as_unit("ns")
|
|
190
203
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
204
|
+
# --- CASO 2: PELO MENOS UM DOS INPUTS É UMA SÉRIE ---
|
|
205
|
+
if isinstance(dates_pd, pd.Series) or isinstance(offset_pd, pd.Series):
|
|
206
|
+
# Garante que ambas as variáveis sejam Series para alinhamento automático.
|
|
207
|
+
# O Pandas faz o "broadcast" do escalar para o tamanho da Series.
|
|
208
|
+
if not isinstance(dates_pd, pd.Series):
|
|
209
|
+
# dates escalar e offset Series -> Series de dates com o índice de offset.
|
|
210
|
+
dates_pd = pd.Series(dates_pd, index=offset_pd.index)
|
|
211
|
+
if not isinstance(offset_pd, pd.Series):
|
|
212
|
+
# offset escalar e dates Series -> Series de offset com o índice de dates.
|
|
213
|
+
offset_pd = pd.Series(offset_pd, index=dates_pd.index)
|
|
194
214
|
|
|
195
|
-
#
|
|
196
|
-
|
|
197
|
-
offsetted_new_dates = pd.Series(offsetted_new_dates).astype("datetime64[ns]")
|
|
215
|
+
# Inicializa a série de resultados com o índice correto e tipo que suporta NaT.
|
|
216
|
+
result = pd.Series(index=dates_pd.index, dtype="datetime64[ns]")
|
|
198
217
|
|
|
199
|
-
#
|
|
200
|
-
|
|
201
|
-
|
|
218
|
+
# Divide the input in order to apply the correct holiday list
|
|
219
|
+
mask_not_null = dates_pd.notna() & offset_pd.notna()
|
|
220
|
+
mask_old_holidays = mask_not_null & (dates_pd < br_holidays.TRANSITION_DATE)
|
|
221
|
+
mask_new_holidays = mask_not_null & (dates_pd >= br_holidays.TRANSITION_DATE)
|
|
202
222
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
223
|
+
if mask_old_holidays.any():
|
|
224
|
+
np_offset_values = np.busday_offset(
|
|
225
|
+
dates=dc.to_numpy_date_type(dates_pd[mask_old_holidays]),
|
|
226
|
+
offsets=offset_pd[mask_old_holidays],
|
|
227
|
+
roll=roll,
|
|
228
|
+
holidays=OLD_HOLIDAYS_ARRAY,
|
|
229
|
+
)
|
|
230
|
+
pd_offset_values = pd.to_datetime(np_offset_values).astype("datetime64[ns]")
|
|
231
|
+
result.loc[mask_old_holidays] = pd_offset_values
|
|
206
232
|
|
|
207
|
-
|
|
208
|
-
|
|
233
|
+
if mask_new_holidays.any():
|
|
234
|
+
np_offset_values = np.busday_offset(
|
|
235
|
+
dates=dc.to_numpy_date_type(dates_pd[mask_new_holidays]),
|
|
236
|
+
offsets=offset_pd[mask_new_holidays],
|
|
237
|
+
roll=roll,
|
|
238
|
+
holidays=NEW_HOLIDAYS_ARRAY,
|
|
239
|
+
)
|
|
240
|
+
pd_offset_values = pd.to_datetime(np_offset_values).astype("datetime64[ns]")
|
|
241
|
+
result.loc[mask_new_holidays] = pd_offset_values
|
|
209
242
|
|
|
210
|
-
|
|
211
|
-
offsetted_dates_np = np.busday_offset(
|
|
212
|
-
dc.to_numpy_date_type(dates_pd),
|
|
213
|
-
offsets=offset,
|
|
214
|
-
roll=roll,
|
|
215
|
-
holidays=br_holidays.get_holiday_array(dates_pd),
|
|
216
|
-
)
|
|
217
|
-
if isinstance(offsetted_dates_np, np.datetime64):
|
|
218
|
-
return pd.Timestamp(offsetted_dates_np).as_unit("ns")
|
|
219
|
-
else:
|
|
220
|
-
return pd.Series(offsetted_dates_np).astype("datetime64[ns]")
|
|
243
|
+
return result
|
|
221
244
|
|
|
222
|
-
|
|
223
|
-
|
|
245
|
+
# --- CASO 3: A ENTRADA 'dates' É UM ESCALAR E 'offset' É UMA SÉRIE ---
|
|
246
|
+
result = pd.Series(index=offset_pd.index, dtype="datetime64[ns]")
|
|
247
|
+
offset_dates_np = np.busday_offset(
|
|
248
|
+
dates=dc.to_numpy_date_type(dates_pd),
|
|
249
|
+
offsets=offset_pd,
|
|
250
|
+
roll=roll,
|
|
251
|
+
holidays=br_holidays.get_holiday_array(dates_pd),
|
|
252
|
+
)
|
|
253
|
+
# Convert from numpy.datetime64 to datetime64[ns] (pandas format)
|
|
254
|
+
offset_dates_pd = pd.to_datetime(offset_dates_np).astype("datetime64[ns]")
|
|
255
|
+
return pd.Series(
|
|
256
|
+
offset_dates_pd.values, index=offset_pd.index, dtype="datetime64[ns]"
|
|
257
|
+
)
|
|
224
258
|
|
|
225
259
|
|
|
226
260
|
@overload
|
|
@@ -250,8 +284,11 @@ def count( # noqa
|
|
|
250
284
|
on the inputs. It accounts for specified holidays, effectively excluding them from
|
|
251
285
|
the business day count.
|
|
252
286
|
|
|
253
|
-
**Important Note:**
|
|
254
|
-
applies to the calculation.
|
|
287
|
+
**Important Note:** Each date in the `start` input is evaluated individually to
|
|
288
|
+
determine which list of holidays (old or new) applies to the calculation. The
|
|
289
|
+
transition date is 2023-12-26, which means:
|
|
290
|
+
- Dates before 2023-12-26 use the old holiday list.
|
|
291
|
+
- Dates on or after 2023-12-26 use the new holiday list.
|
|
255
292
|
|
|
256
293
|
Args:
|
|
257
294
|
start (DateScalar | DateArray): The start date(s) for counting (inclusive).
|
|
@@ -333,8 +370,6 @@ def count( # noqa
|
|
|
333
370
|
|
|
334
371
|
# 1. VALIDAÇÃO ESTRUTURAL
|
|
335
372
|
if isinstance(start_pd, pd.Series) and isinstance(end_pd, pd.Series):
|
|
336
|
-
if len(start_pd) != len(end_pd):
|
|
337
|
-
raise ValueError("Input Series must have the same length.")
|
|
338
373
|
if not start_pd.index.equals(end_pd.index):
|
|
339
374
|
raise ValueError("Input dates have different indices!")
|
|
340
375
|
|
|
@@ -348,53 +383,51 @@ def count( # noqa
|
|
|
348
383
|
if pd.isna(start_pd) or pd.isna(end_pd):
|
|
349
384
|
return pd.NA
|
|
350
385
|
|
|
351
|
-
holidays = br_holidays.get_holiday_array(start_pd)
|
|
352
386
|
result = np.busday_count(
|
|
353
387
|
begindates=dc.to_numpy_date_type(start_pd),
|
|
354
388
|
enddates=dc.to_numpy_date_type(end_pd),
|
|
355
|
-
holidays=
|
|
389
|
+
holidays=br_holidays.get_holiday_array(start_pd),
|
|
356
390
|
)
|
|
357
391
|
return int(result)
|
|
358
392
|
|
|
359
393
|
# --- CASO 2: PELO MENOS UMA ENTRADA É UMA SÉRIE ---
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
)
|
|
394
|
+
# Garante que ambas as variáveis sejam Series para alinhamento automático.
|
|
395
|
+
# O Pandas faz o "broadcast" do escalar para o tamanho da Series.
|
|
396
|
+
if not isinstance(start_pd, pd.Series):
|
|
397
|
+
# start escalar e end Series: cria uma Series de start com o índice de end.
|
|
398
|
+
start_pd = pd.Series(start_pd, index=end_pd.index)
|
|
399
|
+
if not isinstance(end_pd, pd.Series):
|
|
400
|
+
# end escalar e start Series: cria uma Series de end com o índice de start.
|
|
401
|
+
end_pd = pd.Series(end_pd, index=start_pd.index)
|
|
402
|
+
|
|
403
|
+
# Inicializa a série de resultados com o índice correto e tipo que suporta NA.
|
|
404
|
+
# Nulos nas entradas (start_pd ou end_pd) resultarão em NA aqui.
|
|
405
|
+
result = pd.Series(index=start_pd.index, dtype="Int64")
|
|
406
|
+
|
|
407
|
+
# Cria máscaras para linhas não-nulas, divididas pelo calendário de feriados.
|
|
408
|
+
# A lógica de feriados depende APENAS da data de início.
|
|
409
|
+
not_null_mask = start_pd.notna() & end_pd.notna()
|
|
410
|
+
mask_old_holidays = not_null_mask & (start_pd < br_holidays.TRANSITION_DATE)
|
|
411
|
+
mask_new_holidays = not_null_mask & (start_pd >= br_holidays.TRANSITION_DATE)
|
|
412
|
+
|
|
413
|
+
# Calcula e atribui os resultados para o subconjunto "OLD"
|
|
414
|
+
if mask_old_holidays.any():
|
|
415
|
+
result.loc[mask_old_holidays] = np.busday_count(
|
|
416
|
+
begindates=dc.to_numpy_date_type(start_pd[mask_old_holidays]),
|
|
417
|
+
enddates=dc.to_numpy_date_type(end_pd[mask_old_holidays]),
|
|
418
|
+
holidays=OLD_HOLIDAYS_ARRAY,
|
|
419
|
+
)
|
|
387
420
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
421
|
+
# Calcula e atribui os resultados para o subconjunto "NEW"
|
|
422
|
+
if mask_new_holidays.any():
|
|
423
|
+
result.loc[mask_new_holidays] = np.busday_count(
|
|
424
|
+
begindates=dc.to_numpy_date_type(start_pd[mask_new_holidays]),
|
|
425
|
+
enddates=dc.to_numpy_date_type(end_pd[mask_new_holidays]),
|
|
426
|
+
holidays=NEW_HOLIDAYS_ARRAY,
|
|
427
|
+
)
|
|
395
428
|
|
|
396
|
-
|
|
397
|
-
|
|
429
|
+
# As linhas onde not_null_mask era False já contêm o valor <NA> default.
|
|
430
|
+
return result
|
|
398
431
|
|
|
399
432
|
|
|
400
433
|
def generate(
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.35.8"
|
|
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
|
|
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
|