Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed Jul 11, 2023
1 parent 73c6c7b commit e0ce0a1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Analytics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
6 changes: 3 additions & 3 deletions src/Liability.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/UT/BondTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e0ce0a1

Please sign in to comment.