tea-bond 0.3.7__cp310-abi3-macosx_11_0_arm64.whl → 0.3.9__cp310-abi3-macosx_11_0_arm64.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(
|
|
54
|
-
|
|
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 =
|
|
23
|
-
bond_ytm: IntoExpr =
|
|
24
|
-
capital_rate: IntoExpr =
|
|
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
|
-
|
|
40
|
-
future
|
|
41
|
-
|
|
42
|
-
self.bond = parse_into_expr(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
self.
|
|
46
|
-
|
|
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.abi3.so
CHANGED
|
Binary file
|
|
@@ -15,12 +15,12 @@ pybond/nb/nb_datetime.py,sha256=9fLD9rnfpHQ-cvX4H6PoFh_O3jgk475ZKrG8q_UxT34,1026
|
|
|
15
15
|
pybond/nb/nb_duration.py,sha256=FSX1y2JbHB_SJn-hcVe-7Zf2v0xpQKKZ1MfWBY7d7IQ,1639
|
|
16
16
|
pybond/nb/nb_evaluators.py,sha256=fCYxcvW717_1E4qY9AV8R5Pv8eTvWqKk3Zj-zMU1kiw,14987
|
|
17
17
|
pybond/nb/nb_time.py,sha256=LaqXfcNvmYD_lZ2u108MwrxCXoVCBX3cr3oOnPp3c1g,8649
|
|
18
|
-
pybond/pd.py,sha256=
|
|
19
|
-
pybond/pl.py,sha256=
|
|
18
|
+
pybond/pd.py,sha256=u37c9_CYTopUm8Z5OZUPDLlhzAcNUCVL79yOpdj3U30,13302
|
|
19
|
+
pybond/pl.py,sha256=eXu_rcggdBKXLuzyLj65StIw45Jfu44EmTNi06WOBbo,13486
|
|
20
20
|
pybond/pnl.py,sha256=zDHDShaU5Cpp47JELb3u9xURSkm-1NUiZ5aFdwtwWf4,2644
|
|
21
21
|
pybond/polars_utils.py,sha256=A8D5T0x08oMCndWiQ5DPhLsuWp8s4OPgqvAnK36d8yY,2567
|
|
22
|
-
pybond/pybond.abi3.so,sha256=
|
|
22
|
+
pybond/pybond.abi3.so,sha256=RqxkmIlDrx3rAbIvoqh7v_SnuHO_2eG-e4tUvHy6fEA,23207616
|
|
23
23
|
pybond/pybond.pyi,sha256=xME119HJzVNqNCJ9FapVaQg1amxbNHlbd-qfFyiuhL4,11230
|
|
24
|
-
tea_bond-0.3.
|
|
25
|
-
tea_bond-0.3.
|
|
26
|
-
tea_bond-0.3.
|
|
24
|
+
tea_bond-0.3.9.dist-info/METADATA,sha256=NTcEhk7-WT_aWbCc5fmxZbZecfzQa6O3PB0tozeRyhs,258
|
|
25
|
+
tea_bond-0.3.9.dist-info/WHEEL,sha256=Mdosfxua6Dx1zYgObRH97e3wyiELqBbLtoRJj4RUSQE,103
|
|
26
|
+
tea_bond-0.3.9.dist-info/RECORD,,
|
|
File without changes
|