tea-bond 0.3.7__cp310-abi3-win_amd64.whl → 0.3.9__cp310-abi3-win_amd64.whl

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.

Potentially problematic release.


This version of tea-bond might be problematic. Click here for more details.

pybond/pd.py CHANGED
@@ -4,6 +4,7 @@ import pandas as pd
4
4
  import polars as pl
5
5
 
6
6
  from .pl import Bonds as PlBonds
7
+ from .pl import Futures as PlFutures
7
8
  from .pl import TfEvaluators as PlTfEvaluators
8
9
 
9
10
 
@@ -23,9 +24,9 @@ class TfEvaluators:
23
24
  future: str | pd.Series,
24
25
  bond: str | pd.Series,
25
26
  date: str | pd.Series,
26
- future_price: pd.Series,
27
- bond_ytm: pd.Series,
28
- capital_rate: float | pd.Series,
27
+ future_price: pd.Series | None = None,
28
+ bond_ytm: pd.Series | None = None,
29
+ capital_rate: float | pd.Series | None = None,
29
30
  reinvest_rate: float | None = None,
30
31
  ):
31
32
  """
@@ -50,8 +51,12 @@ class TfEvaluators:
50
51
  "capital_rate": capital_rate,
51
52
  }
52
53
  )
53
- self._evaluators = PlTfEvaluators(reinvest_rate=reinvest_rate)
54
- # self.reinvest_rate = reinvest_rate
54
+ self._evaluators = PlTfEvaluators(
55
+ future_price="future_price",
56
+ bond_ytm="bond_ytm",
57
+ capital_rate="capital_rate",
58
+ reinvest_rate=reinvest_rate,
59
+ )
55
60
 
56
61
  @property
57
62
  def net_basis_spread(self):
@@ -258,6 +263,30 @@ class TfEvaluators:
258
263
  "remain_cp_num"
259
264
  ].to_pandas()
260
265
 
266
+ @property
267
+ def deliver_date(self):
268
+ """
269
+ Calculate delivery date (交割日).
270
+
271
+ Returns:
272
+ pd.Series: Delivery date values
273
+ """
274
+ return self.pl_df.select(deliver_date=self._evaluators.deliver_date)[
275
+ "deliver_date"
276
+ ].to_pandas()
277
+
278
+ @property
279
+ def last_trading_date(self):
280
+ """
281
+ Calculate last trading date (最后交易日).
282
+
283
+ Returns:
284
+ pd.Series: Last trading date values
285
+ """
286
+ return self.pl_df.select(last_trading_date=self._evaluators.last_trading_date)[
287
+ "last_trading_date"
288
+ ].to_pandas()
289
+
261
290
 
262
291
  class Bonds:
263
292
  """
@@ -355,6 +384,41 @@ class Bonds:
355
384
  ].to_pandas()
356
385
 
357
386
 
387
+ class Futures:
388
+ def __init__(self, future: str | pd.Series):
389
+ self.future = future
390
+
391
+ def deliver_date(self):
392
+ """
393
+ Calculate delivery date (交割日).
394
+
395
+ Args:
396
+ date: Evaluation date(s)
397
+
398
+ Returns:
399
+ pd.Series: Delivery date values
400
+ """
401
+ df = pl.DataFrame({"future": self.future})
402
+ return df.select(deliver_date=PlFutures("future").deliver_date())[
403
+ "deliver_date"
404
+ ].to_pandas()
405
+
406
+ def last_trading_date(self):
407
+ """
408
+ Calculate last trading date (最后交易日).
409
+
410
+ Args:
411
+ date: Evaluation date(s)
412
+
413
+ Returns:
414
+ pd.Series: Last trading date values
415
+ """
416
+ df = pl.DataFrame({"future": self.future})
417
+ return df.select(last_trading_date=PlFutures("future").last_trading_date())[
418
+ "last_trading_date"
419
+ ].to_pandas()
420
+
421
+
358
422
  def find_workday(date: str | pd.Series, market: str, offset: int = 0):
359
423
  """
360
424
  Find the workday based on the given date and market calendar.
pybond/pl.py CHANGED
@@ -19,9 +19,9 @@ class TfEvaluators:
19
19
  future: IntoExpr = "future",
20
20
  bond: IntoExpr = "bond",
21
21
  date: IntoExpr = "date",
22
- future_price: IntoExpr = "future_price",
23
- bond_ytm: IntoExpr = "bond_ytm",
24
- capital_rate: IntoExpr = "capital_rate",
22
+ future_price: IntoExpr = None,
23
+ bond_ytm: IntoExpr = None,
24
+ capital_rate: IntoExpr = None,
25
25
  reinvest_rate=None,
26
26
  ):
27
27
  """
@@ -36,14 +36,24 @@ class TfEvaluators:
36
36
  capital_rate: Capital cost rate column expression
37
37
  reinvest_rate: Reinvestment rate (optional)
38
38
  """
39
- if future is None:
40
- future = pl.lit(None).cast(str)
41
- self.future = parse_into_expr(future)
42
- self.bond = parse_into_expr(bond)
43
- self.date = parse_into_expr(date)
44
- self.future_price = parse_into_expr(future_price)
45
- self.bond_ytm = parse_into_expr(bond_ytm)
46
- self.capital_rate = parse_into_expr(capital_rate)
39
+ self.future = parse_into_expr(
40
+ future if future is not None else pl.lit(None).cast(str)
41
+ )
42
+ self.bond = parse_into_expr(
43
+ bond if bond is not None else pl.lit(None).cast(str)
44
+ )
45
+ self.date = parse_into_expr(
46
+ date if date is not None else pl.lit(None).cast(pl.Date)
47
+ )
48
+ self.future_price = parse_into_expr(
49
+ future_price if future_price is not None else pl.lit(None)
50
+ )
51
+ self.bond_ytm = parse_into_expr(
52
+ bond_ytm if bond_ytm is not None else pl.lit(None)
53
+ )
54
+ self.capital_rate = parse_into_expr(
55
+ capital_rate if capital_rate is not None else pl.lit(None)
56
+ )
47
57
  self.reinvest_rate = reinvest_rate
48
58
 
49
59
  def _call_plugin(self, symbol: str):
@@ -239,6 +249,26 @@ class TfEvaluators:
239
249
  """
240
250
  return self._call_plugin("evaluators_remain_cp_num")
241
251
 
252
+ @property
253
+ def deliver_date(self):
254
+ """
255
+ Calculate delivery date (交割日).
256
+
257
+ Returns:
258
+ Polars expression for delivery date
259
+ """
260
+ return self._call_plugin("evaluators_deliver_date")
261
+
262
+ @property
263
+ def last_trading_date(self):
264
+ """
265
+ Calculate last trading date (最后交易日).
266
+
267
+ Returns:
268
+ Polars expression for last trading date
269
+ """
270
+ return self._call_plugin("evaluators_last_trading_date")
271
+
242
272
 
243
273
  class Bonds:
244
274
  """
@@ -346,6 +376,61 @@ class Bonds:
346
376
  # TODO(Teamon): 实现向量化根据净价反推ytm的函数
347
377
 
348
378
 
379
+ class Futures:
380
+ def __init__(self, future: IntoExpr = "symbol"):
381
+ """
382
+ Initialize Futures with future identifier.
383
+
384
+ Args:
385
+ future: Future code column expression (default: "symbol")
386
+ """
387
+ self.future = future
388
+
389
+ def _evaluator(self, date: IntoExpr | None = None) -> TfEvaluators:
390
+ """
391
+ Create a TfEvaluators instance for future-only calculations.
392
+
393
+ Args:
394
+ date: Evaluation date column expression
395
+
396
+ Returns:
397
+ TfEvaluators: Configured evaluator instance
398
+ """
399
+ return TfEvaluators(
400
+ future=self.future,
401
+ bond=None,
402
+ date=date,
403
+ bond_ytm=None,
404
+ future_price=None,
405
+ capital_rate=None,
406
+ reinvest_rate=None,
407
+ )
408
+
409
+ def deliver_date(self):
410
+ """
411
+ Calculate delivery date (交割日).
412
+
413
+ Args:
414
+ date: Evaluation date column expression
415
+
416
+ Returns:
417
+ Polars expression for delivery date
418
+ """
419
+ return self._evaluator().deliver_date
420
+
421
+ def last_trading_date(self):
422
+ """
423
+ Calculate last trading date (最后交易日).
424
+
425
+ Args:
426
+ date: Evaluation date column expression
427
+
428
+ Returns:
429
+ Polars expression for last trading date
430
+ """
431
+ return self._evaluator().last_trading_date
432
+
433
+
349
434
  def find_workday(date: IntoExpr, market: str | Ib | Sse, offset: int = 0):
350
435
  """
351
436
  Find the workday based on the given date and market calendar.
pybond/pybond.pyd CHANGED
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tea-bond
3
- Version: 0.3.7
3
+ Version: 0.3.9
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -15,12 +15,12 @@ pybond/nb/nb_datetime.py,sha256=sg3Vmg2n2P_A186QgOGSOKBq-Tr72ht_Yw064yYrWXE,1067
15
15
  pybond/nb/nb_duration.py,sha256=bndVSHdG_yV0_vEWeAHd9Lq_UQ-8nkPnEC9cN2A2ca4,1709
16
16
  pybond/nb/nb_evaluators.py,sha256=GBsW3UuGf8iVUWr2DTISXzdYoGV5ITEOVFJivBNmWkc,15544
17
17
  pybond/nb/nb_time.py,sha256=5KNrWYcPwZUHoxvZKvh3qdhjB0DjRkxbUzONSv6OfhY,8928
18
- pybond/pd.py,sha256=SzHyXRRm7CbytyQ4FCwwM4FazkjXwJLX5y-MZniCbi8,11985
19
- pybond/pl.py,sha256=DzI2YcCqQICKeeQxjjxwcWVBJBiwBjLpuCg_KHHs45s,11680
18
+ pybond/pd.py,sha256=gXUV6d069jC94Ej04njrgQCW16UdYx0Rh9y2IVMc068,13760
19
+ pybond/pl.py,sha256=WhiBv6IOs5-jxK78xd75KXZSogoFyJ0XJ-v23Gjp_ho,13966
20
20
  pybond/pnl.py,sha256=RXC5GnQckD4LmTjgPwCePB-3GxsQ4liu0TW6hSdudLE,2752
21
21
  pybond/polars_utils.py,sha256=020Dy-l6v_NF-y7LXcKyJmWGAgH59NAxWKvjfnJO1tY,2663
22
- pybond/pybond.pyd,sha256=bVJ8Nn6PY9mWno8-LZEaHrQF0ZV89KHa1nXEafc_Q4I,23516672
22
+ pybond/pybond.pyd,sha256=q4quLGe7AotoL05c1kGxlUhh5M-ofcFc754CMM8inxE,23570944
23
23
  pybond/pybond.pyi,sha256=qzOfqoysuUW7rnZYxEmGEJXK_UrCjMvQ29Y_mJOBN1Y,11621
24
- tea_bond-0.3.7.dist-info/METADATA,sha256=HqpNJ-MX00PeagAXvrgYwKgpGlNxMuYzeFYHjofp2U4,258
25
- tea_bond-0.3.7.dist-info/WHEEL,sha256=G8mq-RexZGAfbjW58CyHDPQ4EbuJINRXbIh22TbaFhw,95
26
- tea_bond-0.3.7.dist-info/RECORD,,
24
+ tea_bond-0.3.9.dist-info/METADATA,sha256=NTcEhk7-WT_aWbCc5fmxZbZecfzQa6O3PB0tozeRyhs,258
25
+ tea_bond-0.3.9.dist-info/WHEEL,sha256=G8mq-RexZGAfbjW58CyHDPQ4EbuJINRXbIh22TbaFhw,95
26
+ tea_bond-0.3.9.dist-info/RECORD,,