tea-bond 0.3.6__cp310-abi3-win_amd64.whl → 0.3.8__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
|
|
|
@@ -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
|
-
|
|
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
|
-
"
|
|
97
|
+
"fee": fee,
|
|
49
98
|
"borrowing_cost": borrowing_cost,
|
|
50
99
|
"capital_rate": capital_rate,
|
|
51
100
|
"begin_state": begin_state,
|
pybond/pybond.pyd
CHANGED
|
Binary file
|
|
@@ -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=
|
|
19
|
-
pybond/pl.py,sha256=
|
|
20
|
-
pybond/pnl.py,sha256=
|
|
18
|
+
pybond/pd.py,sha256=SSQdg4hzc9dLN53ICTI65UyAEkAvKnAt98u9EX09IqM,13575
|
|
19
|
+
pybond/pl.py,sha256=kB0rxuJjZnD8tm_c5Vmy6iGxmstaB51qzr65M9vR4sA,13706
|
|
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=
|
|
22
|
+
pybond/pybond.pyd,sha256=mvYdCwkfJP-GuHltpv2c-Sn8GepMZ5QvEU-PAeUCJd0,23558656
|
|
23
23
|
pybond/pybond.pyi,sha256=qzOfqoysuUW7rnZYxEmGEJXK_UrCjMvQ29Y_mJOBN1Y,11621
|
|
24
|
-
tea_bond-0.3.
|
|
25
|
-
tea_bond-0.3.
|
|
26
|
-
tea_bond-0.3.
|
|
24
|
+
tea_bond-0.3.8.dist-info/METADATA,sha256=iFDD8dsw7ptVOSC_aR1cOepgVmUCQVxGKW423JB2BKU,258
|
|
25
|
+
tea_bond-0.3.8.dist-info/WHEEL,sha256=G8mq-RexZGAfbjW58CyHDPQ4EbuJINRXbIh22TbaFhw,95
|
|
26
|
+
tea_bond-0.3.8.dist-info/RECORD,,
|
|
File without changes
|