tea-bond 0.3.6__cp310-abi3-manylinux_2_34_x86_64.whl → 0.3.8__cp310-abi3-manylinux_2_34_x86_64.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
 
@@ -51,7 +52,6 @@ class TfEvaluators:
51
52
  }
52
53
  )
53
54
  self._evaluators = PlTfEvaluators(reinvest_rate=reinvest_rate)
54
- # self.reinvest_rate = reinvest_rate
55
55
 
56
56
  @property
57
57
  def net_basis_spread(self):
@@ -258,6 +258,30 @@ class TfEvaluators:
258
258
  "remain_cp_num"
259
259
  ].to_pandas()
260
260
 
261
+ @property
262
+ def deliver_date(self):
263
+ """
264
+ Calculate delivery date (交割日).
265
+
266
+ Returns:
267
+ pd.Series: Delivery date values
268
+ """
269
+ return self.pl_df.select(deliver_date=self._evaluators.deliver_date)[
270
+ "deliver_date"
271
+ ].to_pandas()
272
+
273
+ @property
274
+ def last_trading_date(self):
275
+ """
276
+ Calculate last trading date (最后交易日).
277
+
278
+ Returns:
279
+ pd.Series: Last trading date values
280
+ """
281
+ return self.pl_df.select(last_trading_date=self._evaluators.last_trading_date)[
282
+ "last_trading_date"
283
+ ].to_pandas()
284
+
261
285
 
262
286
  class Bonds:
263
287
  """
@@ -355,6 +379,41 @@ class Bonds:
355
379
  ].to_pandas()
356
380
 
357
381
 
382
+ class Futures:
383
+ def __init__(self, future: str | pd.Series):
384
+ self.future = future
385
+
386
+ def deliver_date(self):
387
+ """
388
+ Calculate delivery date (交割日).
389
+
390
+ Args:
391
+ date: Evaluation date(s)
392
+
393
+ Returns:
394
+ pd.Series: Delivery date values
395
+ """
396
+ df = pl.DataFrame({"future": self.future})
397
+ return df.select(deliver_date=PlFutures("future").deliver_date())[
398
+ "deliver_date"
399
+ ].to_pandas()
400
+
401
+ def last_trading_date(self):
402
+ """
403
+ Calculate last trading date (最后交易日).
404
+
405
+ Args:
406
+ date: Evaluation date(s)
407
+
408
+ Returns:
409
+ pd.Series: Last trading date values
410
+ """
411
+ df = pl.DataFrame({"future": self.future})
412
+ return df.select(last_trading_date=PlFutures("future").last_trading_date())[
413
+ "last_trading_date"
414
+ ].to_pandas()
415
+
416
+
358
417
  def find_workday(date: str | pd.Series, market: str, offset: int = 0):
359
418
  """
360
419
  Find the workday based on the given date and market calendar.
pybond/pl.py CHANGED
@@ -38,6 +38,8 @@ class TfEvaluators:
38
38
  """
39
39
  if future is None:
40
40
  future = pl.lit(None).cast(str)
41
+ if bond is None:
42
+ bond = pl.lit(None).cast(str)
41
43
  self.future = parse_into_expr(future)
42
44
  self.bond = parse_into_expr(bond)
43
45
  self.date = parse_into_expr(date)
@@ -239,6 +241,26 @@ class TfEvaluators:
239
241
  """
240
242
  return self._call_plugin("evaluators_remain_cp_num")
241
243
 
244
+ @property
245
+ def deliver_date(self):
246
+ """
247
+ Calculate delivery date (交割日).
248
+
249
+ Returns:
250
+ Polars expression for delivery date
251
+ """
252
+ return self._call_plugin("evaluators_deliver_date")
253
+
254
+ @property
255
+ def last_trading_date(self):
256
+ """
257
+ Calculate last trading date (最后交易日).
258
+
259
+ Returns:
260
+ Polars expression for last trading date
261
+ """
262
+ return self._call_plugin("evaluators_last_trading_date")
263
+
242
264
 
243
265
  class Bonds:
244
266
  """
@@ -346,6 +368,61 @@ class Bonds:
346
368
  # TODO(Teamon): 实现向量化根据净价反推ytm的函数
347
369
 
348
370
 
371
+ class Futures:
372
+ def __init__(self, future: IntoExpr = "symbol"):
373
+ """
374
+ Initialize Futures with future identifier.
375
+
376
+ Args:
377
+ future: Future code column expression (default: "symbol")
378
+ """
379
+ self.future = future
380
+
381
+ def _evaluator(self, date: IntoExpr | None = None) -> TfEvaluators:
382
+ """
383
+ Create a TfEvaluators instance for future-only calculations.
384
+
385
+ Args:
386
+ date: Evaluation date column expression
387
+
388
+ Returns:
389
+ TfEvaluators: Configured evaluator instance
390
+ """
391
+ return TfEvaluators(
392
+ future=self.future,
393
+ bond=None,
394
+ date=date,
395
+ bond_ytm=None,
396
+ future_price=None,
397
+ capital_rate=None,
398
+ reinvest_rate=None,
399
+ )
400
+
401
+ def deliver_date(self):
402
+ """
403
+ Calculate delivery date (交割日).
404
+
405
+ Args:
406
+ date: Evaluation date column expression
407
+
408
+ Returns:
409
+ Polars expression for delivery date
410
+ """
411
+ return self._evaluator().deliver_date
412
+
413
+ def last_trading_date(self):
414
+ """
415
+ Calculate last trading date (最后交易日).
416
+
417
+ Args:
418
+ date: Evaluation date column expression
419
+
420
+ Returns:
421
+ Polars expression for last trading date
422
+ """
423
+ return self._evaluator().last_trading_date
424
+
425
+
349
426
  def find_workday(date: IntoExpr, market: str | Ib | Sse, offset: int = 0):
350
427
  """
351
428
  Find the workday based on the given date and market calendar.
pybond/pnl.py CHANGED
@@ -9,6 +9,52 @@ if TYPE_CHECKING:
9
9
  from .polars_utils import parse_into_expr, register_plugin
10
10
 
11
11
 
12
+ class Fee:
13
+ """Represents a fee for a trade."""
14
+
15
+ def __init__(self, fee_str: str = ""):
16
+ self.str = fee_str
17
+
18
+ def __add__(self, other: Fee) -> Fee:
19
+ return Fee(self.str + "+" + other.str)
20
+
21
+ def __radd__(self, other: Fee) -> Fee:
22
+ return Fee(other.str + "+" + self.str)
23
+
24
+ @staticmethod
25
+ def trade(fee) -> TradeFee:
26
+ return TradeFee(fee)
27
+
28
+ @staticmethod
29
+ def qty(fee) -> QtyFee:
30
+ return QtyFee(fee)
31
+
32
+ @staticmethod
33
+ def percent(fee) -> PercentFee:
34
+ return PercentFee(fee)
35
+
36
+
37
+ class TradeFee(Fee):
38
+ """Represents a fixed fee for a trade."""
39
+
40
+ def __init__(self, fee: float):
41
+ self.str = f"Trade({fee})"
42
+
43
+
44
+ class QtyFee(Fee):
45
+ """Represents a fee based on the quantity of a trade."""
46
+
47
+ def __init__(self, fee: float):
48
+ self.str = f"Qty({fee})"
49
+
50
+
51
+ class PercentFee(Fee):
52
+ """Represents a fee based on a percentage of the trade amount."""
53
+
54
+ def __init__(self, fee: float):
55
+ self.str = f"Percent({fee})"
56
+
57
+
12
58
  def calc_bond_trade_pnl(
13
59
  settle_time: IntoExpr,
14
60
  qty: IntoExpr,
@@ -17,11 +63,13 @@ def calc_bond_trade_pnl(
17
63
  symbol: str = "",
18
64
  bond_info_path: str | None = None,
19
65
  multiplier: float = 1,
20
- c_rate: float = 0,
66
+ fee: str | Fee = "",
21
67
  borrowing_cost: float = 0,
22
68
  capital_rate: float = 0,
23
69
  begin_state=None,
24
70
  ) -> pl.Expr:
71
+ if isinstance(fee, Fee):
72
+ fee = fee.str
25
73
  settle_time = parse_into_expr(settle_time)
26
74
  qty = parse_into_expr(qty)
27
75
  clean_price = parse_into_expr(clean_price)
@@ -41,11 +89,12 @@ def calc_bond_trade_pnl(
41
89
  "unrealized_pnl": 0,
42
90
  "coupon_paid": 0,
43
91
  "amt": 0,
92
+ "fee": 0,
44
93
  }
45
94
  kwargs = {
46
95
  "symbol": symbol,
47
96
  "multiplier": multiplier,
48
- "c_rate": c_rate,
97
+ "fee": fee,
49
98
  "borrowing_cost": borrowing_cost,
50
99
  "capital_rate": capital_rate,
51
100
  "begin_state": begin_state,
pybond/pybond.abi3.so CHANGED
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tea-bond
3
- Version: 0.3.6
3
+ Version: 0.3.8
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -17,12 +17,12 @@ pybond/nb/nb_datetime.py,sha256=9fLD9rnfpHQ-cvX4H6PoFh_O3jgk475ZKrG8q_UxT34,1026
17
17
  pybond/nb/nb_duration.py,sha256=FSX1y2JbHB_SJn-hcVe-7Zf2v0xpQKKZ1MfWBY7d7IQ,1639
18
18
  pybond/nb/nb_evaluators.py,sha256=fCYxcvW717_1E4qY9AV8R5Pv8eTvWqKk3Zj-zMU1kiw,14987
19
19
  pybond/nb/nb_time.py,sha256=LaqXfcNvmYD_lZ2u108MwrxCXoVCBX3cr3oOnPp3c1g,8649
20
- pybond/pd.py,sha256=QmkADhIu0T7w1pbhYZB9dFDaPSO9aZ3kdFxktZf5Kro,11591
21
- pybond/pl.py,sha256=fk5AGXym02gCkJIZmOpQRPf1qnqYUa1V_PawbeYm7WE,11285
22
- pybond/pnl.py,sha256=P3KXc-gz6_TA2QxDQR9NHJIJPCvLOGT_v4qN4gzdcRY,1568
20
+ pybond/pd.py,sha256=yDEurCNedu5Q821XFbqsHBAblv9hBDwc3Z3hwdt_lyo,13122
21
+ pybond/pl.py,sha256=7HTX2Eu6hDccy4WJpxej2_UjKQXk6KvWdISt54lqGSk,13234
22
+ pybond/pnl.py,sha256=zDHDShaU5Cpp47JELb3u9xURSkm-1NUiZ5aFdwtwWf4,2644
23
23
  pybond/polars_utils.py,sha256=A8D5T0x08oMCndWiQ5DPhLsuWp8s4OPgqvAnK36d8yY,2567
24
- pybond/pybond.abi3.so,sha256=ReHF3MqeZuEwzV4P5e9tiBdwOOiT3VwxZEevAYzUTEA,30544073
24
+ pybond/pybond.abi3.so,sha256=gYg8tqhCAXdorc3H9TY_yAgOD_pyfooW-PkyUhiloN4,30589305
25
25
  pybond/pybond.pyi,sha256=xME119HJzVNqNCJ9FapVaQg1amxbNHlbd-qfFyiuhL4,11230
26
- tea_bond-0.3.6.dist-info/METADATA,sha256=bE4jcL34IITAPfiDtrul27hgpgLBxDn2m8KxscZgANw,258
27
- tea_bond-0.3.6.dist-info/WHEEL,sha256=QUqTgYGwY2EWSp2nZb9WOq7FyV4zGcx0XCx5wrEnnjI,107
28
- tea_bond-0.3.6.dist-info/RECORD,,
26
+ tea_bond-0.3.8.dist-info/METADATA,sha256=iFDD8dsw7ptVOSC_aR1cOepgVmUCQVxGKW423JB2BKU,258
27
+ tea_bond-0.3.8.dist-info/WHEEL,sha256=QUqTgYGwY2EWSp2nZb9WOq7FyV4zGcx0XCx5wrEnnjI,107
28
+ tea_bond-0.3.8.dist-info/RECORD,,