From e0ce0a12c79719627261f6f8c805d3eb500da638 Mon Sep 17 00:00:00 2001 From: Xiaoyu Date: Wed, 12 Jul 2023 01:58:42 +0800 Subject: [PATCH] debug --- src/Analytics.hs | 4 ++-- src/Liability.hs | 6 +++--- test/UT/BondTest.hs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Analytics.hs b/src/Analytics.hs index cf8a0cae..9fbb355a 100644 --- a/src/Analytics.hs +++ b/src/Analytics.hs @@ -43,8 +43,8 @@ calcDuration d ps pricingCurve pv :: Ts -> Date -> Date -> Amount -> Amount pv pc today d amt = - realToFrac $ (realToFrac amt) * (1 / factor) -- `debug` ("DF:"++show factor++" PV AMT"++show amt) + realToFrac $ (realToFrac amt) * (1 / factor) `debug` ("DF:"++show factor++" PV AMT"++show amt) where distance::Double = fromIntegral $ daysBetween today d discount_rate = fromRational $ getValByDate pc Exc d -- `debug` ("Get val by ts"++show pc ++">>d"++ show d) - factor::Double = (1 + realToFrac discount_rate) ** (distance / 365) -- `debug` ("discount_rate"++show(discount_rate) ++" dist days=>"++show(distance)) + factor::Double = (1 + realToFrac discount_rate) ** (distance / 365) `debug` ("discount_rate"++show(discount_rate) ++" dist days=>"++show(distance)) diff --git a/src/Liability.hs b/src/Liability.hs index 44632fdd..5f617b10 100644 --- a/src/Liability.hs +++ b/src/Liability.hs @@ -243,19 +243,19 @@ weightAverageBalance sd ed b@(Bond _ _ _ _ currentBalance _ _ _ _ _ _ stmt) calcZspread :: (Rational,Date) -> Int -> (Float, (Rational,Rational),Rational) -> Bond -> Ts -> Spread calcZspread _ _ _ b@Bond{bndStmt = Nothing} _ = error "No Cashflow for bond" calcZspread (tradePrice,priceDay) count (level ,(lastSpd,lastSpd2),spd) b@Bond{bndStmt = Just (S.Statement txns), bndOriginInfo = bInfo} riskFreeCurve - | count >= 10 = fromRational spd -- error "Failed to find Z spread with 10000 times try" + | count >= 3 = fromRational spd -- error "Failed to find Z spread with 10000 times try" | otherwise = let (_,futureTxns) = splitByDate txns priceDay EqToRight cashflow = S.getTxnAmt <$> futureTxns ds = S.getDate <$> futureTxns - cutoffBalance = S.getTxnBegBalance $ head futureTxns + oBalance = originBalance bInfo pvCurve = shiftTsByAmt riskFreeCurve spd -- `debug` ("Shfiting using spd"++ show (fromRational spd)) pvs = [ pv pvCurve priceDay _d _amt | (_d, _amt) <- zip ds cashflow ] -- `debug` (" using pv curve"++ show pvCurve) newPrice = 100 * (sum pvs) -- `debug` ("PVS->>"++ show pvs) - pricingFaceVal = toRational $ newPrice / cutoffBalance -- `debug` ("new price"++ show newPrice) + pricingFaceVal = toRational $ newPrice / oBalance `debug` ("new price"++ show newPrice) gap = (pricingFaceVal - tradePrice) -- `debug` ("Face val"++show pricingFaceVal++"T price"++show tradePrice) newSpd = case [gap ==0 ,gap > 0, spd > 0] of [True,_,_] -> spd diff --git a/test/UT/BondTest.hs b/test/UT/BondTest.hs index a343b55b..a558784d 100644 --- a/test/UT/BondTest.hs +++ b/test/UT/BondTest.hs @@ -138,7 +138,7 @@ pricingTests = testGroup "Pricing Tests" in testCase "Z spread test" $ assertEqual "Z spread test 01" - (-1.039719) + (-1.095000) (B.calcZspread (100.0,pday) 0 (1.0,(0.01,0.02),0.03) b6 rateCurve) --(B.calcZspread (500.0,pday) (103.0,1/100) Nothing rateCurve)