Skip to content

Commit

Permalink
enhance perf
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed Jul 17, 2023
1 parent d5d8f0a commit 5490822
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Liability.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ fv2 discount_rate today futureDay amt =

priceBond :: Date -> Ts -> Bond -> PriceResult
priceBond d rc b@(Bond bn _ (OriginalInfo obal od _ _) _ bal cr _ _ _ lastIntPayDay _ (Just (S.Statement txns)))
| length futureCf == 0 = PriceResult 0 0 0 0 0 0
| sum (S.getTxnAmt <$> futureCf) == 0 = PriceResult 0 0 0 0 0 0 -- `debug` ("Passing 0")
| otherwise =
let
presentValue = foldr (\x acc -> acc + (pv rc d (S.getDate x) (S.getTxnAmt x))) 0 futureCf -- `debug` "PRICING -A"
cutoffBalance = case (S.getTxnAsOf txns d) of
Nothing -> (S.getTxnBalance fstTxn) + (S.getTxnPrincipal fstTxn) -- `debug` (show(getTxnBalance fstTxn))
where
fstTxn = head txns
Just _txn -> S.getTxnBalance _txn -- `debug` ("presentValue"++show presentValue++"Bond->"++bn)
Just _txn -> S.getTxnBalance _txn -- `debug` ("presentValue"++show presentValue++"Bond->"++bn)
accruedInt = case _t of
Nothing -> (fromIntegral (max 0 (T.diffDays d leftPayDay))/365) * (mulBI leftBal cr)
Just _ -> 0 -- `debug` ("all txn"++show(_t))-- `debug` ("l day, right"++show(leftPayDay)++show(d)++show(T.diffDays leftPayDay d))
Expand Down Expand Up @@ -180,7 +180,7 @@ priceBond d rc b@(Bond bn _ (OriginalInfo obal od _ _) _ bal cr _ _ _ lastIntPay
_cash_date = S.getDate x
_yield = getValByDate rc Exc _cash_date
_y = (1+ _yield) * (1+ _yield) -- `debug` ("yield->"++ show _yield++"By date"++show d)
_x = ((mulBR (pv rc d _cash_date (S.getTxnAmt x)) _t2) / (fromRational _y)) `debug` ("PRICING -E") -- `debug` ("PV:->"++show (pv rc d (S.getTxnDate x) (S.getTxnAmt x))++"Y->"++ show _y++"T2-->"++ show _t2)
_x = ((mulBR (pv rc d _cash_date (S.getTxnAmt x)) _t2) / (fromRational _y)) -- `debug` ("PRICING -E") -- `debug` ("PV:->"++show (pv rc d (S.getTxnDate x) (S.getTxnAmt x))++"Y->"++ show _y++"T2-->"++ show _t2)
in
_x + acc)
0
Expand Down

0 comments on commit 5490822

Please sign in to comment.