%% Calculate Cash Flows for a Sequential Collateralized Mortgage Obligation (CMO)
% Define the mortgage pool under consideration for CMO structuring using mbscfamounts or mbspassthrough and calculate the cash flows with an A and B tranche for a sequential CMO.

MortgagePrincipal = 1000000;
Coupon = 0.12;
Terms = 6; % months

% Calculate underlying mortgage cash flows
[PrincipalBalance, MonthlyPayments, SchedPrincipalPayments, ...
InterestPayments, Prepayments] = ...
mbspassthrough(MortgagePrincipal, Coupon, Terms, Terms, 0, []);
PrincipalPayments = SchedPrincipalPayments.' + Prepayments.'

%
% Define CMO tranches, A and B.

TranchePrincipals = [500000; 500000];
TrancheCoupons = [0.12; 0.12];

%
% Calculate cash flows for each tranche.

[Balance, Principal, Interest] = ...
cmoseqcf(PrincipalPayments, TranchePrincipals, TrancheCoupons, false)

% Copyright 2015 The MathWorks, Inc.