@@ -2160,18 +2160,53 @@ def mkFee(x,fsDate=None):
21602160 case _:
21612161 raise RuntimeError (f"Failed to match fee: { x } " )
21622162
2163+ def mkBondPricingMethod (x ):
2164+ match x :
2165+ case ("byFactor" , f ):
2166+ return mkTag (("BondBalanceFactor" , f ))
2167+ case ("byRate" , r ):
2168+ return mkTag (("PvBondByRate" , r ))
2169+ case ("byCurve" , ts ):
2170+ return mkTag (("PvBondByCurve" , ts ))
2171+ case _:
2172+ raise RuntimeError (f"Failed to match bondPricingMethod: { x } " )
2173+
2174+ def mkTradeType (x ):
2175+ match x :
2176+ case ("byCash" , cash ):
2177+ return mkTag (("ByCash" , vNum (cash )))
2178+ case ("byBalance" , balance ):
2179+ return mkTag (("ByBalance" , vNum (cash )))
2180+ case _:
2181+ raise RuntimeError (f"Failed to match trade Type: { x } " )
2182+
2183+ def mkIrrType (x ):
2184+ match x :
2185+ case ("holding" , historyCash , holding ):
2186+ return mkTag (("HoldingBond" , [historyCash , vNum (holding ), None ]))
2187+ case ("holding" , historyCash , holding , d , bondPricing ):
2188+ return mkTag (("HoldingBond" , [historyCash , vNum (holding ), (vDate (d ), mkBondPricingMethod (bondPricing ))]))
2189+ case ("buy" , d , bondPricing , tradeType ):
2190+ return mkTag (("BuyBond" , [vDate (d ), mkBondPricingMethod (bondPricing ), mkTradeType (tradeType ), None ]))
2191+ case _:
2192+ raise RuntimeError (f"Failed to match irrType: { x } " )
2193+
2194+
21632195
21642196def mkPricingAssump (x ):
21652197 match x :
2166- case {"贴现日" : pricingDay , "贴现曲线" : xs } | {"date" : pricingDay , "curve" : xs }| {"PVDate" : pricingDay , "PVCurve" : xs }:
2198+ case ( "pv" , pricingDay , xs ) | {"贴现日" : pricingDay , "贴现曲线" : xs } | {"date" : pricingDay , "curve" : xs }| {"PVDate" : pricingDay , "PVCurve" : xs }:
21672199 return mkTag (("DiscountCurve" , [vDate (pricingDay ), mkTs ("IRateCurve" , xs )]))
2168- case {"债券" : bnd_with_price , "利率曲线" : rdps } | {"bonds" : bnd_with_price , "curve" : rdps }:
2200+ case ( "zspread" , bnd_with_price , rdps ) | {"债券" : bnd_with_price , "利率曲线" : rdps } | {"bonds" : bnd_with_price , "curve" : rdps }:
21692201 return mkTag (("RunZSpread" , [mkTs ("IRateCurve" , rdps ), bnd_with_price ]))
2202+ case ("irr" , m ) | {"IRR" : m } | {"Irr" : m } if isinstance (m , dict ):
2203+ return mkTag (("IrrInput" , mapValsBy (m , mkIrrType )))
21702204 case _:
21712205 raise RuntimeError (f"Failed to match pricing assumption: { x } " )
21722206
21732207
21742208def readPricingResult (x , locale ) -> dict | None :
2209+ """ Read pricing result """
21752210 if x is None :
21762211 return None
21772212 h = None
@@ -2182,6 +2217,8 @@ def readPricingResult(x, locale) -> dict | None:
21822217 "en" : ["pricing" , "face" , "WAL" , "duration" , "convexity" , "accure interest" ]}
21832218 elif tag == "ZSpread" :
21842219 h = {"cn" : ["静态利差" ], "en" : ["Z-spread" ]}
2220+ elif tag == "IrrResult" :
2221+ h = {"cn" : ["IRR" ], "en" : ["IRR" ]}
21852222 else :
21862223 raise RuntimeError (f"Failed to read princing result: { x } with tag={ tag } " )
21872224
@@ -2193,10 +2230,11 @@ def readPricingResult(x, locale) -> dict | None:
21932230
21942231 pricingResult = pd .DataFrame .from_dict (tz .valmap (lambda y :y ['contents' ][:- 1 ],x )
21952232 , orient = 'index' , columns = h [locale ]).sort_index ()
2196- #
2233+
21972234 return {"summary" :pricingResult
2198- ,"breakdown" :tz .valmap (lambda z : pd .DataFrame ( [ _ ['contents' ] for _ in z ['contents' ][- 1 ]], columns = english_bondflow_fields ).set_index ("date" ), x )
2199- }
2235+ ,"breakdown" :tz .valmap (lambda z : pd .DataFrame ([ _ ['contents' ] for _ in z ['contents' ][- 1 ]]
2236+ , columns = english_bondflow_fields ).set_index ("date" )
2237+ , x )}
22002238
22012239
22022240def readPoolCf (x , lang = 'english' ):
0 commit comments