PYield 0.41.0__tar.gz → 0.41.1__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 (61) hide show
  1. {pyield-0.41.0 → pyield-0.41.1}/PKG-INFO +6 -19
  2. {pyield-0.41.0 → pyield-0.41.1}/README.md +3 -15
  3. pyield-0.41.1/pyield/__about__.py +1 -0
  4. {pyield-0.41.0 → pyield-0.41.1}/pyield/bc/auction.py +27 -28
  5. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/auctions.py +4 -1
  6. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/lft.py +2 -0
  7. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/ltn.py +3 -0
  8. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/ntnb.py +29 -10
  9. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/ntnb1.py +5 -2
  10. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/ntnbprinc.py +5 -2
  11. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/ntnc.py +10 -0
  12. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/ntnf.py +18 -10
  13. {pyield-0.41.0 → pyield-0.41.1}/pyproject.toml +3 -5
  14. pyield-0.41.0/pyield/__about__.py +0 -1
  15. {pyield-0.41.0 → pyield-0.41.1}/.gitignore +0 -0
  16. {pyield-0.41.0 → pyield-0.41.1}/LICENSE +0 -0
  17. {pyield-0.41.0 → pyield-0.41.1}/pyield/__init__.py +0 -0
  18. {pyield-0.41.0 → pyield-0.41.1}/pyield/anbima/__init__.py +0 -0
  19. {pyield-0.41.0 → pyield-0.41.1}/pyield/anbima/difusao.py +0 -0
  20. {pyield-0.41.0 → pyield-0.41.1}/pyield/anbima/ettj_intraday.py +0 -0
  21. {pyield-0.41.0 → pyield-0.41.1}/pyield/anbima/ettj_last.py +0 -0
  22. {pyield-0.41.0 → pyield-0.41.1}/pyield/anbima/ima.py +0 -0
  23. {pyield-0.41.0 → pyield-0.41.1}/pyield/anbima/imaq.py +0 -0
  24. {pyield-0.41.0 → pyield-0.41.1}/pyield/anbima/tpf.py +0 -0
  25. {pyield-0.41.0 → pyield-0.41.1}/pyield/b3/__init__.py +0 -0
  26. {pyield-0.41.0 → pyield-0.41.1}/pyield/b3/di1.py +0 -0
  27. {pyield-0.41.0 → pyield-0.41.1}/pyield/b3/di_over.py +0 -0
  28. {pyield-0.41.0 → pyield-0.41.1}/pyield/b3/futures/__init__.py +0 -0
  29. {pyield-0.41.0 → pyield-0.41.1}/pyield/b3/futures/common.py +0 -0
  30. {pyield-0.41.0 → pyield-0.41.1}/pyield/b3/futures/historical.py +0 -0
  31. {pyield-0.41.0 → pyield-0.41.1}/pyield/b3/futures/intraday.py +0 -0
  32. {pyield-0.41.0 → pyield-0.41.1}/pyield/b3/futures/xml.py +0 -0
  33. {pyield-0.41.0 → pyield-0.41.1}/pyield/bc/__init__.py +0 -0
  34. {pyield-0.41.0 → pyield-0.41.1}/pyield/bc/ptax_api.py +0 -0
  35. {pyield-0.41.0 → pyield-0.41.1}/pyield/bc/rates.py +0 -0
  36. {pyield-0.41.0 → pyield-0.41.1}/pyield/bc/repo.py +0 -0
  37. {pyield-0.41.0 → pyield-0.41.1}/pyield/bc/trades_intraday.py +0 -0
  38. {pyield-0.41.0 → pyield-0.41.1}/pyield/bc/trades_monthly.py +0 -0
  39. {pyield-0.41.0 → pyield-0.41.1}/pyield/bc/vna.py +0 -0
  40. {pyield-0.41.0 → pyield-0.41.1}/pyield/bday/__init__.py +0 -0
  41. {pyield-0.41.0 → pyield-0.41.1}/pyield/bday/core.py +0 -0
  42. {pyield-0.41.0 → pyield-0.41.1}/pyield/bday/holidays/__init__.py +0 -0
  43. {pyield-0.41.0 → pyield-0.41.1}/pyield/bday/holidays/br_holidays_new.txt +0 -0
  44. {pyield-0.41.0 → pyield-0.41.1}/pyield/bday/holidays/br_holidays_old.txt +0 -0
  45. {pyield-0.41.0 → pyield-0.41.1}/pyield/bday/holidays/brholidays.py +0 -0
  46. {pyield-0.41.0 → pyield-0.41.1}/pyield/config.py +0 -0
  47. {pyield-0.41.0 → pyield-0.41.1}/pyield/conftest.py +0 -0
  48. {pyield-0.41.0 → pyield-0.41.1}/pyield/converters.py +0 -0
  49. {pyield-0.41.0 → pyield-0.41.1}/pyield/data_cache.py +0 -0
  50. {pyield-0.41.0 → pyield-0.41.1}/pyield/fwd.py +0 -0
  51. {pyield-0.41.0 → pyield-0.41.1}/pyield/interpolator.py +0 -0
  52. {pyield-0.41.0 → pyield-0.41.1}/pyield/ipca/__init__.py +0 -0
  53. {pyield-0.41.0 → pyield-0.41.1}/pyield/ipca/historical.py +0 -0
  54. {pyield-0.41.0 → pyield-0.41.1}/pyield/ipca/projected.py +0 -0
  55. {pyield-0.41.0 → pyield-0.41.1}/pyield/py.typed +0 -0
  56. {pyield-0.41.0 → pyield-0.41.1}/pyield/retry.py +0 -0
  57. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/__init__.py +0 -0
  58. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/benchmark.py +0 -0
  59. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/pre.py +0 -0
  60. {pyield-0.41.0 → pyield-0.41.1}/pyield/tn/tools.py +0 -0
  61. {pyield-0.41.0 → pyield-0.41.1}/pyield/types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PYield
3
- Version: 0.41.0
3
+ Version: 0.41.1
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>
@@ -33,9 +33,8 @@ Classifier: Operating System :: OS Independent
33
33
  Classifier: Programming Language :: Python :: 3
34
34
  Classifier: Topic :: Office/Business :: Financial :: Investment
35
35
  Requires-Python: >=3.11
36
- Requires-Dist: numpy>=2.0.0
37
- Requires-Dist: pandas[html,parquet]>=2.0.0
38
- Requires-Dist: polars>=1.33.0
36
+ Requires-Dist: pandas[html]>=2.0.0
37
+ Requires-Dist: polars[numpy,pyarrow]>=1.33.0
39
38
  Requires-Dist: requests>=2.31.0
40
39
  Requires-Dist: tenacity>=9.0.0
41
40
  Description-Content-Type: text/markdown
@@ -289,18 +288,6 @@ Series: 'bdays' [i64]
289
288
  ]
290
289
  ```
291
290
 
292
- ### Pandas Interop
293
- Polars objects are the canonical return types. Convert explicitly when you need pandas:
294
- ```python
295
- df_pandas = df.to_pandas(use_pyarrow_extension_array=True)
296
- series_pandas = s.to_pandas(use_pyarrow_extension_array=True)
297
- ```
298
-
299
- ### Rationale
300
- Using Polars + Arrow dtypes provides:
301
- * Deterministic schema & faster IO
302
- * Efficient vectorized date casting
303
- * Clear null vs. missing semantics
304
- * Reduced overhead vs. repeated Pandas conversions
305
-
306
- These conventions keep public APIs flexible on input while consistent on output.
291
+ ## Tests
292
+ To run the test suite, use the following command:
293
+ pytest pyield --doctest-modules
@@ -247,18 +247,6 @@ Series: 'bdays' [i64]
247
247
  ]
248
248
  ```
249
249
 
250
- ### Pandas Interop
251
- Polars objects are the canonical return types. Convert explicitly when you need pandas:
252
- ```python
253
- df_pandas = df.to_pandas(use_pyarrow_extension_array=True)
254
- series_pandas = s.to_pandas(use_pyarrow_extension_array=True)
255
- ```
256
-
257
- ### Rationale
258
- Using Polars + Arrow dtypes provides:
259
- * Deterministic schema & faster IO
260
- * Efficient vectorized date casting
261
- * Clear null vs. missing semantics
262
- * Reduced overhead vs. repeated Pandas conversions
263
-
264
- These conventions keep public APIs flexible on input while consistent on output.
250
+ ## Tests
251
+ To run the test suite, use the following command:
252
+ pytest pyield --doctest-modules
@@ -0,0 +1 @@
1
+ __version__ = "0.41.1"
@@ -4,15 +4,6 @@ Documentação da API do BC
4
4
  Exemplo de chamada:
5
5
  "https://olinda.bcb.gov.br/olinda/servico/leiloes_selic/versao/v1/odata/leiloesTitulosPublicos(dataMovimentoInicio=@dataMovimentoInicio,dataMovimentoFim=@dataMovimentoFim,dataLiquidacao=@dataLiquidacao,codigoTitulo=@codigoTitulo,dataVencimento=@dataVencimento,edital=@edital,tipoPublico=@tipoPublico,tipoOferta=@tipoOferta)?@dataMovimentoInicio='2025-04-08'&@dataMovimentoFim='2025-04-08'&$top=100&$format=json"
6
6
 
7
- Examplo de retorno da API:
8
-
9
- id , dataMovimento , dataLiquidacao , edital, tipoPublico, prazo, quantidadeOfertada, quantidadeAceita, codigoTitulo, dataVencimento , tipoOferta, ofertante , quantidadeOfertadaSegundaRodada, quantidadeAceitaSegundaRodada, cotacaoMedia , cotacaoCorte , taxaMedia, taxaCorte, financeiro
10
- 9fe0a3ed0ae043f545d8918000005d , 2025-08-28 00:00:00, 2025-08-29 00:00:00, 202, TodoMercado, 2316, 3000000, 3000000, 100000, 2032-01-01 00:00:00, Venda , Tesouro Nacional, 750000, 0, "443,791682" , "443,791682" , "13,7599", "13,7599", "1331,4"
11
- 9fe0a3ed0ae043f545d8918000005e , 2025-08-28 00:00:00, 2025-08-29 00:00:00, 203, TodoMercado, 1951, 1000000, 1000000, 950199, 2031-01-01 00:00:00, Venda , Tesouro Nacional, 250000, 0, "887,706572" , "887,706572" , "13,703" , "13,703" , "887,7"
12
- 9fe0a3ed0ae043f545d8918000005c , 2025-08-28 00:00:00, 2025-08-29 00:00:00, 202, TodoMercado, 1402, 6000000, 6000000, 100000, 2029-07-01 00:00:00, Venda , Tesouro Nacional, 1500000, 0, "620,124125" , "620,116199" , "13,3786", "13,379" , "3720,7"
13
- 9fe0a3ed0ae043f545d8918000005f , 2025-08-28 00:00:00, 2025-08-29 00:00:00, 203, TodoMercado, 3412, 300000, 300000, 950199, 2035-01-01 00:00:00, Venda , Tesouro Nacional, 75000, 42426, "825,382124" , "825,382124" , "13,928" , "13,928" , "282,7"
14
- 9fe0a3ed0ae043f545d8918000005b , 2025-08-28 00:00:00, 2025-08-29 00:00:00, 202, TodoMercado, 763, 6000000, 6000000, 100000, 2027-10-01 00:00:00, Venda , Tesouro Nacional, 1500000, 0, "769,543353" , "769,439322" , "13,4259", "13,4333", "4617,3"
15
- 9fe09a766d18e3de0ac228c80000c5a, 2025-08-28 00:00:00, 2025-08-29 00:00:00, 202, TodoMercado, 398, 2000000, 960000, 100000, 2026-10-01 00:00:00, Venda , Tesouro Nacional, 0, 0, "865,527516" , "865,432896" , "14,2045", "14,216" , "830,9"
16
7
  """ # noqa: E501
17
8
 
18
9
  import datetime as dt
@@ -56,8 +47,10 @@ NAME_MAPPING = {
56
47
  "taxaCorte": "CutRate",
57
48
  "quantidadeOfertada": "OfferedQuantityFR",
58
49
  "quantidadeAceita": "AcceptedQuantityFR",
50
+ "quantidadeLiquidada": "SettledQuantityFR",
59
51
  "quantidadeOfertadaSegundaRodada": "OfferedQuantitySR",
60
52
  "quantidadeAceitaSegundaRodada": "AcceptedQuantitySR",
53
+ "quantidadeLiquidadaSegundaRodada": "SettledQuantitySR",
61
54
  "financeiro": "Value", # = FR + SR (in millions)
62
55
  }
63
56
 
@@ -82,6 +75,8 @@ API_SCHEMA = {
82
75
  "taxaMedia": pl.Float64,
83
76
  "taxaCorte": pl.Float64,
84
77
  "financeiro": pl.Float64,
78
+ "quantidadeLiquidada": pl.Int64,
79
+ "quantidadeLiquidadaSegundaRodada": pl.Int64,
85
80
  }
86
81
 
87
82
  BASE_API_URL = "https://olinda.bcb.gov.br/olinda/servico/leiloes_selic/versao/v1/odata/leiloesTitulosPublicos(dataMovimentoInicio=@dataMovimentoInicio,dataMovimentoFim=@dataMovimentoFim,dataLiquidacao=@dataLiquidacao,codigoTitulo=@codigoTitulo,dataVencimento=@dataVencimento,edital=@edital,tipoPublico=@tipoPublico,tipoOferta=@tipoOferta)?"
@@ -135,7 +130,7 @@ def _parse_csv(csv_text: str) -> pl.DataFrame:
135
130
  )
136
131
  # Converte os campos datetime para Date (mantemos apenas a data).
137
132
  df = df.with_columns(
138
- pl.col(["dataMovimento", "dataLiquidacao", "dataVencimento"]).cast(pl.Date)
133
+ pl.col("dataMovimento", "dataLiquidacao", "dataVencimento").cast(pl.Date)
139
134
  )
140
135
  return df
141
136
 
@@ -167,18 +162,16 @@ def _process_df(df: pl.DataFrame) -> pl.DataFrame:
167
162
  # E calcular o financeiro da FR e SR com base na proporção das quantidades.
168
163
  df = (
169
164
  df.with_columns(
170
- # 1. Calcula as quantidades totais, tratando nulos automaticamente.
171
- pl.sum_horizontal("OfferedQuantityFR", "OfferedQuantitySR").alias(
172
- "OfferedQuantity"
165
+ # Converte o valor financeiro de milhões para unidades e tipo inteiro
166
+ (pl.col("Value") * 1_000_000).round(0).cast(pl.Int64),
167
+ # Converte as taxas de % para decimais
168
+ (pl.col("AvgRate", "CutRate") / 100).round(6),
169
+ # Calcula as quantidades totais, tratando nulos automaticamente.
170
+ OfferedQuantity=pl.sum_horizontal("OfferedQuantityFR", "OfferedQuantitySR"),
171
+ AcceptedQuantity=pl.sum_horizontal(
172
+ "AcceptedQuantityFR", "AcceptedQuantitySR"
173
173
  ),
174
- pl.sum_horizontal("AcceptedQuantityFR", "AcceptedQuantitySR").alias(
175
- "AcceptedQuantity"
176
- ),
177
- # 2. Converte o valor financeiro de milhões para unidades e tipo inteiro
178
- (pl.col("Value") * 1_000_000).round(0).cast(pl.Int64).alias("Value"),
179
- # 3. Converte as taxas de % para decimais
180
- (pl.col("AvgRate") / 100).round(6).alias("AvgRate"),
181
- (pl.col("CutRate") / 100).round(6).alias("CutRate"),
174
+ SettledQuantity=pl.sum_horizontal("SettledQuantityFR", "SettledQuantitySR"),
182
175
  )
183
176
  .with_columns(
184
177
  # 5. Calcula o valor financeiro da primeira rodada (ValueFR)
@@ -271,9 +264,9 @@ def _add_dv01(df: pl.DataFrame) -> pl.DataFrame:
271
264
 
272
265
  df = df.with_columns(
273
266
  # 2. Criar as colunas DV01 multiplicando a expressão base pelas quantidades.
274
- (dv01_unit_expr * pl.col("AcceptedQuantity")).alias("DV01"),
275
- (dv01_unit_expr * pl.col("AcceptedQuantityFR")).alias("DV01FR"),
276
- (dv01_unit_expr * pl.col("AcceptedQuantitySR")).alias("DV01SR"),
267
+ DV01=dv01_unit_expr * pl.col("AcceptedQuantity"),
268
+ DV01FR=dv01_unit_expr * pl.col("AcceptedQuantityFR"),
269
+ DV01SR=dv01_unit_expr * pl.col("AcceptedQuantitySR"),
277
270
  )
278
271
 
279
272
  return df
@@ -296,7 +289,7 @@ def _get_ptax_df(start_date: dt.date, end_date: dt.date) -> pl.DataFrame:
296
289
  return pl.DataFrame()
297
290
 
298
291
  # Converte para Polars, seleciona, renomeia e ordena (importante para join_asof)
299
- return df.select(["Date", "MidRate"]).rename({"MidRate": "PTAX"}).sort("Date")
292
+ return df.select("Date", "MidRate").rename({"MidRate": "PTAX"}).sort("Date")
300
293
 
301
294
 
302
295
  def _add_usd_dv01(df: pl.DataFrame) -> pl.DataFrame:
@@ -304,8 +297,8 @@ def _add_usd_dv01(df: pl.DataFrame) -> pl.DataFrame:
304
297
  Adiciona o DV01 em USD usando um join_asof para encontrar a PTAX mais recente.
305
298
  """
306
299
  # Determina o intervalo de datas necessário a partir do DataFrame de leilões
307
- ptax_start_date = df.get_column("Date").min()
308
- ptax_end_date = df.get_column("Date").max()
300
+ ptax_start_date = df["Date"].min()
301
+ ptax_end_date = df["Date"].max()
309
302
 
310
303
  # Busca o DataFrame da PTAX
311
304
  df_ptax = _get_ptax_df(start_date=ptax_start_date, end_date=ptax_end_date)
@@ -360,6 +353,9 @@ def _sort_and_reorder_columns(df: pl.DataFrame) -> pl.DataFrame:
360
353
  "DV01FRUSD",
361
354
  "DV01SRUSD",
362
355
  "DV01USD",
356
+ "SettledQuantityFR",
357
+ "SettledQuantitySR",
358
+ "SettledQuantity",
363
359
  "OfferedQuantityFR",
364
360
  "OfferedQuantitySR",
365
361
  "OfferedQuantity",
@@ -432,7 +428,7 @@ def auctions(
432
428
  Examples:
433
429
  >>> from pyield import bc
434
430
  >>> bc.auctions(start="19-08-2025", end="19-08-2025")
435
- shape: (5, 30)
431
+ shape: (5, 33)
436
432
  ┌────────────┬────────────┬─────────────┬───────────┬───┬──────────────────┬─────────────┬──────────┬─────────────┐
437
433
  │ Date ┆ Settlement ┆ AuctionType ┆ Ordinance ┆ … ┆ AcceptedQuantity ┆ ValueFR ┆ ValueSR ┆ Value │
438
434
  │ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
@@ -478,6 +474,9 @@ def auctions(
478
474
  - AcceptedQuantityFR: Quantidade aceita na primeira rodada (FR).
479
475
  - AcceptedQuantitySR: Quantidade aceita na segunda rodada (SR).
480
476
  - AcceptedQuantity: Quantidade total aceita no leilão (FR + SR).
477
+ - SettledQuantityFR: Quantidade liquidada na primeira rodada (FR).
478
+ - SettledQuantitySR: Quantidade liquidada na segunda rodada (SR).
479
+ - SettledQuantity: Quantidade total liquidada no leilão (FR + SR
481
480
  - ValueFR: Valor da primeira rodada (FR) do leilão em R$.
482
481
  - ValueSR: Valor da segunda rodada (SR) em R$.
483
482
  - Value: Valor total do leilão em R$ (FR + SR).
@@ -430,11 +430,14 @@ def auction(auction_date: DateLike) -> pl.DataFrame:
430
430
  df = _add_dv01_usd(df)
431
431
  df = _add_avg_maturity(df)
432
432
  df = df.select(FINAL_COLUMN_ORDER)
433
+
434
+ # Substituir eventuais NaNs por None para compatibilidade com bancos de dados
435
+ df = df.with_columns(cs.float().fill_nan(None))
433
436
  return df
434
437
 
435
438
  except requests.exceptions.RequestException as e:
436
439
  logger.error(f"An error occurred during the API request: {e}")
437
440
  return pl.DataFrame()
438
- except ValueError as e:
441
+ except (ValueError, TypeError) as e:
439
442
  logger.error(f"An error occurred while parsing the JSON response: {e}")
440
443
  return pl.DataFrame()
@@ -169,4 +169,6 @@ def price(
169
169
  >>> lft.price(15785.324502, 99.9291)
170
170
  15774.132706
171
171
  """
172
+ if has_nullable_args(vna, quotation):
173
+ return float("nan")
172
174
  return tools.truncate(vna * quotation / 100, 6)
@@ -177,6 +177,9 @@ def dv01(
177
177
  >>> ltn.dv01(None, "01-01-2032", 0.150970)
178
178
  nan
179
179
  """
180
+ if has_nullable_args(settlement, maturity, rate):
181
+ return float("nan")
182
+
180
183
  price1 = price(settlement, maturity, rate)
181
184
  price2 = price(settlement, maturity, rate + 0.0001)
182
185
  return price1 - price2
@@ -135,7 +135,7 @@ def _generate_all_coupon_dates(
135
135
  # Offset dates to the 15th
136
136
  coupon_dates = coupon_dates.dt.offset_by("14d")
137
137
 
138
- # First coupon date must be after the reference date
138
+ # First coupon date must be after the start date
139
139
  return coupon_dates.filter(coupon_dates > start)
140
140
 
141
141
 
@@ -162,7 +162,7 @@ def payment_dates(
162
162
  >>> from pyield import ntnb
163
163
  >>> ntnb.payment_dates("10-05-2024", "15-05-2025")
164
164
  shape: (3,)
165
- Series: '' [date]
165
+ Series: 'payment_dates' [date]
166
166
  [
167
167
  2024-05-15
168
168
  2024-11-15
@@ -171,6 +171,7 @@ def payment_dates(
171
171
  """
172
172
  if has_nullable_args(settlement, maturity):
173
173
  return pl.Series(dtype=pl.Date)
174
+
174
175
  settlement = cv.convert_dates(settlement)
175
176
  maturity = cv.convert_dates(maturity)
176
177
 
@@ -185,7 +186,7 @@ def payment_dates(
185
186
  coupon_date -= pd.DateOffset(months=6)
186
187
  coupon_date = coupon_date.date()
187
188
 
188
- return pl.Series(coupon_dates).sort()
189
+ return pl.Series(name="payment_dates", values=coupon_dates).sort()
189
190
 
190
191
 
191
192
  def cash_flows(
@@ -222,6 +223,9 @@ def cash_flows(
222
223
  │ 2025-05-15 ┆ 102.956301 │
223
224
  └─────────────┴────────────┘
224
225
  """
226
+ if has_nullable_args(settlement, maturity):
227
+ return pl.DataFrame(schema={"PaymentDate": pl.Date, "CashFlow": pl.Float64})
228
+
225
229
  # Get the coupon dates between the settlement and maturity dates
226
230
  settlement = cv.convert_dates(settlement)
227
231
  maturity = cv.convert_dates(maturity)
@@ -231,7 +235,9 @@ def cash_flows(
231
235
  if p_dates.is_empty():
232
236
  return pl.DataFrame(schema={"PaymentDate": pl.Date, "CashFlow": pl.Float64})
233
237
 
234
- df = pl.DataFrame({"PaymentDate": p_dates}).with_columns(
238
+ df = pl.DataFrame(
239
+ {"PaymentDate": p_dates},
240
+ ).with_columns(
235
241
  pl.when(pl.col("PaymentDate") == maturity)
236
242
  .then(FINAL_PMT)
237
243
  .otherwise(COUPON_PMT)
@@ -274,20 +280,23 @@ def quotation(
274
280
  >>> ntnb.quotation("15-08-2024", "15-08-2032", 0.05929)
275
281
  100.6409
276
282
  """
277
- cf_df = cash_flows(settlement, maturity)
278
- if cf_df.is_empty():
283
+ if has_nullable_args(settlement, maturity, rate):
279
284
  return float("nan")
280
285
 
281
- cf_dates = cf_df["PaymentDate"]
282
- cf_values = cf_df["CashFlow"]
286
+ df_cf = cash_flows(settlement, maturity)
287
+ if df_cf.is_empty():
288
+ return float("nan")
289
+
290
+ cf_dates = df_cf["PaymentDate"]
291
+ cf_values = df_cf["CashFlow"]
283
292
 
284
293
  # Calculate the number of business days between settlement and cash flow dates
285
294
  bdays = bday.count(settlement, cf_dates)
286
295
 
287
296
  # Calculate the number of periods truncated as per Anbima rules
288
- num_of_years = tl.truncate(bdays / 252, 14)
297
+ byears = tl.truncate(bdays / 252, 14)
289
298
 
290
- discount_factor = (1 + rate) ** num_of_years
299
+ discount_factor = (1 + rate) ** byears
291
300
 
292
301
  # Calculate the present value of each cash flow (DCF) rounded as per Anbima rules
293
302
  cf_present_value = (cf_values / discount_factor).round(10)
@@ -657,9 +666,13 @@ def duration(
657
666
  >>> ntnb.duration("23-08-2024", "15-08-2060", 0.061005)
658
667
  15.08305431313046
659
668
  """
669
+ if has_nullable_args(settlement, maturity, rate):
670
+ return float("nan")
671
+
660
672
  df = cash_flows(settlement, maturity)
661
673
  if df.is_empty():
662
674
  return float("nan")
675
+
663
676
  byears = bday.count(settlement, df["PaymentDate"]) / 252
664
677
  dcf = df["CashFlow"] / (1 + rate) ** byears
665
678
  duration = (dcf * byears).sum() / dcf.sum()
@@ -695,6 +708,9 @@ def dv01(
695
708
  >>> ntnb.dv01("26-03-2025", "15-08-2060", 0.074358, 4470.979474)
696
709
  4.640875999999935
697
710
  """
711
+ if has_nullable_args(settlement, maturity, rate, vna):
712
+ return float("nan")
713
+
698
714
  quotation1 = quotation(settlement, maturity, rate)
699
715
  quotation2 = quotation(settlement, maturity, rate + 0.0001)
700
716
  price1 = price(vna, quotation1)
@@ -746,6 +762,9 @@ def forwards(
746
762
  │ 2060-08-15 ┆ 8722 ┆ 0.073795 ┆ 0.074505 │
747
763
  └──────────────┴─────────┴────────────────┴─────────────┘
748
764
  """
765
+ if has_nullable_args(date):
766
+ return pl.DataFrame()
767
+
749
768
  # Validate and normalize the date
750
769
  df = data(date).select("MaturityDate", "BDToMat", "IndicativeRate")
751
770
  if zero_coupon:
@@ -113,9 +113,9 @@ def payment_dates(
113
113
  if len(amtz_dates) == 0:
114
114
  raise ValueError("No amortization dates found after settlement date.")
115
115
 
116
- s_pmt_dates = pl.Series(name="payment_dates", values=amtz_dates).cast(pl.Date)
116
+ pmt_dates = pl.Series(name="payment_dates", values=amtz_dates).cast(pl.Date)
117
117
 
118
- return s_pmt_dates.filter(s_pmt_dates > settlement).sort()
118
+ return pmt_dates.filter(pmt_dates > settlement).sort()
119
119
 
120
120
 
121
121
  def cash_flows(
@@ -217,6 +217,9 @@ def quotation(
217
217
  >>> ntnb1.quotation("18-06-2025", "15-12-2084", 0.07010, r_mais)
218
218
  0.038332
219
219
  """
220
+ if has_nullable_args(settlement, maturity, rate, commercial_name):
221
+ return float("nan")
222
+
220
223
  cf_df = cash_flows(settlement, maturity, commercial_name)
221
224
  cf_dates = cf_df["PaymentDate"]
222
225
  cf_values = cf_df["CashFlow"]
@@ -38,9 +38,9 @@ def price(
38
38
  bdays = bday.count(settlement, maturity)
39
39
 
40
40
  # Calculate the number of periods truncated as per Anbima rule
41
- num_of_years = tools.truncate(bdays / 252, 14)
41
+ byears = tools.truncate(bdays / 252, 14)
42
42
 
43
- discount_factor = (1 + rate) ** num_of_years
43
+ discount_factor = (1 + rate) ** byears
44
44
 
45
45
  # Truncate the price to 6 decimal places as per Anbima rules
46
46
  return tools.truncate(face_value / discount_factor, 6)
@@ -75,6 +75,9 @@ def dv01(
75
75
  >>> bp.dv01("02-12-2025", "15-05-2029", 0.0777, 4567.033825)
76
76
  1.1200559999997495
77
77
  """
78
+ if has_nullable_args(settlement, maturity, rate, face_value):
79
+ return float("nan")
80
+
78
81
  price1 = price(settlement, maturity, rate, face_value)
79
82
  price2 = price(settlement, maturity, rate + 0.0001, face_value)
80
83
  return price1 - price2
@@ -105,6 +105,7 @@ def payment_dates(
105
105
  """
106
106
  if has_nullable_args(settlement, maturity):
107
107
  return pl.Series(dtype=pl.Date)
108
+
108
109
  # Validate and normalize dates
109
110
  settlement = cv.convert_dates(settlement)
110
111
  maturity = cv.convert_dates(maturity)
@@ -168,6 +169,9 @@ def cash_flows(
168
169
  │ 2031-01-01 ┆ 105.830052 │
169
170
  └─────────────┴────────────┘
170
171
  """
172
+ if has_nullable_args(settlement, maturity):
173
+ return pl.DataFrame(schema={"PaymentDate": pl.Date, "CashFlow": pl.Float64})
174
+
171
175
  # Validate and normalize dates
172
176
  settlement = cv.convert_dates(settlement)
173
177
  maturity = cv.convert_dates(maturity)
@@ -221,6 +225,9 @@ def quotation(
221
225
  >>> ntnc.quotation("21-03-2025", "01-01-2031", 0.067626)
222
226
  126.4958
223
227
  """
228
+ if has_nullable_args(settlement, maturity, rate):
229
+ return float("nan")
230
+
224
231
  cf_df = cash_flows(settlement, maturity)
225
232
  if cf_df.is_empty():
226
233
  return float("nan")
@@ -293,6 +300,9 @@ def duration(
293
300
  >>> ntnc.duration("21-03-2025", "01-01-2031", 0.067626)
294
301
  4.405363320448
295
302
  """
303
+ if has_nullable_args(settlement, maturity, rate):
304
+ return float("nan")
305
+
296
306
  df = cash_flows(settlement, maturity)
297
307
  if df.is_empty():
298
308
  return float("nan")
@@ -107,7 +107,7 @@ def payment_dates(
107
107
  >>> from pyield import ntnf
108
108
  >>> ntnf.payment_dates("15-05-2024", "01-01-2027")
109
109
  shape: (6,)
110
- Series: '' [date]
110
+ Series: 'payment_dates' [date]
111
111
  [
112
112
  2024-07-01
113
113
  2025-01-01
@@ -138,7 +138,7 @@ def payment_dates(
138
138
  coupon_date -= pd.DateOffset(months=6)
139
139
  coupon_date = coupon_date.date() # DateOffset returns a Timestamp
140
140
 
141
- return pl.Series(coupon_dates).sort()
141
+ return pl.Series(name="payment_dates", values=coupon_dates).sort()
142
142
 
143
143
 
144
144
  def cash_flows(
@@ -184,14 +184,16 @@ def cash_flows(
184
184
  maturity = cv.convert_dates(maturity)
185
185
 
186
186
  # Get the payment dates between the settlement and maturity dates
187
- pay_dates = payment_dates(settlement, maturity)
187
+ pmt_dates = payment_dates(settlement, maturity)
188
188
 
189
189
  # Return empty DataFrame if no payment dates (settlement >= maturity)
190
- if pay_dates.is_empty():
190
+ if pmt_dates.is_empty():
191
191
  return pl.DataFrame(schema={"PaymentDate": pl.Date, "CashFlow": pl.Float64})
192
192
 
193
193
  # Set the cash flow at maturity to FINAL_PMT and the others to COUPON_PMT
194
- df = pl.DataFrame(data={"PaymentDate": pay_dates}).with_columns(
194
+ df = pl.DataFrame(
195
+ data={"PaymentDate": pmt_dates},
196
+ ).with_columns(
195
197
  pl.when(pl.col("PaymentDate") == maturity)
196
198
  .then(FINAL_PMT)
197
199
  .otherwise(COUPON_PMT)
@@ -199,7 +201,7 @@ def cash_flows(
199
201
  )
200
202
 
201
203
  if adj_payment_dates:
202
- adj_pay_dates = bday.offset(pay_dates, 0)
204
+ adj_pay_dates = bday.offset(pmt_dates, 0)
203
205
  df = df.with_columns(PaymentDate=adj_pay_dates)
204
206
  return df
205
207
 
@@ -236,12 +238,12 @@ def price(
236
238
  if has_nullable_args(settlement, maturity, rate):
237
239
  return float("nan")
238
240
 
239
- cf_df = cash_flows(settlement, maturity)
240
- if cf_df.is_empty():
241
+ df_cf = cash_flows(settlement, maturity)
242
+ if df_cf.is_empty():
241
243
  return float("nan")
242
244
 
243
- cf_values = cf_df["CashFlow"]
244
- bdays = bday.count(settlement, cf_df["PaymentDate"])
245
+ cf_values = df_cf["CashFlow"]
246
+ bdays = bday.count(settlement, df_cf["PaymentDate"])
245
247
  byears = tools.truncate(bdays / 252, 14)
246
248
  discount_factors = (1 + rate) ** byears
247
249
  # Calculate the present value of each cash flow (DCF) rounded as per Anbima rules
@@ -754,6 +756,9 @@ def duration(
754
756
  >>> ntnf.duration(None, "01-01-2035", 0.121785)
755
757
  nan
756
758
  """
759
+ if has_nullable_args(settlement, maturity, rate):
760
+ return float("nan")
761
+
757
762
  df = cash_flows(settlement, maturity)
758
763
  if df.is_empty():
759
764
  return float("nan")
@@ -795,6 +800,9 @@ def dv01(
795
800
  >>> ntnf.dv01("", "01-01-2035", 0.151375)
796
801
  nan
797
802
  """
803
+ if has_nullable_args(settlement, maturity, rate):
804
+ return float("nan")
805
+
798
806
  price1 = price(settlement, maturity, rate)
799
807
  price2 = price(settlement, maturity, rate + 0.0001)
800
808
  return price1 - price2
@@ -14,9 +14,8 @@ classifiers = [
14
14
  "Topic :: Office/Business :: Financial :: Investment",
15
15
  ]
16
16
  dependencies = [
17
- "pandas[html, parquet]>=2.0.0",
18
- "numpy>=2.0.0",
19
- "polars>=1.33.0",
17
+ "polars[numpy, pyarrow]>=1.33.0",
18
+ "pandas[html]>=2.0.0",
20
19
  "requests>=2.31.0",
21
20
  "tenacity>=9.0.0",
22
21
  ]
@@ -35,8 +34,7 @@ dev = [
35
34
  "mkdocs-material",
36
35
  "mkdocstrings[python]",
37
36
  "mkdocs-autorefs",
38
- "types-requests",
39
- "pandas-stubs",
37
+ "types-requests",
40
38
  "lxml-stubs",
41
39
  ]
42
40
 
@@ -1 +0,0 @@
1
- __version__ = "0.41.0"
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