### Basic Generic Deal Setup Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Initializes a Generic deal object with detailed parameters for assets, accounts, bonds, fees, and payment/collection logic. This serves as a foundational example for setting up complex financial deals. ```python from absbox import Generic test01 = Generic( "TEST01" ,{"cutoff":"2021-03-01","closing":"2021-06-15","firstPay":"2021-07-26" ,"payFreq":["DayOfMonth",20],"poolFreq":"MonthEnd","stated":"2030-01-01"} ,{'assets':[["Mortgage" ,{"originBalance":2200,"originRate":["fix",0.045],"originTerm":30 ,"freq":"Monthly","type":"Level","originDate":"2021-02-01"} ,{"currentBalance":2200 ,"currentRate":0.08 ,"remainTerm":20 ,"status":"current"}]]} ,(("acc01",{"balance":0}),) ,(("A1",{"balance":1000 ,"rate":0.07 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.08} ,"bondType":{"Sequential":None}}) ,("B",{"balance":1000 ,"rate":0.0 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.00} ,"bondType":{"Equity":None} })) ,(("trusteeFee",{"type":{"fixFee":30},"feeStart":"2021-06-15"}),) ,{"amortizing":[ ["payFee","acc01",['trusteeFee']] ,["accrueAndPayInt","acc01",["A1"]] ,["payPrin","acc01",["A1"]] ,["payPrin","acc01",["B"]] ,["payIntResidual","acc01","B"] ]} ,[["CollectedInterest","acc01"] ,["CollectedPrincipal","acc01"] ,["CollectedPrepayment","acc01"] ,["CollectedRecoveries","acc01"]] ,None ,None ,None ,None ,("PreClosing","Amortizing") ) ``` -------------------------------- ### Basic Liquidity Provider Example Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html An example configuration for a 'warehouse' type liquidity provider, showing credit, balance, type, calculation methods, and rates. ```json { "warehouse":{ "credit" : 2000 ,"balance":300 ,"type": {"total": 4000} ,"creditCalc":"IncludeDueInt" ,"start": "2021-06-15" ,"rateType": ("fix", 0.05) ,"feeType": ("fix", 0.03) ,"rate":0.03 ,"fee":0.01 } } ``` -------------------------------- ### Limit Decorator Examples Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Examples of using the 'limit' decorator with different configurations like percentage of due amount, a fixed amount, or a formula. ```json {"balPct": 0.6} ``` ```json {"balCapAmt": 500} ``` ```json {"formula": } ``` ```json {"DS": } ``` ```json {"ds": } ``` -------------------------------- ### API Setup Source: https://absbox-doc.readthedocs.io/en/latest/analytics.html Demonstrates how to initialize the API client with different configurations, including production, development, and local environments. ```APIDOC ## API Setup Here is a list of available servers at absbox.org ```python from absbox import API, EnginePath # Initialize with default production API localAPI = API("https://absbox.org/api/latest") # Setting default language localAPI = API("https://absbox.org/api/latest", lang='english') # Initialize with development API (since version 0.26.7) localAPI = API(EnginePath.DEV, check=False) # Initialize with production API localAPI = API(EnginePath.PROD, check=False) # Initialize with local API localAPI = API(EnginePath.LOCAL, check=False) ``` **Note:** Users can pull the docker image to run their own in-house environment. The remote engine exposes RESTful Service; `absbox` sends deal models and cashflow projection assumptions to that server. The engine code is hosted at Hastructure. ``` -------------------------------- ### Example Trigger Configurations Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Demonstrates various trigger configurations including conditions and effects for different collection and distribution events. Includes examples for 'any' and 'all' logic in trigger conditions. ```json { "BeforeCollect":{} ,"AfterCollect":{ "Mytrigger0":{"condition":[("cumPoolDefaultedRate",)">",0.05] ,"effects":("newStatus","Defaulted") ,"status":False ,"curable":False} } ,"BeforeDistribution":{ "Mytrigger1":{"condition":[">=","2025-01-01"] ,"effects":("newStatus","Defaulted") ,"status":False ,"curable":False} } ,"AfterDistribution":{ "Mytrigger2": {"condition":[("bondFactor",)"<=",0.1] ,"effects":("newStatus","Accelerated") ,"status":False ,"curable":False} } } #a list of triggers effects { "AfterCollect":{ "Mytrigger3":{"condition":[("cumPoolDefaultedRate",)">",0.05] ,"effects":("Effects" ,("newStatus","Defaulted") ,("accrueFees","feeA","feeB")) ,"status":False ,"curable":False} } } # ALL and ANY logic of triggers ( and they can nested toghter ! ) ,{"AfterCollect": {"Mytrigger4": {"condition":["any" ,[("cumPoolDefaultedRate",)">",0.05] ,[>","2021-09-15"]] ,"effects":("newStatus","Accelerated") ,"status":False ,"curable":False} } } ,{"AfterCollect": {"Mytrigger5": {"condition":["all" ,[("cumPoolDefaultedRate",)">",0.05] ,[>","2021-09-15"]] ,"effects":("newStatus","Accelerated") ,"status":False ,"curable":False} } } ``` -------------------------------- ### Interest Rate Swap Configuration Example Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Example of an Interest Rate Swap configuration. It includes settlement dates, the rate pair for swapping (paying LPR5Y with spread, receiving a fixed rate), the base calculation formula, and start date. ```json swap = { "swap1":{ "settleDates":"MonthEnd" ,"pair":[("LPR5Y",0.01),0.05] # paying a float rate with spread ,and receiving a fix annualized rate ,"base":{"formula":("poolBalance",)} ,"start":"2021-06-25" ,"balance":2093.87 } } ``` -------------------------------- ### Setup Account with Fixed Target Amount Source: https://absbox-doc.readthedocs.io/en/latest/nbsample/AccountSetup.html Configures distribution and reserve accounts with a fixed target balance. This setup is used to simulate scenarios where a reserve account must maintain a specific balance. ```python accountSample.accounts = (("acc01",{"balance":0}) # distribution account ,("reserveAcc",{"balance":100 ,"type":("fix",100)})) # reserve account r = localAPI.run(accountSample ,poolAssump = ("Pool",("Mortgage",None,None,None,None) ,None ,None) ,runAssump = None ,read=True) ``` -------------------------------- ### Install Absbox using pip Source: https://absbox-doc.readthedocs.io/en/latest/installation.html Use this command to install the Absbox Python package. ```bash pip install absbox ``` -------------------------------- ### Account Support Configuration Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Examples of configuring support from specific accounts, with and without book ledger details. ```python ["account","accountName"] ``` ```python ["account","accountName",("Debit","ledgerName")] ``` -------------------------------- ### Account Setup with Formula Source: https://absbox-doc.readthedocs.io/en/latest/nbsample/AccountSetup.html Define accounts with initial balances and formulas for calculating reserve account types. Use localAPI.run to process these accounts. ```python accountSample.accounts = (("acc01",{"balance":0}) ,("reserveAcc",{"balance":100 ,"type":("target" ,("*",("poolBalance",),0.02) # )}")) r2 = localAPI.run(accountSample ,poolAssump = ("Pool",("Mortgage",None,None,None,None) ,None ,None) ,runAssump = None ,read=True) ``` -------------------------------- ### Check Absbox installation version Source: https://absbox-doc.readthedocs.io/en/latest/installation.html Verify the currently installed version of the Absbox package. ```bash pip show absbox ``` -------------------------------- ### Setup Multiple Pools with Same Asset Type Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Demonstrates setting up a deal with multiple pools, where each pool contains assets of the same type (e.g., Mortgage). ```json "pool":{"PoolA":{'assets':[["Mortgage" ,{"originBalance":2200,"originRate":["fix",0.045],"originTerm":30 ,"freq":"Monthly","type":"Level","originDate":"2021-02-01"} ,{"currentBalance":2200 ,"currentRate":0.08 ,"remainTerm":30 ,"status":"current"}]])}, "PoolB":{'assets':[["Mortgage" ,{"originBalance":1100,"originRate":["fix",0.045],"originTerm":30 ,"freq":"Monthly","type":"Level","originDate":"2021-02-01"} ,{"currentBalance":1100 ,"currentRate":0.08 ,"remainTerm":30 ,"status":"current"}]]} } ``` -------------------------------- ### Setup for Bond Interest Calculation Source: https://absbox-doc.readthedocs.io/en/latest/nbsample/IntOverIntExample.html Imports pandas for data manipulation and Generic from absbox.local.generic for modeling. Sets pandas display options to show all rows. ```python import pandas as pd from absbox.local.generic import Generic pd.set_option("display.max_rows",None) ``` -------------------------------- ### Index Hedge Base Examples Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Illustrates different ways to define the base for an Index Hedge: a fixed value, a formula, or a schedule. ```json {"fix":10000} ``` ```json {"formula": } ``` ```json {"schedule": } ``` -------------------------------- ### Account Setup with Interest Rate Configuration Source: https://absbox-doc.readthedocs.io/en/latest/nbsample/AccountSetup.html Defines account structures with initial balances and complex interest rate types, including periodic resets and index-based rates. This is used for setting up financial accounts before running simulations. ```python accountSample.accounts = (("acc01",{"balance":0}) ,("reserveAcc",{"balance":100 ,"type":("target",("*",("poolBalance",),0.02)) ,"interest":{"period":"YearEnd" ,"reset":"QuarterEnd" ,"index":"SOFR3M" ,"spread":0.02 ,"rate":0.03 ,"lastSettleDate":"2020-11-02"} })) r4 = localAPI.run(accountSample ,poolAssump = ("Pool",("Mortgage",None,None,None,None) ,None ,None) ,runAssump = [("interest",("SOFR3M",0.04))] ,read=True) ``` -------------------------------- ### Account Setup with Fixed Rate Interest Source: https://absbox-doc.readthedocs.io/en/latest/nbsample/AccountSetup.html Configure accounts with fixed interest rates, specifying the interest period, rate, and last settlement date. Use localAPI.run to process these accounts. ```python accountSample.accounts = (("acc01",{"balance":0 ,"interest":{"period":"QuarterEnd" # ,"rate":0.05 ,"lastSettleDate":"2022-11-02"} }) ,("reserveAcc",{"balance":100 ,"type":("target",("*",("poolBalance",),0.02))})) r3 = localAPI.run(accountSample ,poolAssump = ("Pool",("Mortgage",None,None,None,None) ,None ,None) ,runAssump = None ,read=True) ``` -------------------------------- ### Setup Multiple Pools with Mixed Asset Types Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Illustrates setting up a deal with multiple pools, where pools can contain different asset types (e.g., Mortgage and Loan). ```json "pool":{"PoolA":{'assets':[["Mortgage" ,{"originBalance":2200,"originRate":["fix",0.045],"originTerm":30 ,"freq":"Monthly","type":"Level","originDate":"2021-02-01"} ,{"currentBalance":2200 ,"currentRate":0.08 ,"remainTerm":30 ,"status":"current"}]])}, "PoolB":{'assets':[["Loan" ,{"originBalance": 80000 ,"originRate": ["floater",0.045,{"index":"SOFR3M" ,"spread":0.01 ,"reset":"QuarterEnd"}] ,"originTerm": 60 ,"freq": "Monthly" ,"type": "i_p" ,"originDate": "2021-02-01"} ,{"currentBalance": 65000 ,"currentRate": 0.06 ,"remainTerm": 60 ,"status": "Current"}]]} } ``` -------------------------------- ### Get Library Path Source: https://absbox-doc.readthedocs.io/en/latest/library.html Retrieve the path for the Deal Library. This is useful for configuring connections to the public or self-hosted instances. ```python from absbox import LibraryPath ``` -------------------------------- ### Setup Absbox API Source: https://absbox-doc.readthedocs.io/en/latest/analytics.html Instantiate the Absbox API client for different environments (development, production, local) and set default language. Supports versions from 0.26.7. ```python from absbox import API,EnginePath localAPI = API("https://absbox.org/api/latest") # setting default language localAPI = API("https://absbox.org/api/latest",lang='english') # since version 0.26.7 # https://absbox.org/api/dev localAPI = API(EnginePath.DEV,check=False) # https://absbox.org/api/latest localAPI = API(EnginePath.PROD,check=False) # http://localhost:8081 localAPI = API(EnginePath.LOCAL,check=False) ``` -------------------------------- ### Run Hastructure Docker container Source: https://absbox-doc.readthedocs.io/en/latest/installation.html Start a Hastructure engine instance from the Docker image. The server defaults to exposing its port at 8081. ```bash docker run yellowbean/hastructure ``` -------------------------------- ### Model Bonds in absbox Source: https://absbox-doc.readthedocs.io/en/latest/nbsample/DistillWaterfall.html Define bond structures with their principal, interest rate, start date, and rate type. Use this for setting up the initial bond portfolio. ```python bonds = ( ("AR",{"balance":198_000_000 ,"rate":0.07 ,"originBalance":198_000_000 ,"originRate":0.07 ,"startDate":"2025-02-18" ,"rateType":{"floater":[0.05,"EURIBOR3M",0.0123,"QuarterEnd"]} ,"bondType":{"Sequential":None}}) ,("B1R",{"balance":29_000_000 ,"rate":0.0 ,"originBalance":29_000_000 ,"originRate":0.07 ,"startDate":"2025-02-18" ,"rateType":{"floater":[0.05,"EURIBOR3M",0.0175,"QuarterEnd"]} ,"bondType":{"Sequential":None} }) ,("B2R",{"balance":15_000_000 ,"rate":0.046 ,"originBalance":15_000_000 ,"originRate":0.046 ,"startDate":"2025-02-18" ,"rateType":{"Fixed":0.046} ,"bondType":{"Sequential":None} }) ,("CR",{"balance":24_000_000 ,"rate":0.0 ,"originBalance":24_000_000 ,"originRate":0.07 ,"startDate":"2025-02-18" ,"rateType":{"floater":[0.05,"EURIBOR3M",0.0205,"QuarterEnd"]} ,"bondType":{"Sequential":None} }) ,("DR",{"balance":28_000_000 ,"rate":0.0 ,"originBalance":28_000_000 ,"originRate":0.07 ,"startDate":"2025-02-18" ,"rateType":{"floater":[0.05,"EURIBOR3M",0.027,"QuarterEnd"]} ,"bondType":{"Sequential":None} }) ,("ER",{"balance":18_000_000 ,"rate":0.0 ,"originBalance":18_000_000 ,"originRate":0.07 ,"startDate":"2025-02-18" ,"rateType":{"floater":[0.05,"EURIBOR3M",0.0475,"QuarterEnd"]} ,"bondType":{"Sequential":None} }) ,("FR",{"balance":12_000_000 ,"rate":0.0 ,"originBalance":12_000_000 ,"originRate":0.07 ,"startDate":"2025-02-18" ,"rateType":{"floater":[0.05,"EURIBOR3M",0.0757,"QuarterEnd"]} ,"bondType":{"Sequential":None} }) ,("SUB",{"balance":28_427_000 ,"rate":0.0 ,"originBalance":28_427_000 ,"originRate":0.07 ,"startDate":"2025-02-18" ,"rateType":{"Fixed":0.00} ,"bondType":{"Equity":None} ,'stmt': [ ["2025-02-18",0,0,0,0,-28_427_000,0,0,None,""] ] }) ) ``` ```python bndNames = [ bn for bn,_ in bonds ] ``` -------------------------------- ### Unlimit Liquidity Provider Configuration Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Configure an unlimited line of credit for a liquidity provider. Requires specifying the type as 'Unlimit' and a start date. ```json { "type" : "Unlimit" ,"start": } ``` -------------------------------- ### Fixed Rate Interest Setup Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Configures a fixed interest rate for an account, specifying the period, rate, and last settlement date. ```json ("ReserveAccountA",{"balance":0 ,"type":{"fixReserve":1000} ,"interest":{"period":"QuarterEnd" ,"rate":0.05 ,"lastSettleDate":"2022-11-02"}}) ``` -------------------------------- ### Formula-based Credit Calculation Example Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Demonstrates a liquidity provider where credit is calculated using a formula based on bond balances and factors. 'creditCalc' is set to 'IncludeDueInt'. ```json { "warehouse":{ "credit" : 2000 ,"balance":300 ,"type": {"formula":("max", ("factor",("bondBalance","A","B"),0.005) , ("factor",("originalBondBalance","A","B"),0.002))} ,"creditCalc":"IncludeDueInt" ,"start": "2021-06-15" ,"rateType": ("fix", 0.05) ,"feeType": ("fix", 0.03) ,"rate":0.03 ,"fee":0.01 } } ``` -------------------------------- ### Limit Decorator Tuple Examples Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Alternative syntax for the 'limit' decorator using tuples for percentage of due amount or a fixed amount. ```python ("balPct", 0.6) ``` ```python ("balCapAmt", 500) ``` ```python ("formula", ) ``` ```python ("ds", ) ``` -------------------------------- ### Floating Rate Interest Setup Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Sets up an account with a floating interest rate, including period, index, spread, reset date, current rate, and last settlement date. ```json ("InvestmentAccountA",{"balance":0 ,"type":{"fixReserve":1000} ,"interest":{"period":"QuarterEnd" ,"index":"SOFR3M" ,"spread":0.001 ,"reset":"QuarterEnd" ,"rate": 0.03 ,"lastSettleDate":"2022-11-02"}}) ``` -------------------------------- ### Setup Interest Rate Swap Deal Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Defines and sets up an interest rate swap within a deal structure. This includes specifying deal parameters, pool assets, accounts, bonds, fees, and the waterfall logic, along with the swap details. It then uses mkDeal to create the deal object and runs it using a local API. ```python from absbox import mkDeal, API deal_data = { "name":"Sample with Interest Swap" ,"dates":{"cutoff":"2021-03-01","closing":"2021-06-15","firstPay":"2021-07-26" ,"payFreq":["DayOfMonth",20],"poolFreq":"MonthEnd","stated":"2030-01-01"} ,"pool":{'assets':[["Mortgage" ,{"originBalance":2200,"originRate":["fix",0.045],"originTerm":30 ,"freq":"Monthly","type":"Level","originDate":"2021-02-01"} ,{"currentBalance":2200 ,"currentRate":0.08 ,"remainTerm":20 ,"status":"current"}]]} ,"accounts":{"acc01":{"balance":0}} ,"bonds":{"A1":{"balance":1000 ,"rate":0.07 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.08} ,"bondType":{"Sequential":None}} ,"B":{"balance":1000 ,"rate":0.0 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.00} ,"bondType":{"Equity":None}}} ,"fees":{"trusteeFee":{"type":{"fixFee":30}}} ,"collect":[["CollectedInterest","acc01"] ,["CollectedPrincipal","acc01"] ,["CollectedPrepayment","acc01"] ,["CollectedRecoveries","acc01"]] ,"waterfall":{"amortizing":[ ["payFee","acc01",['trusteeFee']] ,["settleSwap","acc01","swap1"] ,["accrueAndPayInt","acc01",["A1"]] ,["payPrin","acc01",["A1"]] ,["payPrin","acc01",["B"]] ,["payPrinResidual","acc01",["B"]] ] } } if __name__ == '__main__': from absbox import API localAPI = API("http://localhost:8081") swap = { "swap1":{"settleDates":"MonthEnd" ,"pair":("LPR5Y",0.01),0.05] ,"base":{"formula":("poolBalance",)} ,"start":"2021-06-25" ,"balance":2093.87} } deal = mkDeal(deal_data|{"rateSwap":swap}) r = localAPI.run(deal ,runAssump = [("interest" ,("LPR5Y",[["2022-01-01",0.05] ,["2023-01-01",0.06]]))] ,read=True) r['rateSwap']['swap1'] ``` -------------------------------- ### Initialize API and Define Deal Data Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Initializes the Absbox API and defines a complex deal structure including dates, pool assets, accounts, bonds, fees, collection, and waterfall logic. This setup is required before running any simulations. ```python localAPI = API("http://localhost:8081",lang='english',check=False) deal_data = { "name":"Yield Supplement Overcollateralization" ,"dates":{"cutoff":"2021-06-01" ,"closing":"2021-07-15" ,"firstPay":"2021-08-26" ,"payFreq":["DayOfMonth",20] ,"poolFreq":"MonthEnd" ,"stated":"2030-01-01"} ,"pool":{'assets':[["Mortgage" ,{"originBalance":1300,"originRate":["fix",0.045],"originTerm":30 ,"freq":"Monthly","type":"Level","originDate":"2021-03-05"} ,{"currentBalance":1300 ,"currentRate":0.08 ,"remainTerm":30 ,"status":"current"}]]} ,"accounts":{"acc01":{"balance":100} ,"acc02":{"balance":0}} ,"bonds":{"A1":{"balance":1000 ,"rate":0.07 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.08} ,"bondType":{"Sequential":None}} ,"B":{"balance":1000 ,"rate":0.0 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.00} ,"bondType":{"Equity":None}}} ,"fees":{} ,"collect":[["CollectedCash","acc01"]] ,"waterfall":{"Amortizing":[ ["accrueAndPayInt","acc01",["A1"]] ,["payPrin","acc01",["A1"] ,{"limit": {"formula":("-",("schedulePoolValuation",('PvRate',("poolWaRate",))) ,("schedulePoolValuation",('PvRate',("max",("poolWaRate",),("const",0.09))))) }}] ,["payPrin","acc01",["B"]] ,["payPrinResidual","acc01",["B"]] ]} ,"status":("PreClosing","Amortizing") } if __name__ == '__main__': from absbox import API localAPI = API("https://absbox.org/api/latest") from absbox import mkDeal deal = mkDeal(deal_data) r = localAPI.run(deal ,poolAssump = None ,runAssump = [("inspect",(["DayOfMonth",20],("schedulePoolValuation",('PvRate',0.08))) ,(["DayOfMonth",20],("schedulePoolValuation",('PvRate',("max",("poolWaRate",),("const",0.09))))) ,(["DayOfMonth",20],("-",("schedulePoolValuation",('PvRate',("poolWaRate",))) ,("schedulePoolValuation",('PvRate',("max",("poolWaRate",),("const",0.09)))))) ) ] ,read=True) # from absbox.local.util import unifyTs # unifyTs(r['result']['inspect'].values()) # r['bonds']['A1'] ``` -------------------------------- ### Deal Stats Example Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html This tuple represents deal statistics, including periods a bond has been paid and a pool has been collected. It's useful for index-based payment schedules. ```python ( .... ,None ,("PreClosing","Amortizing") ,None ,None ,None ,{"BondPaidPeriod": 2,"PoolCollectedPeriod":0} ) ``` -------------------------------- ### Liquidity Provider with Formula Capping - AbsBox Generic Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Models a liquidity provider scenario where the support amount is capped using a formula. This example demonstrates using 'Max' and 'substract' functions to define the cap based on bond due interest and account balance. ```python from absbox import Generic test01 = Generic( "liquidation provider with interest" ,{"cutoff":"2021-03-01","closing":"2021-06-15","firstPay":"2021-07-26" ,"payFreq":["DayOfMonth",20],"poolFreq":"MonthEnd","stated":"2030-01-01"} ,{'assets':[["Mortgage" ,{"originBalance":2200,"originRate":["fix",0.045],"originTerm":30 ,"freq":"Monthly","type":"Level","originDate":"2021-02-01"} ,{"currentBalance":1200 ,"currentRate":0.08 ,"remainTerm":20 ,"status":"current"}]]} ,(("acc01",{"balance":0}),("acc02",{"balance":0})) ,(("A1",{"balance":1000 ,"rate":0.08 ,"originBalance":1000 ,"originRate":0.08 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.09} ,"bondType":{"Sequential":None}}) ,("B",{"balance":500 ,"rate":0.05 ,"originBalance":500 ,"originRate":0.05 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.10} ,"bondType":{"Sequential":None} })) ,tuple() ,{"amortizing":[ ["calcInt","A1"] ,["liqSupport", "insuranceProvider","account","acc01" ,{"formula": ("Max" ,("substract",("bondDueInt","A1","B"),("accountBalance","acc01")) ,("constant",0.0))}] ,["accrueAndPayInt","acc01",["A1","B"]] ,["payPrin","acc02",["A1"]] ,["payPrin","acc02",["B"]] ,["If" ,[("bondBalance","A1","B"),"=",0] ,["accrueAndPayInt","acc02",["A1","B"]] ,["liqRepay","bal","acc01","insuranceProvider"] ,["liqRepay","bal","acc02","insuranceProvider"]] ]} ,[["CollectedInterest","acc01"] ,["CollectedPrincipal","acc02"] ,["CollectedPrepayment","acc02"] ,["CollectedRecoveries","acc02"]] ,{"insuranceProvider": {"lineOfCredit":100,"start":"2021-06-15" ,"type":{"Reset":"MonthEnd","Formula":("bondBalance",),"Pct":0.0015}}} ,None ,None ,None ,("PreClosing","Amortizing") ) ``` -------------------------------- ### Model Projected Cashflow by Factor Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Use this syntax to model assets based on projected cashflows when loan-level data is unavailable. This example specifies cashflow attribution percentages, rates, and indices. ```python ["ProjectedByFactor" , [["2024-09-01",100] ,["2024-10-01",50] ,["2024-11-01",30] ,["2024-12-01",0] ] ,"MonthEnd" ,(0.5, 0.08) ,[(0.5, 0.02, "LIBOR1M")] ] ``` -------------------------------- ### Instantiate Deal with Waterfall Source: https://absbox-doc.readthedocs.io/en/latest/nbsample/IntroWaterfall.html Instantiates a 'Generic' deal object in absbox, incorporating a defined waterfall structure. This setup includes defining assets, accounts, fees, and the waterfall itself, preparing the deal for simulation. ```python from absbox import Generic test01 = Generic( "TEST01" ,{"cutoff":"2021-03-01","closing":"2021-06-15","firstPay":"2021-07-26" ,"payFreq":["DayOfMonth",20],"poolFreq":"MonthEnd","stated":"2030-01-01"} ,{'assets':[["Mortgage" ,{"originBalance":2200,"originRate":["fix",0.045],"originTerm":30 ,"freq":"Monthly","type":"Level","originDate":"2021-02-01"} ,{"currentBalance":2200 ,"currentRate":0.08 ,"remainTerm":30 ,"status":"current"}]]} ,(("acc01",{"balance":0}),) ,(("A1",{"balance":1000 ,"rate":0.07 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.08} ,"bondType":{"Sequential":None}}) ,("B",{"balance":1000 ,"rate":0.0 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.00} ,"bondType":{"Equity":None} }) )) ,(("issuanceFee",{"type":{"fixFee":30},"feeStart":"2021-06-15"}) ,("serviceFee",{"type":{"annualPctFee":[("poolBalance",),0.02]},"feeStart":"2021-06-15"}) ,("trusteeFee",{"type":{"annualPctFee":[("poolBalance",),0.01]},"feeStart":"2021-06-15"}) ) ,sampleWaterfall ,[["CollectedInterest","acc01"] ,["CollectedPrincipal","acc01"] ,["CollectedPrepayment","acc01"] ,["CollectedRecoveries","acc01"]] ,None ,None ,None ,None ,("PreClosing","Amortizing") ) ``` -------------------------------- ### Model Bond with BalanceByPeriod Schedule Source: https://absbox-doc.readthedocs.io/en/latest/nbsample/BondScheduleByPeriod.html This snippet defines a generic deal with a bond ('A1') that has a principal repayment schedule defined by 'BalanceByPeriod'. The schedule specifies the remaining principal balance for each period. This example requires AbsBox version 0.42.x or later. ```python from absbox import Generic test01 = Generic( "deal with bond schedule by index" ,{"collect":["2021-03-01","2021-06-30"],"pay":["2021-06-15","2021-07-20"] ,"payFreq":["DayOfMonth",20],"poolFreq":"MonthEnd","stated":"2030-01-01"} ,{'assets':[["Mortgage" ,{"originBalance":2200,"originRate":0.045,"originTerm":30 ,"freq":"Monthly","type":"Level","originDate":"2021-02-01"} ,{"currentBalance":2200 ,"currentRate":0.08 ,"remainTerm":30 ,"status":"current"}]] ,'issuanceStat':{"IssuanceBalance":2300}} ,(("acc01",{"balance":0}),) ,(("A1",{"balance":1000 ,"rate":0.07 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.08} ,"bondType":{"BalanceByPeriod": [[0,900] ,[1,850] ,[2,825] ,[3,810] ,[4,805] ,[5,780] ,[6,0] ]} }) ,("B",{"balance":1000 ,"rate":0.0 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.00} ,"bondType":{"Equity":None} })) ,(("trusteeFee",{"type":{"fixFee":30},"feeStart":"2021-06-15"}),) ,{"amortizing":[ ["payFee","acc01",['trusteeFee']] ,["accrueAndPayInt","acc01",["A1"]] ,['inspect',"beforePayPrin",("dealStat","int","BondPaidPeriod")] ,["payPrin","acc01",["A1"]] ,["payPrin","acc01",["B"]] ,["payIntResidual","acc01","B"] ]} ,[["CollectedInterest","acc01"] ,["CollectedPrincipal","acc01"] ,["CollectedPrepayment","acc01"] ,["CollectedRecoveries","acc01"]] ,None ,None ,None ,None ,"Amortizing" ,None ,None ,None ,{"BondPaidPeriod": 2,"PoolCollectedPeriod":0} ) ``` -------------------------------- ### Apply Pool Level Assumption for Installment Asset Source: https://absbox-doc.readthedocs.io/en/latest/analytics.html Sets default, prepayment, recovery, and extra assumptions for all Installment assets within a pool. ```python ("Pool",("Installment",,,,) , ,) ``` -------------------------------- ### Initialize Root Finder with Deal Parameters Source: https://absbox-doc.readthedocs.io/en/latest/analytics.html Set up the root finder for advanced analytics. This function requires a deal object, pool assumptions, run assumptions, and a tweak/stop condition tuple. Use with caution on public servers due to CPU intensity. ```python r0 = api.runRootFinder( , , ,(, >) ) ``` -------------------------------- ### Installment with Evenly Distributed Fee and Principal Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Model an installment asset with evenly distributed fee and principal. The `type` is set to `"f_p"`. ```python ["Installment" ,{"originBalance": 1000.0 ,"feeRate": ["fix",0.01] ,"originTerm": 12 ,"freq": "Monthly" ,"type": "f_p" ,"originDate": "2022-01-01"} ,{"status": "Current" ,"currentBalance":1000 ,"remainTerm":10}] ``` -------------------------------- ### Initialize Generic Deal with Fee by Index Source: https://absbox-doc.readthedocs.io/en/latest/nbsample/FeeFlowByIndex.html Sets up a 'Generic' deal instance with a fee structure defined by 'feeByIndex'. This configuration is useful for applying specific fee amounts at different periods. Ensure all required parameters for assets, liabilities, and cash flows are correctly provided. ```python from absbox import Generic test01 = Generic( "deal with bond schedule by index" ,{"collect":["2021-03-01","2021-06-30"],"pay":["2021-06-15","2021-07-20"] ,"payFreq":["DayOfMonth",20],"poolFreq":"MonthEnd","stated":"2030-01-01"} ,{'assets':[["Mortgage" ,{"originBalance":2200,"originRate":["fix",0.045],"originTerm":30 ,"freq":"Monthly","type":"Level","originDate":"2021-02-01"} ,{"currentBalance":2200 ,"currentRate":0.08 ,"remainTerm":30 ,"status":"current"}]] ,'issuanceStat':{"IssuanceBalance":2300}} ,(("acc01",{"balance":0}),) ,(("A1",{"balance":1000 ,"rate":0.07 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.08} ,"bondType": "Sequential" }) ,("B",{"balance":1000 ,"rate":0.0 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.00} ,"bondType":{"Equity":None} })) ,(("feeByIndex",{"type":{"flowByBondPeriod": [ [1,80],[2,120],[3,300] ]},"feeStart":"2021-06-15"}),) ,{"amortizing":[ ["calcAndPayFee","acc01",['feeByIndex']] ,["accrueAndPayInt","acc01",["A1"]] ,["payPrin","acc01",["A1"]] ,["payPrin","acc01",["B"]] ,["payIntResidual","acc01","B"] ]} ,[["CollectedInterest","acc01"] ,["CollectedPrincipal","acc01"] ,["CollectedPrepayment","acc01"] ,["CollectedRecoveries","acc01"]] ,None ,None ,None ,None ,"Amortizing" ,None ,None ,None ,{"BondPaidPeriod": 0,"PoolCollectedPeriod":0} ) ``` -------------------------------- ### Initialize API and Run Deal Source: https://absbox-doc.readthedocs.io/en/latest/howto.html Initialize the absbox API client and create a deal object. Then, run the deal projection with optional assumptions and read the results. ```python from absbox import API,mkDeal localAPI = API("http://localhost:8081",check=False) deal = mkDeal(deal_data,preCheck=False) r = localAPI.run(deal ,poolAssump = None ,runAssump = None ,read=True ,preCheck=False) ``` -------------------------------- ### Installment with No Fee for First N Periods Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Model an installment asset where no fee is charged for the first N periods. The `type` is set to `("PO_FirstN", 2)`. ```python ["Installment" ,{"originBalance": 1200.0 ,"feeRate": ["fix",0.01] ,"originTerm": 12 ,"freq": "Monthly" ,"type": ("PO_FirstN", 2) ,"originDate": "2022-01-01"} ,{"status": "Current" ,"currentBalance":1200 ,"remainTerm":12}] ``` -------------------------------- ### Run Installment Analytics with Pool Assumptions Source: https://absbox-doc.readthedocs.io/en/latest/analytics.html Configures and runs analytics for an 'Installment' asset class, specifying pool assumptions for default, prepayment, and recovery. Allows for term-based vectors in assumptions. ```python r = localAPI.run(deal ,poolAssump = ("Pool",("Installment",,,,) , ,) ,runAssump = None ,read=True) ``` -------------------------------- ### Connect to Deal Library Source: https://absbox-doc.readthedocs.io/en/latest/library.html Instantiate the Deal Library client by providing the API endpoint. Use this to connect to a self-hosted or cloud-hosted instance. ```python from absbox import LIBRARY library = LIBRARY("http://localhost:8082/api") ``` -------------------------------- ### runDates Source: https://absbox-doc.readthedocs.io/en/latest/api.html Generates a list of dates based on a starting date and a specified date pattern. ```APIDOC runDates(_d_, _dp_, _eDate=None) generate a list of dates from date pattern Parameters: d (date): a starting date dp (date pattern): a date pattern ``` -------------------------------- ### Define Issuance Fee Source: https://absbox-doc.readthedocs.io/en/latest/modeling.html Defines a one-off issuance fee with a specified balance and start date. ```python ("issuance_fee" ,{"type":{"fixFee":100} ,"feeStart":"2022-01-01"}) ``` -------------------------------- ### Login to Deal Library Source: https://absbox-doc.readthedocs.io/en/latest/library.html Authenticate with the Deal Library using username and password, or use `safeLogin` for trial accounts. ```python library.login("username","password") library.safeLogin("trial_1")" ``` -------------------------------- ### Define and Initialize a Dummy Deal with Loan Data Source: https://absbox-doc.readthedocs.io/en/latest/howto.html Initializes a 'Generic' deal object with specified parameters and integrates the processed loan data ('mortgages') into the deal structure. ```python loan_level_deal = Generic( "loan_level_deal" ,{"cutoff":"2023-03-01","closing":"2023-02-15","firstPay":"2023-04-20" ,"payFreq":["DayOfMonth",20],"poolFreq":"MonthEnd","stated":"2042-01-01"} ,{'assets':mortgages} #<<<<<<<--- here ,(("acc01",{"balance":0}),) ,(("A1",{"balance":37498392.54 ,"rate":0.03 ,"originBalance":1000 ,"originRate":0.07 ,"startDate":"2020-01-03" ,"rateType":{"Fixed":0.08} ,"bondType":{"Sequential":None}}),) ,(("trusteeFee",{"type":{"fixFee":30}}),) ,{"amortizing":[ ["payFee","acc01",['trusteeFee']] ,["payInt","acc01",["A1"]] ,["payPrin","acc01",["A1"]] ]} ,[["CollectedInterest","acc01"] ,["CollectedPrincipal","acc01"] ,["CollectedPrepayment","acc01"] ,["CollectedRecoveries","acc01"]] ,None ,None) ``` -------------------------------- ### Define Lease Gap Assumption by Days Source: https://absbox-doc.readthedocs.io/en/latest/analytics.html Specifies the number of days between the end of one lease and the start of the next. ```python ('days', x) ``` -------------------------------- ### Load Autoreload and Set to 2 Source: https://absbox-doc.readthedocs.io/en/latest/nbsample/How-to-price-Balloon-Mortgage.html Ensures that code changes are automatically reloaded. This is a common setup for interactive Python development. ```python %load_ext autoreload %autoreload 2 ```