diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2023-01-24 14:38:23 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2023-01-24 14:38:23 -0500 |
| commit | eb0aedd63787f690fa7b45eeb889dced00c66220 (patch) | |
| tree | 641e41775e4c312b296167ec8dfa4417151a1624 | |
| parent | 972c4ec8976c51e275ab8c5b01067e26bfe13a79 (diff) | |
| download | pyisda-eb0aedd63787f690fa7b45eeb889dced00c66220.tar.gz | |
more tests
| -rw-r--r-- | unpack.py | 38 |
1 files changed, 28 insertions, 10 deletions
@@ -1,7 +1,8 @@ from serenitas.utils.db2 import dbconn from lz4.block import decompress import datetime -from construct import Enum, CString, Struct, Int32ul, Int32sl, Int64ul, Int64sl, Float64l, this +from construct import Enum, CString, Struct, Int8ul, Int32ul, Int32sl, Int64ul, Int64sl, Float64l, this +from pyisda.curve import YieldCurve as CYieldCurve, SpreadCurve as CSpreadCurve TRatePt = Struct("fDate" / Int64sl, "fRate" / Float64l) @@ -16,18 +17,28 @@ YieldCurve = Struct("curve" / TCurve, CurveName = Struct("Seniority" / Enum(Int32ul, Senior=0, Subordinated=1), "DocClause" / Enum(Int32ul, XR14=0, MR14=1, MM14=2, CR14=3), "ticker" / CString("utf8")) - -SurvivalCurve = Struct("curve" / TCurve, - "recovery" / Float64l[this.curve.fNumItems], - "defaulted" / Int64sl, - "name" / CurveName) - -NewTCurve = Struct("fNumItems" / Int32sl, +SpreadCurve = Struct("curve" / TCurve, + "recovery" / Float64l[this.curve.fNumItems], + "defaulted" / Int64sl, + "name" / CurveName) +TCurve_v1 = Struct("fNumItems" / Int32sl, "fDayCountConv" / Int32sl, "fBaseDate" / Int64sl, "fBasis" / Float64l, "fArray" / TRatePt[this.fNumItems]) +YieldCurve_v1 = Struct("curve" / TCurve_v1) +CurveName_v1 = Struct("Seniority" / Enum(Int8ul, Senior=0, Subordinated=1), + "DocClause" / Enum(Int8ul, XR14=0, MR14=1, MM14=2, CR14=3), + "ticker" / CString("utf8")) + + +SpreadCurve_v1 = Struct("curve" / TCurve_v1, + "recovery" / Float64l[this.curve.fNumItems], + "defaulted" / Int64sl, + "name" / CurveName_v1) + + serenitasdb = dbconn("serenitasdb") with serenitasdb.cursor(binary=True) as c: c.execute('SELECT curve FROM rate_curves WHERE effective_date=%s AND curve_type=%s', @@ -35,11 +46,18 @@ with serenitasdb.cursor(binary=True) as c: (state,) = c.fetchone() curve = decompress(state, 500) yc = YieldCurve.parse(curve) + yc_prime = CYieldCurve.from_bytes(state) + curve_v1 = yc_prime.as_bytes(False) + yc_v1 = YieldCurve_v1.parse(curve_v1) c.execute('SELECT curve FROM cds_curves WHERE date=%s AND redcode=%s', (datetime.date(2023, 1, 9), 'EKFHAH')) (state,) = c.fetchone() curve = decompress(state, 600) - sc = SurvivalCurve.parse(curve) + sc = SpreadCurve.parse(curve) + breakpoint() + sc_prime = CSpreadCurve.from_bytes(state, compressed=True) + curve_v1 = sc_prime.as_bytes(False) + sc_v1 = SpreadCurve_v1.parse(curve_v1) -new_yc = NewTCurve.build({"fNumItems":yc.curve.fNumItems, "fDayCountConv":yc.curve.fDayCountConv, "fBaseDate":yc.curve.fBaseDate, +new_yc = TCurve_v1.build({"fNumItems":yc.curve.fNumItems, "fDayCountConv":yc.curve.fDayCountConv, "fBaseDate":yc.curve.fBaseDate, "fBasis":yc.curve.fBasis, "fArray":yc.curve.fArray}) |
