From 416b91ad9d685521783c1b2425de197bb7e94290 Mon Sep 17 00:00:00 2001 From: Xiaoyu Date: Sat, 7 Sep 2024 13:39:29 +0800 Subject: [PATCH] expose obligor field --- src/AssetClass/AssetBase.hs | 21 +++++++---- src/AssetClass/Installment.hs | 28 +++++++-------- src/AssetClass/Lease.hs | 68 +++++++++++++++++------------------ src/AssetClass/Loan.hs | 60 ++++++++++--------------------- src/AssetClass/Mortgage.hs | 62 ++++++++++++++++---------------- src/AssetClass/Receivable.hs | 34 +++++++++--------- src/Assumptions.hs | 2 +- test/UT/AnalyticsTest.hs | 4 +-- test/UT/AssetTest.hs | 49 ++++++++++++------------- 9 files changed, 158 insertions(+), 170 deletions(-) diff --git a/src/AssetClass/AssetBase.hs b/src/AssetClass/AssetBase.hs index ba35f75..cdcbdb7 100644 --- a/src/AssetClass/AssetBase.hs +++ b/src/AssetClass/AssetBase.hs @@ -127,23 +127,31 @@ data ReceivableFeeType = FixedFee Balance -- ^ a flat fee amo deriving (Show,Generic,Eq,Ord) +data Obligor = Obligor {obligorId :: Int + , obligorTag :: [String] + , obligorFields :: Map.Map String (Either String Double) + } deriving (Show,Generic,Eq,Ord) + data OriginalInfo = MortgageOriginalInfo { originBalance :: Balance ,originRate :: IR.RateType ,originTerm :: Int ,period :: Period ,startDate :: Date ,prinType :: AmortPlan - ,prepaymentPenalty :: Maybe PrepayPenaltyType } + ,prepaymentPenalty :: Maybe PrepayPenaltyType + ,obligor :: Maybe Obligor } | LoanOriginalInfo { originBalance :: Balance ,originRate :: IR.RateType ,originTerm :: Int ,period :: Period ,startDate :: Date - ,prinType :: AmortPlan } + ,prinType :: AmortPlan + ,obligor :: Maybe Obligor } | LeaseInfo { startDate :: Date -- ^ lease start date ,originTerm :: Int -- ^ total terms ,paymentDates :: DatePattern -- ^ payment dates pattern - ,originRental :: Amount} -- ^ rental by day + ,originRental :: Amount -- ^ rental by day + ,obligor :: Maybe Obligor } | FixedAssetInfo { startDate :: Date ,originBalance :: Balance ,residualBalance :: Balance @@ -155,7 +163,8 @@ data OriginalInfo = MortgageOriginalInfo { originBalance :: Balance ,originBalance :: Balance ,originAdvance :: Balance ,dueDate :: Date - ,feeType :: Maybe ReceivableFeeType } + ,feeType :: Maybe ReceivableFeeType + ,obligor :: Maybe Obligor } deriving (Show,Generic,Ord,Eq) @@ -283,7 +292,7 @@ instance IR.UseRate ProjectedCashflow where = Just $ (\(a,b,c) -> c) <$> fs -$(concat <$> traverse (deriveJSON defaultOptions) [''OriginalInfo, ''FixedAsset, ''AmortPlan, ''PrepayPenaltyType +$(concat <$> traverse (deriveJSON defaultOptions) [''Obligor, ''OriginalInfo, ''FixedAsset, ''AmortPlan, ''PrepayPenaltyType , ''Capacity, ''AmortRule, ''ReceivableFeeType]) @@ -311,7 +320,7 @@ instance ToSchema (TsPoint IRate) instance ToSchema (TsPoint Rational) instance ToSchema (TsPoint Bool) instance ToSchema (RoundingBy IRate) - +instance ToSchema Obligor instance ToSchema Index instance ToSchema DayCount instance ToSchema Direction diff --git a/src/AssetClass/Installment.hs b/src/AssetClass/Installment.hs index c1eafc2..8ee7666 100644 --- a/src/AssetClass/Installment.hs +++ b/src/AssetClass/Installment.hs @@ -71,7 +71,7 @@ projectInstallmentFlow (startBal, lastPaidDate, (originRepay,originInt), startRa instance Asset Installment where - calcCashflow inst@(Installment (LoanOriginalInfo ob or ot p sd ptype) cb rt st) asOfDay _ + calcCashflow inst@(Installment (LoanOriginalInfo ob or ot p sd ptype _) cb rt st) asOfDay _ = CF.CashFlowFrame (cb,asOfDay,Nothing) flows where lastPayDate:cf_dates = lastN (rt+1) $ sd:getPaymentDates inst 0 @@ -103,9 +103,9 @@ instance Asset Installment where getCurrentBal (Installment _ b _ _ ) = b - getOriginBal (Installment (LoanOriginalInfo ob _ _ _ _ _) _ _ _) = ob + getOriginBal (Installment (LoanOriginalInfo ob _ _ _ _ _ _) _ _ _) = ob - getOriginRate (Installment (LoanOriginalInfo _ or _ _ _ _) _ _ _) + getOriginRate (Installment (LoanOriginalInfo _ or _ _ _ _ _) _ _ _) = case or of Fix _ _r -> _r Floater _ _ _ _r _ _ _ _ -> _r @@ -113,20 +113,20 @@ instance Asset Installment where isDefaulted (Installment _ _ _ (Defaulted _)) = True isDefaulted (Installment {}) = False - getPaymentDates (Installment (LoanOriginalInfo _ _ ot p sd _) _ _ _) extra + getPaymentDates (Installment (LoanOriginalInfo _ _ ot p sd _ _) _ _ _) extra = genDates sd p (ot+extra) - getOriginDate (Installment (LoanOriginalInfo _ _ ot p sd _) _ _ _) = sd + getOriginDate (Installment (LoanOriginalInfo _ _ ot p sd _ _) _ _ _) = sd - getRemainTerms (Installment (LoanOriginalInfo _ _ ot p sd _) _ rt _) = rt + getRemainTerms (Installment (LoanOriginalInfo _ _ ot p sd _ _) _ rt _) = rt - updateOriginDate (Installment (LoanOriginalInfo ob or ot p sd _type) cb rt st) nd - = Installment (LoanOriginalInfo ob or ot p nd _type) cb rt st + updateOriginDate (Installment (LoanOriginalInfo ob or ot p sd _type _obligor) cb rt st) nd + = Installment (LoanOriginalInfo ob or ot p nd _type _obligor) cb rt st - resetToOrig (Installment (LoanOriginalInfo ob or ot p sd _type) cb rt st) - = Installment (LoanOriginalInfo ob or ot p sd _type) ob ot st + resetToOrig (Installment (LoanOriginalInfo ob or ot p sd _type _obligor) cb rt st) + = Installment (LoanOriginalInfo ob or ot p sd _type _obligor) ob ot st - projCashflow inst@(Installment (LoanOriginalInfo ob or ot p sd pt) cb rt Current) + projCashflow inst@(Installment (LoanOriginalInfo ob or ot p sd pt _) cb rt Current) asOfDay pAssump@(A.InstallmentAssump defaultAssump prepayAssump recoveryAssump ams,_,_) mRates @@ -152,7 +152,7 @@ instance Asset Installment where -- ^ project with defaulted at a date - projCashflow inst@(Installment (LoanOriginalInfo ob or ot p sd ptype) cb rt (Defaulted (Just defaultedDate))) + projCashflow inst@(Installment (LoanOriginalInfo ob or ot p sd ptype _) cb rt (Defaulted (Just defaultedDate))) asOfDay (_,_,(A.DefaultedRecovery rr lag timing)) mRates @@ -171,7 +171,7 @@ instance Asset Installment where projCashflow inst@(Installment _ cb rt (Defaulted Nothing)) asOfDay assumps _ = (CF.CashFlowFrame (cb, asOfDay, Nothing) $ [CF.LoanFlow asOfDay cb 0 0 0 0 0 0 (getOriginRate inst) Nothing],Map.empty) - splitWith (Installment (LoanOriginalInfo ob or ot p sd _type) cb rt st) rs - = [ Installment (LoanOriginalInfo (mulBR ob ratio) or ot p sd _type) (mulBR cb ratio) rt st | ratio <- rs ] + splitWith (Installment (LoanOriginalInfo ob or ot p sd _type _obligor) cb rt st) rs + = [ Installment (LoanOriginalInfo (mulBR ob ratio) or ot p sd _type _obligor) (mulBR cb ratio) rt st | ratio <- rs ] diff --git a/src/AssetClass/Lease.hs b/src/AssetClass/Lease.hs index 9f88710..6ccd0bc 100644 --- a/src/AssetClass/Lease.hs +++ b/src/AssetClass/Lease.hs @@ -64,8 +64,8 @@ accrueRentals rc@(LeftBalanceCurve tps) pd@(payD:payDs) accrueCutoff payAmts (payAmts ++ [accrueRentalBetween accrueCutoff payD rc]) -- `debug` ("ACCRENTALS"++ show accrueCutoff++">>"++show payD++"rc+"++ show rc) nextLease :: Lease -> (RentChangeCurve, TermChangeRate, DayGap) -> (Lease, Date) -nextLease l@(RegularLease (LeaseInfo sd ot dp dr) bal rt _) (rcCurve,tc,gd) - = (RegularLease (LeaseInfo nextStartDate nextOriginTerm dp nextDailyRate) newBal rt Current,nextEndDate) -- `debug` ("1+tc"++show (1+tc) ++">>"++ show (mulIR ot (1+tc))) +nextLease l@(RegularLease (LeaseInfo sd ot dp dr ob) bal rt _) (rcCurve,tc,gd) + = (RegularLease (LeaseInfo nextStartDate nextOriginTerm dp nextDailyRate ob) newBal rt Current,nextEndDate) -- `debug` ("1+tc"++show (1+tc) ++">>"++ show (mulIR ot (1+tc))) where leaseEndDate = last $ projectCfDates dp sd ot nextStartDate = T.addDays (succ (toInteger gd)) leaseEndDate -- `debug` ("Gap Day ->"++ show gd) @@ -76,8 +76,8 @@ nextLease l@(RegularLease (LeaseInfo sd ot dp dr) bal rt _) (rcCurve,tc,gd) nextDailyRate = dr + mulBR dr currentRateOnCurve*(fromRational yearsBetween) newBal = fromRational $ mulBInteger nextDailyRate $ daysBetween nextStartDate nextEndDate -nextLease l@(StepUpLease (LeaseInfo sd ot dp dr) lsteupInfo bal rt _) (rcCurve,tc,gd) - = (StepUpLease (LeaseInfo nextStartDate nextOriginTerm dp nextDailyRate) lsteupInfo newBal rt Current,nextEndDate) -- `debug` ("leaseEndDate>>"++show leaseEndDate++">>>"++show (succ (toInteger gd))) +nextLease l@(StepUpLease (LeaseInfo sd ot dp dr ob) lsteupInfo bal rt _) (rcCurve,tc,gd) + = (StepUpLease (LeaseInfo nextStartDate nextOriginTerm dp nextDailyRate ob) lsteupInfo newBal rt Current,nextEndDate) -- `debug` ("leaseEndDate>>"++show leaseEndDate++">>>"++show (succ (toInteger gd))) where leaseEndDate = last $ projectCfDates dp sd ot nextStartDate = T.addDays (succ (toInteger gd)) leaseEndDate -- `debug` ("Gap Day ->"++ show gd) @@ -112,8 +112,8 @@ getGapDaysByBalance l tbl@(rows,defaultVal) = let tbl = ThresholdTable rows pmt = case l of - (RegularLease (LeaseInfo _ _ _ dr) _ _ _) -> dr - (StepUpLease (LeaseInfo _ _ _ dr) _ _ _ _) -> dr + (RegularLease (LeaseInfo _ _ _ dr _) _ _ _) -> dr + (StepUpLease (LeaseInfo _ _ _ dr _) _ _ _ _) -> dr in fromMaybe defaultVal $ lookupTable tbl Down (>= pmt) @@ -130,15 +130,15 @@ projectCfDates dp sd ot -- ^ return a lease contract with opening balance and a payment cashflow on each payment date patchBalance :: Lease -> (Lease,[Amount]) -patchBalance (RegularLease (LeaseInfo sd ot dp dr) bal rt st) +patchBalance (RegularLease (LeaseInfo sd ot dp dr ob) bal rt st) = let cf_dates = lastN (succ rt) $ projectCfDates dp sd ot pmts = [ fromRational (mulBInt dr ds) | ds <- getIntervalDays cf_dates ] new_bal = sum pmts -- `debug` ("cf_date" ++ show cf_dates) in - (RegularLease (LeaseInfo sd ot dp dr) new_bal rt st, pmts) + (RegularLease (LeaseInfo sd ot dp dr ob) new_bal rt st, pmts) -patchBalance (StepUpLease (LeaseInfo sd ot dp dr) lsu bal rt st) +patchBalance (StepUpLease (LeaseInfo sd ot dp dr ob) lsu bal rt st) = let p_dates = projectCfDates dp sd ot cf_dates = lastN (succ rt) $ projectCfDates dp sd ot @@ -168,14 +168,14 @@ patchBalance (StepUpLease (LeaseInfo sd ot dp dr) lsu bal rt st) accrueRentals rate_curve (tail cf_dates) last_pay_date [] -- `debug` ("Using curve->"++show rate_curve++">>"++ show last_pay_date) new_bal = sum pmts -- `debug` ("Patch balance pmts"++ show pmts) in - (StepUpLease (LeaseInfo sd ot dp dr) lsu new_bal rt st,pmts) + (StepUpLease (LeaseInfo sd ot dp dr ob) lsu new_bal rt st,pmts) instance Asset Lease where calcCashflow l@(RegularLease {}) d _ = CF.CashFlowFrame (0,d,Nothing) $ cutBy Inc Future d (zipWith3 CF.LeaseFlow (tail cf_dates) bals pmts) where - (RegularLease (LeaseInfo sd ot dp dr) bal rt st,pmts) = patchBalance l + (RegularLease (LeaseInfo sd ot dp dr ob) bal rt st,pmts) = patchBalance l cf_dates = lastN (succ rt) $ projectCfDates dp sd ot daysBetween = getIntervalDays cf_dates -- `debug` (">>>>>> genSerialDates"++ show cf_dates) bals = tail $ scanl (-) bal pmts -- `debug` ("PMTS for regular"++show pmts) @@ -183,32 +183,32 @@ instance Asset Lease where calcCashflow l@(StepUpLease {}) d _ = CF.CashFlowFrame (0,d,Nothing) $ cutBy Inc Future d (zipWith3 CF.LeaseFlow (tail cf_dates) bals pmts) where - (StepUpLease (LeaseInfo sd ot dp dr) lsu bal rt st,pmts) = patchBalance l -- `debug` ("1") + (StepUpLease (LeaseInfo sd ot dp dr ob) lsu bal rt st,pmts) = patchBalance l -- `debug` ("1") p_dates = projectCfDates dp sd ot -- `debug` ("2") cf_dates = lastN (succ rt) p_dates -- `debug` ("3") -- `debug` ("P dates"++ show p_dates) bals = tail $ scanl (-) bal pmts -- `debug` ("4"++show pmts) -- `debug` ("PMTS->"++ show pmts) - getPaymentDates l@(RegularLease (LeaseInfo sd ot dp _) _ rt _) _ + getPaymentDates l@(RegularLease (LeaseInfo sd ot dp _ _) _ rt _) _ = genSerialDates dp Inc sd ot - getPaymentDates l@(StepUpLease (LeaseInfo sd ot dp _) _ _ rt _) _ + getPaymentDates l@(StepUpLease (LeaseInfo sd ot dp _ _) _ _ rt _) _ = genSerialDates dp Inc sd ot - getOriginDate (StepUpLease (LeaseInfo sd ot dp _) _ _ rt _) = sd - getOriginDate (RegularLease (LeaseInfo sd ot dp _) _ rt _) = sd + getOriginDate (StepUpLease (LeaseInfo sd ot dp _ _) _ _ rt _) = sd + getOriginDate (RegularLease (LeaseInfo sd ot dp _ _) _ rt _) = sd - getRemainTerms (StepUpLease (LeaseInfo sd ot dp _) _ _ rt _) = rt - getRemainTerms (RegularLease (LeaseInfo sd ot dp _) _ rt _) = rt + getRemainTerms (StepUpLease (LeaseInfo sd ot dp _ _) _ _ rt _) = rt + getRemainTerms (RegularLease (LeaseInfo sd ot dp _ _) _ rt _) = rt - updateOriginDate (StepUpLease (LeaseInfo sd ot dp dr) lsu bal rt st) nd - = StepUpLease (LeaseInfo nd ot dp dr) lsu bal rt st - updateOriginDate (RegularLease (LeaseInfo sd ot dp dr) bal rt st) nd - = RegularLease (LeaseInfo nd ot dp dr) bal rt st + updateOriginDate (StepUpLease (LeaseInfo sd ot dp dr ob) lsu bal rt st) nd + = StepUpLease (LeaseInfo nd ot dp dr ob) lsu bal rt st + updateOriginDate (RegularLease (LeaseInfo sd ot dp dr ob) bal rt st) nd + = RegularLease (LeaseInfo nd ot dp dr ob) bal rt st - resetToOrig (StepUpLease (LeaseInfo sd ot dp dr) lsu bal rt st) - = fst . patchBalance $ StepUpLease (LeaseInfo sd ot dp dr) lsu bal ot st - resetToOrig (RegularLease (LeaseInfo sd ot dp dr) bal rt st) - = fst . patchBalance $ RegularLease (LeaseInfo sd ot dp dr) bal ot st + resetToOrig (StepUpLease (LeaseInfo sd ot dp dr ob) lsu bal rt st) + = fst . patchBalance $ StepUpLease (LeaseInfo sd ot dp dr ob) lsu bal ot st + resetToOrig (RegularLease (LeaseInfo sd ot dp dr ob) bal rt st) + = fst . patchBalance $ RegularLease (LeaseInfo sd ot dp dr ob) bal ot st projCashflow l asOfDay ((AP.LeaseAssump gapAssump rentAssump ed exStress),_,_) mRates = (CF.CashFlowFrame (0,asOfDay,Nothing) allTxns, Map.empty) @@ -237,8 +237,8 @@ instance Asset Lease where StepUpLease _ _ bal _ _ -> bal RegularLease _ bal _ _-> bal - getOriginRate (StepUpLease (LeaseInfo _ _ _ dr) _ _ _ _) = fromRational $ toRational dr - getOriginRate (RegularLease (LeaseInfo _ _ _ dr) _ _ _) = fromRational $ toRational dr + getOriginRate (StepUpLease (LeaseInfo _ _ _ dr _) _ _ _ _) = fromRational $ toRational dr + getOriginRate (RegularLease (LeaseInfo _ _ _ dr _) _ _ _) = fromRational $ toRational dr isDefaulted (StepUpLease _ _ _ rt Current) = False isDefaulted (StepUpLease _ _ _ rt _) = True @@ -248,14 +248,14 @@ instance Asset Lease where getOriginBal l = let _sd = case l of - RegularLease (LeaseInfo sd ot dp dr) bal _ _ -> sd - StepUpLease (LeaseInfo sd ot dp dr) _ bal _ _ -> sd + RegularLease (LeaseInfo sd ot dp dr _) bal _ _ -> sd + StepUpLease (LeaseInfo sd ot dp dr _) _ bal _ _ -> sd CF.CashFlowFrame _ txns = calcCashflow l _sd Nothing in CF.mflowBegBalance $ head txns - splitWith (RegularLease (LeaseInfo sd ot dp dr) bal rt st ) rs - = [ RegularLease (LeaseInfo sd ot dp dr) (mulBR bal ratio) rt st | ratio <- rs ] - splitWith (StepUpLease (LeaseInfo sd ot dp dr) stup bal rt st ) rs - = [ StepUpLease (LeaseInfo sd ot dp dr) stup (mulBR bal ratio) rt st | ratio <- rs] + splitWith (RegularLease (LeaseInfo sd ot dp dr ob) bal rt st ) rs + = [ RegularLease (LeaseInfo sd ot dp dr ob) (mulBR bal ratio) rt st | ratio <- rs ] + splitWith (StepUpLease (LeaseInfo sd ot dp dr ob) stup bal rt st ) rs + = [ StepUpLease (LeaseInfo sd ot dp dr ob) stup (mulBR bal ratio) rt st | ratio <- rs] diff --git a/src/AssetClass/Loan.hs b/src/AssetClass/Loan.hs index ddabdb8..bacf27f 100644 --- a/src/AssetClass/Loan.hs +++ b/src/AssetClass/Loan.hs @@ -76,7 +76,7 @@ projectLoanFlow ((originBal,ot,or), startBal, lastPayDate, pt, dc,startRate, beg (zip5 cfDates ppyRates defRates rateVector remainTerms) instance Asset Loan where - calcCashflow pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd ptype) bal rate term _ ) asOfDay mRates + calcCashflow pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd ptype _) bal rate term _ ) asOfDay mRates = fst $ projCashflow pl asOfDay @@ -84,68 +84,46 @@ instance Asset Loan where ,A.DummyDelinqAssump ,A.DummyDefaultAssump) mRates - -- calcCashflow pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd ptype) bal rate term _ ) asOfDay mRates - -- = CF.CashFlowFrame (head bFlow,asOfDay,Nothing) $ cutBy Inc Future asOfDay txns - -- where - -- orate = getOriginRate pl - -- pmt = calcPmt bal (periodRateFromAnnualRate p rate) term - -- cfDates = lastN (term + 1) $ sd:getPaymentDates pl 0 - -- l = pred (length cfDates) - -- ratesUsed = A.projRates rate or mRates cfDates -- `debug` ("rates used"++show (A.projRates rate or mRates cfDates)) - -- dc = getDayCount or - -- (bFlow,prinFlow,intFlow) = case ptype of - -- Level -> calcPiFlow dc bal pmt cfDates ratesUsed - -- Even -> calc_p_i_flow_even (bal / fromIntegral term) bal ratesUsed rate - -- I_P -> calc_p_i_flow_i_p bal cfDates ratesUsed - -- ScheduleRepayment cf _ -> - -- let - -- periodIntervals = getIntervalFactors (sd:getTsDates cf) - -- schedulePrin = fromRational <$> getTsVals cf - -- bals = scanl (-) ob schedulePrin - -- ints = [ mulBIR (mulBR b f) r | (b,f,r) <- zip3 bals periodIntervals ratesUsed ] - -- in - -- (lastN term bals,lastN term schedulePrin,lastN term ints) - -- txns = zipWith10 CF.LoanFlow (tail cfDates) bFlow prinFlow intFlow (replicate l 0.0) (replicate l 0.0) (replicate l 0.0) (replicate l 0.0) (replicate l rate) (replicate l Nothing) -- `debug` ("rates used in calc "++show ratesUsed) - - getCurrentBal pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd ptype ) _bal _rate _term _ ) + + getCurrentBal pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd ptype _) _bal _rate _term _ ) = _bal - getOriginRate pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd ptype ) _bal _rate _term _ ) + getOriginRate pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd ptype _) _bal _rate _term _ ) = case or of Fix _ _r -> _r Floater _ _ _ _r _ _ _ _ -> _r - getCurrentRate pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd ptype ) _bal _rate _term _ ) + getCurrentRate pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd ptype _) _bal _rate _term _ ) = _rate - getOriginBal pl@(PersonalLoan (LoanOriginalInfo ob _ _ _ _ _) _ _ _ _ ) = ob + getOriginBal pl@(PersonalLoan (LoanOriginalInfo ob _ _ _ _ _ _) _ _ _ _ ) = ob isDefaulted pl@(PersonalLoan _ _ _ _ (Defaulted _)) = True isDefaulted PersonalLoan {} = False getOriginInfo (PersonalLoan oi cb cr rt st) = oi - getOriginDate (PersonalLoan (LoanOriginalInfo ob or ot p sd I_P) cb cr rt st ) = sd + getOriginDate (PersonalLoan (LoanOriginalInfo ob or ot p sd I_P _) cb cr rt st ) = sd - resetToOrig m@(PersonalLoan (LoanOriginalInfo ob or ot p sd I_P) cb cr rt st ) - = PersonalLoan (LoanOriginalInfo ob or ot p sd I_P) ob (getOriginRate m) ot st + resetToOrig m@(PersonalLoan (LoanOriginalInfo ob or ot p sd I_P obr) cb cr rt st ) + = PersonalLoan (LoanOriginalInfo ob or ot p sd I_P obr) ob (getOriginRate m) ot st - getRemainTerms (PersonalLoan (LoanOriginalInfo ob or ot p sd I_P) cb cr rt st ) = rt + getRemainTerms (PersonalLoan (LoanOriginalInfo ob or ot p sd I_P _) cb cr rt st ) = rt - updateOriginDate (PersonalLoan (LoanOriginalInfo ob or ot p sd I_P) cb cr rt st ) nd - = PersonalLoan (LoanOriginalInfo ob or ot p nd I_P) cb cr rt st + updateOriginDate (PersonalLoan (LoanOriginalInfo ob or ot p sd I_P obr) cb cr rt st ) nd + = PersonalLoan (LoanOriginalInfo ob or ot p nd I_P obr) cb cr rt st - getPaymentDates pl@(PersonalLoan (LoanOriginalInfo ob _ ot p sd (ScheduleRepayment ts mDp) ) _bal _rate _term _ ) extra + getPaymentDates pl@(PersonalLoan (LoanOriginalInfo ob _ ot p sd (ScheduleRepayment ts mDp) _) _bal _rate _term _ ) extra = let pdays = getTsDates ts extraDates = genSerialDates (fromMaybe MonthEnd mDp) Inc (last pdays) extra in pdays ++ extraDates - getPaymentDates pl@(PersonalLoan (LoanOriginalInfo ob _ ot p sd _ ) _bal _rate _term _ ) extra + getPaymentDates pl@(PersonalLoan (LoanOriginalInfo ob _ ot p sd _ _) _bal _rate _term _ ) extra = genDates sd p (ot+extra) -- ^ Project cashflow for loans with prepayment/default/loss and interest rate assumptions - projCashflow pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd prinPayType) cb cr rt Current) + projCashflow pl@(PersonalLoan (LoanOriginalInfo ob or ot p sd prinPayType _) cb cr rt Current) asOfDay (A.LoanAssump defaultAssump prepayAssump recoveryAssump ams,_,_) mRate @@ -169,7 +147,7 @@ instance Asset Loan where (futureTxns,historyM) = CF.cutoffTrs asOfDay (patchLossRecovery txns recoveryAssump) -- ^ Project cashflow for defautled loans - projCashflow m@(PersonalLoan (LoanOriginalInfo ob or ot p sd prinPayType) cb cr rt (Defaulted (Just defaultedDate))) + projCashflow m@(PersonalLoan (LoanOriginalInfo ob or ot p sd prinPayType _) cb cr rt (Defaulted (Just defaultedDate))) asOfDay (_,_,A.DefaultedRecovery rr lag timing) _ @@ -183,10 +161,10 @@ instance Asset Loan where in (CF.CashFlowFrame (cb,asOfDay,Nothing) futureTxns, historyM) - projCashflow m@(PersonalLoan (LoanOriginalInfo ob or ot p sd prinPayType) cb cr rt (Defaulted Nothing)) asOfDay assumps _ + projCashflow m@(PersonalLoan (LoanOriginalInfo ob or ot p sd prinPayType _) cb cr rt (Defaulted Nothing)) asOfDay assumps _ = (CF.CashFlowFrame (cb,asOfDay,Nothing) [CF.LoanFlow asOfDay 0 0 0 0 0 0 0 cr Nothing],Map.empty) projCashflow a b c d = error $ "failed to match projCashflow"++show a++show b++show c++show d - splitWith l@(PersonalLoan (LoanOriginalInfo ob or ot p sd prinPayType) cb cr rt st) rs - = [ PersonalLoan (LoanOriginalInfo (mulBR ob ratio) or ot p sd prinPayType) (mulBR cb ratio) cr rt st | ratio <- rs ] + splitWith l@(PersonalLoan (LoanOriginalInfo ob or ot p sd prinPayType obr) cb cr rt st) rs + = [ PersonalLoan (LoanOriginalInfo (mulBR ob ratio) or ot p sd prinPayType obr) (mulBR cb ratio) cr rt st | ratio <- rs ] diff --git a/src/AssetClass/Mortgage.hs b/src/AssetClass/Mortgage.hs index a6c60ba..2b9eadb 100644 --- a/src/AssetClass/Mortgage.hs +++ b/src/AssetClass/Mortgage.hs @@ -335,7 +335,7 @@ buildARMrates or@(IR.Floater _ idx sprd initRate dp _ _ mRoundBy ) Nothing -> error $ "Failed to find index"++ show idx instance Ast.Asset Mortgage where - calcCashflow m@(Mortgage (MortgageOriginalInfo ob or ot p sd ptype _) _bal _rate _term _mbn Current) d mRates + calcCashflow m@(Mortgage (MortgageOriginalInfo ob or ot p sd ptype _ _) _bal _rate _term _mbn Current) d mRates = fst (projCashflow m d (MortgageAssump Nothing Nothing Nothing Nothing,A.DummyDelinqAssump,A.DummyDefaultAssump) mRates) @@ -345,12 +345,12 @@ instance Ast.Asset Mortgage where getCurrentBal (Mortgage _ _bal _ _ _ _) = _bal getCurrentBal (AdjustRateMortgage _ _ _bal _ _ _ _) = _bal - getOriginBal (Mortgage (MortgageOriginalInfo _bal _ _ _ _ _ _) _ _ _ _ _ ) = _bal - getOriginBal (AdjustRateMortgage (MortgageOriginalInfo _bal _ _ _ _ _ _) _ _ _ _ _ _ ) = _bal + getOriginBal (Mortgage (MortgageOriginalInfo _bal _ _ _ _ _ _ _) _ _ _ _ _ ) = _bal + getOriginBal (AdjustRateMortgage (MortgageOriginalInfo _bal _ _ _ _ _ _ _) _ _ _ _ _ _ ) = _bal getOriginRate m = let - (MortgageOriginalInfo _ or _ _ _ _ _) = getOriginInfo m + (MortgageOriginalInfo _ or _ _ _ _ _ _) = getOriginInfo m in case or of IR.Fix _ _r -> _r @@ -360,15 +360,15 @@ instance Ast.Asset Mortgage where getCurrentRate (AdjustRateMortgage _ _ _ r _ _ _) = r getCurrentRate (ScheduleMortgageFlow _ flows _) = 0.0 - resetToOrig m@(Mortgage (MortgageOriginalInfo ob or ot p sd pt pp) cb cr rt mBn st) - = Mortgage (MortgageOriginalInfo ob or ot p sd pt pp) + resetToOrig m@(Mortgage (MortgageOriginalInfo ob or ot p sd pt pp obr) cb cr rt mBn st) + = Mortgage (MortgageOriginalInfo ob or ot p sd pt pp obr) ob (getOriginRate m) ot mBn st --TODO borrowerNum is not being updated - resetToOrig m@(AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd pt pp) arm cb cr rt mBn st) - = AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd pt pp) + resetToOrig m@(AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd pt pp obr) arm cb cr rt mBn st) + = AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd pt pp obr) arm ob (getOriginRate m) @@ -377,8 +377,8 @@ instance Ast.Asset Mortgage where st --TODO borrowerNum is not being updated resetToOrig m@(ScheduleMortgageFlow begDate flows dp) = m - getPaymentDates (Mortgage (MortgageOriginalInfo _ _ ot p sd _ _) _ _ _ _ _) extra = genDates sd p (ot+extra) - getPaymentDates (AdjustRateMortgage (MortgageOriginalInfo _ _ ot p sd _ _) _ _ _ _ _ _) extra = genDates sd p (ot+extra) + getPaymentDates (Mortgage (MortgageOriginalInfo _ _ ot p sd _ _ _) _ _ _ _ _) extra = genDates sd p (ot+extra) + getPaymentDates (AdjustRateMortgage (MortgageOriginalInfo _ _ ot p sd _ _ _) _ _ _ _ _ _) extra = genDates sd p (ot+extra) getPaymentDates (ScheduleMortgageFlow begDate flows dp) extra = let @@ -392,23 +392,23 @@ instance Ast.Asset Mortgage where isDefaulted Mortgage {} = False isDefaulted AdjustRateMortgage {} = False - getOriginDate (Mortgage (MortgageOriginalInfo _ _ ot p sd _ _) _ _ ct _ _) = sd - getOriginDate (AdjustRateMortgage (MortgageOriginalInfo _ _ ot p sd _ _) _ _ _ ct _ _) = sd + getOriginDate (Mortgage (MortgageOriginalInfo _ _ ot p sd _ _ _) _ _ ct _ _) = sd + getOriginDate (AdjustRateMortgage (MortgageOriginalInfo _ _ ot p sd _ _ _) _ _ _ ct _ _) = sd getOriginDate (ScheduleMortgageFlow begDate _ _) = begDate - getRemainTerms (Mortgage (MortgageOriginalInfo _ _ ot p sd _ _) _ _ ct _ _) = ct - getRemainTerms (AdjustRateMortgage (MortgageOriginalInfo _ _ ot p sd _ _) _ _ _ ct _ _) = ct + getRemainTerms (Mortgage (MortgageOriginalInfo _ _ ot p sd _ _ _) _ _ ct _ _) = ct + getRemainTerms (AdjustRateMortgage (MortgageOriginalInfo _ _ ot p sd _ _ _) _ _ _ ct _ _) = ct getOriginInfo (Mortgage oi _ _ _ _ _) = oi getOriginInfo (AdjustRateMortgage oi _ _ _ _ _ _) = oi - updateOriginDate (Mortgage (MortgageOriginalInfo ob or ot p sd _type mpn) cb cr ct mbn st) nd - = Mortgage (MortgageOriginalInfo ob or ot p nd _type mpn) cb cr ct mbn st - updateOriginDate (AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd _type mpn) arm cb cr ct mbn st) nd - = AdjustRateMortgage (MortgageOriginalInfo ob or ot p nd _type mpn) arm cb cr ct mbn st + updateOriginDate (Mortgage (MortgageOriginalInfo ob or ot p sd _type mpn obr) cb cr ct mbn st) nd + = Mortgage (MortgageOriginalInfo ob or ot p nd _type mpn obr) cb cr ct mbn st + updateOriginDate (AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd _type mpn obr) arm cb cr ct mbn st) nd + = AdjustRateMortgage (MortgageOriginalInfo ob or ot p nd _type mpn obr) arm cb cr ct mbn st -- project current mortgage with total default amt - projCashflow m@(Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn) cb cr rt mbn Current) + projCashflow m@(Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn _) cb cr rt mbn Current) asOfDay mars@(A.MortgageAssump (Just (A.DefaultByAmt (dBal,vs))) amp amr ams ,_ ,_) mRates = @@ -426,7 +426,7 @@ instance Ast.Asset Mortgage where (futureTxns,historyM)= CF.cutoffTrs asOfDay (patchLossRecovery txns amr) -- project current adjMortgage with total default amt - projCashflow m@(AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn) arm cb cr rt mbn Current) + projCashflow m@(AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn _) arm cb cr rt mbn Current) asOfDay mars@(A.MortgageAssump (Just (A.DefaultByAmt (dBal,vs))) amp amr ams,_,_) mRates = @@ -475,7 +475,7 @@ instance Ast.Asset Mortgage where -- project current mortgage(without delinq) - projCashflow m@(Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn) cb cr rt mbn Current) + projCashflow m@(Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn _) cb cr rt mbn Current) asOfDay mars@(A.MortgageAssump amd amp amr ams ,_ ,_) mRates = @@ -505,7 +505,7 @@ instance Ast.Asset Mortgage where (futureTxns,historyM)= CF.cutoffTrs asOfDay (patchLossRecovery (txns++extraTxns) amr) -- project current mortgage(with delinq) - projCashflow m@(Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn) cb cr rt mbn Current) + projCashflow m@(Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn _) cb cr rt mbn Current) asOfDay mars@(A.MortgageDeqAssump amd amp amr ams ,_ @@ -526,7 +526,7 @@ instance Ast.Asset Mortgage where (futureTxns,historyM)= CF.cutoffTrs asOfDay txns -- project defaulted Mortgage - projCashflow m@(Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn) cb cr rt mbn (Defaulted (Just defaultedDate)) ) + projCashflow m@(Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn _) cb cr rt mbn (Defaulted (Just defaultedDate)) ) asOfDay (_,_,A.DefaultedRecovery rr lag timing) _ = let @@ -548,7 +548,7 @@ instance Ast.Asset Mortgage where = (CF.CashFlowFrame (cb,asOfDay,Nothing) [ CF.MortgageFlow asOfDay 0 0 0 0 0 0 0 cr mbn Nothing Nothing] ,Map.empty) -- project current AdjMortgage - projCashflow m@(AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn) arm cb cr rt mbn Current) + projCashflow m@(AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn _) arm cb cr rt mbn Current) asOfDay mars@(A.MortgageAssump amd amp amr ams,_,_) mRates = @@ -573,7 +573,7 @@ instance Ast.Asset Mortgage where (futureTxns,historyM)= CF.cutoffTrs asOfDay (patchLossRecovery txns amr) -- project current AdjMortgage with delinq - projCashflow m@(AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn) arm cb cr rt mbn Current) + projCashflow m@(AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn _) arm cb cr rt mbn Current) asOfDay mars@(A.MortgageAssump amd amp amr ams,_,_) mRates = @@ -635,15 +635,15 @@ instance Ast.Asset Mortgage where projCashflow a b c d = error $ "Failed to match when proj mortgage>>" ++ show a ++ show b ++ show c ++ show d - getBorrowerNum m@(Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType _) cb cr rt mbn _ ) = fromMaybe 1 mbn - getBorrowerNum m@(AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd prinPayType _) _ cb cr rt mbn _ ) = fromMaybe 1 mbn + getBorrowerNum m@(Mortgage _ cb cr rt mbn _ ) = fromMaybe 1 mbn + getBorrowerNum m@(AdjustRateMortgage _ _ cb cr rt mbn _ ) = fromMaybe 1 mbn - splitWith (Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn) cb cr rt mbn st ) rs - = [ Mortgage (MortgageOriginalInfo (mulBR ob ratio) or ot p sd prinPayType mpn) (mulBR cb ratio) cr rt mbn st + splitWith (Mortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn obr) cb cr rt mbn st ) rs + = [ Mortgage (MortgageOriginalInfo (mulBR ob ratio) or ot p sd prinPayType mpn obr) (mulBR cb ratio) cr rt mbn st | ratio <- rs ] - splitWith (AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn) arm cb cr rt mbn st ) rs - = [ AdjustRateMortgage (MortgageOriginalInfo (mulBR ob ratio) or ot p sd prinPayType mpn) arm (mulBR cb ratio) cr rt mbn st + splitWith (AdjustRateMortgage (MortgageOriginalInfo ob or ot p sd prinPayType mpn obr) arm cb cr rt mbn st ) rs + = [ AdjustRateMortgage (MortgageOriginalInfo (mulBR ob ratio) or ot p sd prinPayType mpn obr) arm (mulBR cb ratio) cr rt mbn st | ratio <- rs ] diff --git a/src/AssetClass/Receivable.hs b/src/AssetClass/Receivable.hs index 69887b7..2a1e52a 100644 --- a/src/AssetClass/Receivable.hs +++ b/src/AssetClass/Receivable.hs @@ -50,7 +50,7 @@ buildRecoveryCfs sd defaultedBal (Just (A.RecoveryByDays r dists)) calcDueFactorFee :: Receivable -> Date -> Balance -calcDueFactorFee r@(Invoice (ReceivableInfo sd ob oa dd ft) st) asOfDay +calcDueFactorFee r@(Invoice (ReceivableInfo sd ob oa dd ft obr) st) asOfDay = case ft of Nothing -> 0 Just (FixedFee b) -> b @@ -65,16 +65,16 @@ calcDueFactorFee r@(Invoice (ReceivableInfo sd ob oa dd ft) st) asOfDay Just (AdvanceFee r) -> mulBR oa (r * (yearCountFraction DC_ACT_365F sd dd)) Just (CompoundFee fs) -> let - newReceivables = [ Invoice (ReceivableInfo sd ob oa dd (Just newFeeType)) st | newFeeType <- fs] + newReceivables = [ Invoice (ReceivableInfo sd ob oa dd (Just newFeeType) obr) st | newFeeType <- fs] in sum $ (`calcDueFactorFee` asOfDay) <$> newReceivables instance Asset Receivable where - getPaymentDates r@(Invoice (ReceivableInfo sd ob oa dd ft) st) _ = [dd] + getPaymentDates r@(Invoice (ReceivableInfo sd ob oa dd ft _) st) _ = [dd] - calcCashflow r@(Invoice (ReceivableInfo sd ob oa dd ft) st) asOfDay _ + calcCashflow r@(Invoice (ReceivableInfo sd ob oa dd ft _) st) asOfDay _ = CF.CashFlowFrame (ob,asOfDay,Nothing) $ cutBy Inc Future asOfDay txns where payDate = dd @@ -86,31 +86,31 @@ instance Asset Receivable where txns = [initTxn,CF.ReceivableFlow payDate 0 0 principal feePaid 0 0 0 Nothing] - getCurrentBal r@(Invoice (ReceivableInfo sd ob oa dd ft) st) = ob + getCurrentBal r@(Invoice (ReceivableInfo sd ob oa dd ft _) st) = ob - isDefaulted r@(Invoice (ReceivableInfo sd ob oa dd ft) Current) = False - isDefaulted r@(Invoice (ReceivableInfo sd ob oa dd ft) _) = True + isDefaulted r@(Invoice (ReceivableInfo sd ob oa dd ft _) Current) = False + isDefaulted r@(Invoice (ReceivableInfo sd ob oa dd ft _) _) = True - getOriginDate r@(Invoice (ReceivableInfo sd ob oa dd ft) st) = sd + getOriginDate r@(Invoice (ReceivableInfo sd ob oa dd ft _) st) = sd - resetToOrig r@(Invoice (ReceivableInfo sd ob oa dd ft) st) = r + resetToOrig r@(Invoice (ReceivableInfo sd ob oa dd ft _) st) = r - getRemainTerms r@(Invoice (ReceivableInfo sd ob oa dd ft) st) = 1 + getRemainTerms r@(Invoice (ReceivableInfo sd ob oa dd ft _) st) = 1 getOriginRate _ = 0 getCurrentRate _ = 0 - updateOriginDate r@(Invoice (ReceivableInfo sd ob oa dd ft) st) newDate + updateOriginDate r@(Invoice (ReceivableInfo sd ob oa dd ft obr) st) newDate = let gaps = daysBetween sd dd in - Invoice (ReceivableInfo newDate ob oa (T.addDays gaps newDate) ft) st + Invoice (ReceivableInfo newDate ob oa (T.addDays gaps newDate) ft obr) st - splitWith r@(Invoice (ReceivableInfo sd ob oa dd ft) st) rs - = [ (Invoice (ReceivableInfo sd (mulBR ob ratio) (mulBR oa ratio) dd ft) st) | ratio <- rs ] + splitWith r@(Invoice (ReceivableInfo sd ob oa dd ft obr) st) rs + = [ (Invoice (ReceivableInfo sd (mulBR ob ratio) (mulBR oa ratio) dd ft obr) st) | ratio <- rs ] -- Defaulted Invoice - projCashflow r@(Invoice (ReceivableInfo sd ob oa dd ft) (Defaulted _)) + projCashflow r@(Invoice (ReceivableInfo sd ob oa dd ft _) (Defaulted _)) asOfDay massump@(A.ReceivableAssump _ amr ams, _ , _) mRates @@ -123,7 +123,7 @@ instance Asset Receivable where -- Performing Invoice - projCashflow r@(Invoice (ReceivableInfo sd ob oa dd ft) Current) + projCashflow r@(Invoice (ReceivableInfo sd ob oa dd ft _) Current) asOfDay massump@(A.ReceivableAssump (Just A.DefaultAtEnd) amr ams, _ , _) mRates @@ -139,7 +139,7 @@ instance Asset Receivable where txns = [CF.ReceivableFlow payDate 0 0 0 0 ob 0 realizedLoss Nothing] (futureTxns,historyM)= CF.cutoffTrs asOfDay $ txns++(buildRecoveryCfs payDate ob amr) - projCashflow r@(Invoice (ReceivableInfo sd ob oa dd ft) Current) + projCashflow r@(Invoice (ReceivableInfo sd ob oa dd ft _) Current) asOfDay massump@(A.ReceivableAssump amd amr ams, _ , _) mRates diff --git a/src/Assumptions.hs b/src/Assumptions.hs index e1ff3c2..8417f81 100644 --- a/src/Assumptions.hs +++ b/src/Assumptions.hs @@ -61,7 +61,7 @@ data ApplyAssumptionType = PoolLevel AssetPerf | ByName (Map.Map PoolId AssetPerf) -- ^ assumption for a named pool | ByPoolId (Map.Map PoolId ApplyAssumptionType) - -- ^ assumption for a named pool + -- ^ assumption for a pool | ByDealName (Map.Map DealName (ApplyAssumptionType, NonPerfAssumption)) -- ^ assumption for a named deal deriving (Show, Generic) diff --git a/test/UT/AnalyticsTest.hs b/test/UT/AnalyticsTest.hs index 4ab2937..375985b 100644 --- a/test/UT/AnalyticsTest.hs +++ b/test/UT/AnalyticsTest.hs @@ -65,7 +65,7 @@ assetPricingTest = testCase "Loan Pricing(Inc Int)" $ assertEqual "Loan Pricing" (AssetPrice 1037.38 0.76 0.7 (-1.0) 0.21) - (priceAsset (PersonalLoan (LoanOriginalInfo 1200 (Fix DC_30_360_US 0.08) 12 Monthly (L.toDate "20240701") I_P) 1000 0.08 10 Current) + (priceAsset (PersonalLoan (LoanOriginalInfo 1200 (Fix DC_30_360_US 0.08) 12 Monthly (L.toDate "20240701") I_P Nothing) 1000 0.08 10 Current) (L.toDate "20241002") (PvRate 0.03) (LoanAssump Nothing Nothing Nothing Nothing,DummyDelinqAssump,DummyDefaultAssump) @@ -74,7 +74,7 @@ assetPricingTest = ,testCase "Loan Pricing(Exc Int)" $ assertEqual "Loan Pricing" (AssetPrice 1037.17 0.76 0.7 (-1.0) 0.21) - (priceAsset (PersonalLoan (LoanOriginalInfo 1200 (Fix DC_30_360_US 0.08) 12 Monthly (L.toDate "20240701") I_P) 1000 0.08 10 Current) + (priceAsset (PersonalLoan (LoanOriginalInfo 1200 (Fix DC_30_360_US 0.08) 12 Monthly (L.toDate "20240701") I_P Nothing) 1000 0.08 10 Current) (L.toDate "20241002") (PvRate 0.03) (LoanAssump Nothing Nothing Nothing Nothing,DummyDelinqAssump,DummyDefaultAssump) diff --git a/test/UT/AssetTest.hs b/test/UT/AssetTest.hs index 0dd1f3b..b6adf0e 100644 --- a/test/UT/AssetTest.hs +++ b/test/UT/AssetTest.hs @@ -30,44 +30,44 @@ debug = flip trace dummySt = (0,L.toDate "19000101",Nothing) tm = AB.Mortgage - (AB.MortgageOriginalInfo 10000 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") AB.Level Nothing) + (AB.MortgageOriginalInfo 10000 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") AB.Level Nothing Nothing) 8000 0.08 19 Nothing AB.Current tm1 = AB.Mortgage - (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") AB.Even Nothing) + (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") AB.Even Nothing Nothing) 240 0.08 19 Nothing AB.Current tm2 = AB.Mortgage - (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") AB.Even Nothing) + (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") AB.Even Nothing Nothing) 240 0.08 19 Nothing (AB.Defaulted Nothing) tm4 = AB.Mortgage - (AB.MortgageOriginalInfo 240 (Fix DC_30_360_US 0.08) 36 L.Monthly (L.toDate "20210701") (AB.Balloon 120) Nothing) + (AB.MortgageOriginalInfo 240 (Fix DC_30_360_US 0.08) 36 L.Monthly (L.toDate "20210701") (AB.Balloon 120) Nothing Nothing) 120 0.08 36 Nothing AB.Current tm5 = AB.Mortgage - (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 36 L.Monthly (L.toDate "20210101") (AB.Balloon 120) Nothing) + (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 36 L.Monthly (L.toDate "20210101") (AB.Balloon 120) Nothing Nothing) 100 0.08 24 Nothing AB.Current tm6 = AB.Mortgage - (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 36 L.Monthly (L.toDate "20210101") (AB.Balloon 120) Nothing) + (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 36 L.Monthly (L.toDate "20210101") (AB.Balloon 120) Nothing Nothing) 120 0.08 36 Nothing AB.Current tm7 = AB.Mortgage - (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 36 L.Monthly (L.toDate "20210101") (AB.Balloon 120) Nothing) + (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 36 L.Monthly (L.toDate "20210101") (AB.Balloon 120) Nothing Nothing) 120 0.08 24 Nothing AB.Current @@ -194,7 +194,7 @@ mortgageTests = testGroup "Mortgage cashflow Tests" loanTests = let loan1 = AB.PersonalLoan - (AB.LoanOriginalInfo 180 (Fix DC_ACT_365F 0.08) 36 L.Monthly (L.toDate "20200101") AB.I_P) + (AB.LoanOriginalInfo 180 (Fix DC_ACT_365F 0.08) 36 L.Monthly (L.toDate "20200101") AB.I_P Nothing) 120 0.08 24 @@ -245,7 +245,7 @@ leaseFunTests = leaseTests = let lease1 = AB.RegularLease - (AB.LeaseInfo (L.toDate "20230101") 12 MonthEnd 1) + (AB.LeaseInfo (L.toDate "20230101") 12 MonthEnd 1 Nothing) 100 12 AB.Current @@ -253,7 +253,7 @@ leaseTests = cf1 = Ast.calcCashflow lease1 asofDate Nothing lease2 = AB.StepUpLease - (AB.LeaseInfo (L.toDate "20230601") 12 MonthEnd 1) + (AB.LeaseInfo (L.toDate "20230601") 12 MonthEnd 1 Nothing) (AB.FlatRate MonthEnd 0.02) 100 12 @@ -261,7 +261,7 @@ leaseTests = cf2 = Ast.calcCashflow lease2 asofDate Nothing lease3 = AB.StepUpLease - (AB.LeaseInfo (L.toDate "20230401") 4 MonthEnd 1) + (AB.LeaseInfo (L.toDate "20230401") 4 MonthEnd 1 Nothing) (AB.ByRateCurve MonthEnd [0.02,0.04,0.05,0.06]) 100 4 @@ -333,7 +333,7 @@ leaseTests = installmentTest = let loan1 = AB.Installment - (AB.LoanOriginalInfo 1000 (Fix DC_ACT_365F 0.01) 12 L.Monthly (L.toDate "20220101") AB.F_P) + (AB.LoanOriginalInfo 1000 (Fix DC_ACT_365F 0.01) 12 L.Monthly (L.toDate "20220101") AB.F_P Nothing) 1000 12 AB.Current @@ -341,7 +341,7 @@ installmentTest = loan1Cf = Ast.calcCashflow loan1 asofDate1 Nothing loan2 = AB.Installment - (AB.LoanOriginalInfo 1000 (Fix DC_ACT_365F 0.01) 12 L.Monthly (L.toDate "20220101") AB.F_P) + (AB.LoanOriginalInfo 1000 (Fix DC_ACT_365F 0.01) 12 L.Monthly (L.toDate "20220101") AB.F_P Nothing) 500 12 AB.Current @@ -349,21 +349,21 @@ installmentTest = asofDate2 = L.toDate "20220815" loan3 = AB.Installment - (AB.LoanOriginalInfo 1000 (Fix DC_ACT_365F 0.01) 12 L.Monthly (L.toDate "20220101") AB.F_P) + (AB.LoanOriginalInfo 1000 (Fix DC_ACT_365F 0.01) 12 L.Monthly (L.toDate "20220101") AB.F_P Nothing) 416.69 5 AB.Current loan3Cf = Ast.calcCashflow loan3 asofDate2 Nothing loan4 = AB.Installment - (AB.LoanOriginalInfo 1000 (Fix DC_ACT_365F 0.01) 12 L.Monthly (L.toDate "20220101") AB.F_P) + (AB.LoanOriginalInfo 1000 (Fix DC_ACT_365F 0.01) 12 L.Monthly (L.toDate "20220101") AB.F_P Nothing) 208.35 5 AB.Current loan4Cf = Ast.calcCashflow loan4 asofDate2 Nothing loan5 = AB.Installment - (AB.LoanOriginalInfo 1200 (Fix DC_ACT_365F 0.01) 12 L.Monthly (L.toDate "20220101") (AB.PO_FirstN 4)) + (AB.LoanOriginalInfo 1200 (Fix DC_ACT_365F 0.01) 12 L.Monthly (L.toDate "20220101") (AB.PO_FirstN 4) Nothing) 1000 10 AB.Current @@ -415,6 +415,7 @@ armTest = Monthly (L.toDate "20230501") AB.Level + Nothing Nothing) (ARM 12 (Just 0.015) (Just 0.01) (Just 0.09) (Just 0.02) ) 240 0.08 19 @@ -484,7 +485,7 @@ ppy_3_1 = Just $ AB.FixPct 0.01 (Just 2) ppy_4 = Just $ AB.Sliding 0.1 0.01 ppy_5 = Just $ AB.StepDown [(2,0.5),(12,0.2)] -origin_info = AB.MortgageOriginalInfo 10000 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") AB.Level Nothing +origin_info = AB.MortgageOriginalInfo 10000 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") AB.Level Nothing Nothing tm_ppy_1 = AB.Mortgage (origin_info { AB.prepaymentPenalty = ppy_1}) 10000 0.08 24 Nothing AB.Current tm_ppy_2 = AB.Mortgage (origin_info { AB.prepaymentPenalty = ppy_2}) 10000 0.08 24 Nothing AB.Current @@ -623,7 +624,7 @@ delinqScheduleCFTest = delinqMortgageTest = let tm1 = AB.Mortgage - (AB.MortgageOriginalInfo 12 (Fix DC_ACT_365F 0.08) 12 L.Monthly (L.toDate "20210101") AB.Level Nothing) + (AB.MortgageOriginalInfo 12 (Fix DC_ACT_365F 0.08) 12 L.Monthly (L.toDate "20210101") AB.Level Nothing Nothing) 240 0.08 3 Nothing AB.Current @@ -671,7 +672,7 @@ delinqMortgageTest = btlMortgageTest = let btl = AB.Mortgage - (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") AB.I_P Nothing) + (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") AB.I_P Nothing Nothing) 240 0.08 2 Nothing AB.Current @@ -702,7 +703,7 @@ btlMortgageTest = nonPayMortgageTest = let m = AB.Mortgage - (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") (AB.NO_FirstN 3 AB.Level) Nothing) + (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") (AB.NO_FirstN 3 AB.Level) Nothing Nothing) 240 0.08 24 Nothing AB.Current @@ -714,7 +715,7 @@ nonPayMortgageTest = ,A.DummyDelinqAssump,A.DummyDefaultAssump) (CF.CashFlowFrame _ txns,_) = Ast.projCashflow m (L.toDate "20200101") assump1 Nothing m1 = AB.Mortgage - (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") (AB.IO_FirstN 3 AB.Level) Nothing) + (AB.MortgageOriginalInfo 240 (Fix DC_ACT_365F 0.08) 24 L.Monthly (L.toDate "20210101") (AB.IO_FirstN 3 AB.Level) Nothing Nothing) 240 0.08 24 Nothing AB.Current @@ -751,9 +752,9 @@ nonPayMortgageTest = receivableTest = let - invoice1 = AB.Invoice (AB.ReceivableInfo (L.toDate "20240401") 1500 1000 (L.toDate "20240601") Nothing) AB.Current - invoice2 = AB.Invoice (AB.ReceivableInfo (L.toDate "20240401") 1500 1000 (L.toDate "20240601") (Just (AB.FixedFee 50))) AB.Current - invoice0 = AB.Invoice (AB.ReceivableInfo (L.toDate "20240401") 1500 1000 (L.toDate "20240601") Nothing) (AB.Defaulted Nothing) + invoice1 = AB.Invoice (AB.ReceivableInfo (L.toDate "20240401") 1500 1000 (L.toDate "20240601") Nothing Nothing) AB.Current + invoice2 = AB.Invoice (AB.ReceivableInfo (L.toDate "20240401") 1500 1000 (L.toDate "20240601") (Just (AB.FixedFee 50)) Nothing ) AB.Current + invoice0 = AB.Invoice (AB.ReceivableInfo (L.toDate "20240401") 1500 1000 (L.toDate "20240601") Nothing Nothing) (AB.Defaulted Nothing) invoiceAssump = (A.ReceivableAssump Nothing Nothing