Structured Securities - Amortized Example

Overview


This example examines a simple security that is structured like an amortized loan and backed by a pool of assets. In this example, the security has a stated principal and interest rate, and pays fixed payments.

Full Code





let amt = await import('/lib/finance/fixed-income/v1.0.0/amortized.mjs');
let pm = await import('/lib/finance/fixed-income/v1.0.0/payments.mjs');
let st = await import('/lib/sort/v1.0.0/sort.mjs');

let start = '2020-01-31';
let number = 12*10;
let period=12;
let endOfMonth = true;
let principal = 100000;
let rate = 0.05;

let payments = pm.amortized(start, principal, rate, number, period, endOfMonth);
let paymentMap = $group(payments, p=>p.date)();

let flows = //set this to an array of cash flows from assets backing the security

flows = [...flows, ...payments]
let cashFlows = $group(flows, p=>p.date).map((keys, values)=>{
    let item = {
        date:keys[0],
        cash : $list(values).filter(p=>p.value !== undefined).map(p=>p.value).sum()-$list(values).filter(p=>p.payment !== undefined).map(p=>p.payment).sum()
    }
    return item;
}).values();

let cash = 0;
for(let item of st.sort(cashFlows, p=>p.date)){
  //increase the cash available by 
  cash += item.value;
  if(item.date in paymentMap){
    item.fees = 10;
    cash -= item.fees;
  }
  item.cash = cash;
}
					
Try it!

Contents