@@ -539,6 +539,60 @@ def test_revolving_01(setup_api):
539539def test_06 (setup_api ):
540540 r = setup_api .run (test06 , read = True , runAssump = [])
541541 assert r ['pool' ]['flow' ]['PoolConsol' ].Principal .sum () == 2175 , "Total principal should be 2175.0"
542+
543+
544+ @pytest .mark .waterfall
545+ def test_limit_01 (setup_api ):
546+ formulaPay = \
547+ ["IfElse" ,["date" ,"<=" ,"2021-10-20" ]
548+ ,[['payPrin' , 'acc01' , ['A1' ],{"limit" :{"formula" :("const" ,30 )}}]]
549+ ,[['payPrin' , 'acc01' , ['A1' ]]]
550+ ]
551+
552+ test01_ = test01 & lens .waterfall ['default' ][1 ].set (formulaPay )
553+ r = setup_api .run (test01_ ,read = True )
554+ assert r ['bonds' ]['A1' ][:"2021-10-20" ].principal .to_list () == [30.0 , 30.0 , 30.0 , 30.0 ]
555+ assert r ['bonds' ]['A1' ].loc ["2021-11-20" ].principal .item () == 75.92
556+
557+ formulaPay = \
558+ ["IfElse" ,["date" ,"<=" ,"2021-10-20" ]
559+ ,[['payPrin' , 'acc01' , ['A1' ],{"limit" :{"balPct" :0.4 }}]]
560+ ,[['payPrin' , 'acc01' , ['A1' ]]]
561+ ]
562+
563+ test01_ = test01 & lens .waterfall ['default' ][1 ].set (formulaPay )
564+ r = setup_api .run (test01_ ,read = True )
565+ assert r ['bonds' ]['A1' ][:"2021-11-20" ].principal .to_list () == [122.01 , 30.78 , 30.44 , 30.58 , 76.48 ]
566+
567+ formulaPay = ['payPrin' , 'acc01' , ['A1' ],{"limit" :{"balCapAmt" :75 }}]
568+
569+ test01_ = test01 & lens .waterfall ['default' ][1 ].set (formulaPay )
570+ r = setup_api .run (test01_ ,read = True )
571+ r ['bonds' ]['A1' ].principal .to_list () == [75 ]* 13 + [25 ]
572+
573+ @pytest .mark .waterfall
574+ def test_support_account (setup_api ):
575+ """ Test support account """
576+ test01_ = test01 & lens .accounts .set ((('acc01' , {'balance' : 0 }),('acc02' , {'balance' : 200 })))\
577+ & lens .waterfall ['default' ][0 ].modify (lambda x : x + [{"support" :["account" ,"acc02" ]}])
578+ r = setup_api .run (test01_ ,read = True
579+ ,poolAssump = ("Pool" ,("Mortgage" ,{"CDR" :0.75 },None ,None ,None )
580+ ,None
581+ ,None ))
582+ assert r ['accounts' ]['acc01' ].loc ['2023-09-20' ].change .item () == - 2.56
583+ assert r ['accounts' ]['acc02' ].loc ['2023-09-20' ].change .item () == - 0.13
584+
585+ test01_ = test01 & lens .accounts .set ((('acc01' , {'balance' : 0 }),('acc02' , {'balance' : 10 }),('acc03' , {'balance' : 50 })))\
586+ & lens .waterfall ['default' ][0 ].modify (lambda x : x + [{"support" :["support" ,("account" ,"acc02" ),("account" ,"acc03" )]}])
587+ r = setup_api .run (test01_ ,read = True
588+ ,poolAssump = ("Pool" ,("Mortgage" ,{"CDR" :0.75 },None ,None ,None )
589+ ,None
590+ ,None )
591+ )
592+ assert r ['accounts' ]['acc01' ].loc ['2023-09-20' ].change .item () == - 2.56
593+ assert r ['accounts' ]['acc02' ].loc ['2023-09-20' ].change .item () == - 0.13
594+ assert r ['accounts' ]['acc02' ].loc ['2024-01-20' ].change .item () == - 1.96
595+ assert r ['accounts' ]['acc03' ].loc ['2024-01-20' ].change .item () == - 0.73
542596# @pytest.mark.analytics
543597# def test_rootfinder_by_formula(setup_api):
544598# poolPerf = ("Pool",("Mortgage",{"CDR":0.002},{"CPR":0.001},{"Rate":0.1,"Lag":18},None)
0 commit comments