## Documentation Center |

This example illustrates how the Financial Toolbox™ and Financial Instruments Toolbox™ can be used to price a level mortgage backed security using the BDT model.

On this page… |
---|

Load the BDT Tree Stored in the Data File Observe the Interest Rate Tree Compute the Price Tree for the Non-Prepayable Mortgage |

**Load the BDT Tree Stored in the Data File**

```
load mbsexample.mat
```

**Observe the Interest Rate Tree**

Visualize the interest rate evolution along the tree by looking at the output structure BDTTree. BDTTree returns an inverse discount tree, which you can convert into an interest rate tree with the cvtree function.

BDTTreeR = cvtree(BDTTree);

Look at the upper branch and lower branch paths of the tree:

OldFormat = get(0, 'format'); format short %Rate at root node: RateRoot = treepath(BDTTreeR.RateTree, [0]) %Rates along upper branch: RatePathUp = treepath(BDTTreeR.RateTree, [1 1 1 1 1]) %Rates along lower branch: RatePathDown = treepath(BDTTreeR.RateTree, [2 2 2 2 2])

RateRoot = 0.0399 RatePathUp = 0.0399 0.0397 0.0391 0.0383 0.0373 0.0360 RatePathDown = 0.0399 0.0470 0.0550 0.0638 0.0734 0.0841

**Compute the Price Tree for the Non-Prepayable Mortgage**

Let's say that we have a 3 year $10000 level prepayable loan, with a mortgage interest rate of 4.64% semi-annually compounded.

MortgageAmount = 10000; CouponRate = 0.0464; Period = 2; Settle='01-Jan-2007'; Maturity='01-Jan-2010'; Compounding = BDTTree.TimeSpec.Compounding; format bank % Use the function 'amortize.m' in the Financial Toolbox to calculate the mortgage % payment of the loan (MP), the interest and principal components, and the % outstanding principal balance. NumPeriods = date2time(Settle,Maturity, Compounding)'; [Principal, InterestPayment, OutstandingBalance, MP] = amortize(CouponRate/Period, NumPeriods, MortgageAmount); % Display Principal, Interest and Outstanding balances PrincipalAmount = Principal' InterestPaymentAmount = InterestPayment' OutstandingBalanceAmount =OutstandingBalance' CFlowAmounts = MP*ones(1,NumPeriods); % The CFlowDates are the same as the tree level dates CFlowDates= {'01-Jul-2007' ,'01-Jan-2008' ,'01-Jul-2008' , '01-Jan-2009' , '01-Jul-2009' , '01-Jan-2010'} ; % Calculate the price of the non-prepayable mortgage [PriceNonPrepayableMortgage, PriceTreeNonPrepayableMortgage] = cfbybdt(BDTTree, CFlowAmounts, CFlowDates, Settle); for iLevel = 2:length(PriceTreeNonPrepayableMortgage.PTree) PriceTreeNonPrepayableMortgage.PTree{iLevel}(:,:)= PriceTreeNonPrepayableMortgage.PTree{iLevel}(:,:) - MP; end % Look at the price of the mortgage today (tObs = 0) PriceNonPrepayableMortgage % The value of the non-prepayable mortgage is $10017.47. This value exceeds % the $10000 amount borrowed since the homeowner received not only $10000, but % also a prepayment option. % Look at the value of the mortgage on the last date, right after the last % mortgage payment, is zero: PriceTreeNonPrepayableMortgage.PTree{end}; % Visualize the price tree for the non-prepayable mortgage. treeviewer(PriceTreeNonPrepayableMortgage)

PrincipalAmount = 1572.59 1609.07 1646.40 1684.60 1723.68 1763.67 InterestPaymentAmount = 232.00 195.52 158.19 119.99 80.91 40.92 OutstandingBalanceAmount = 8427.41 6818.34 5171.94 3487.35 1763.67 0.00 PriceNonPrepayableMortgage = 10017.47

**Compute the Price Tree of the Prepayment Option**

% The Prepayment option is like a call option on a bond. % % The exercise price or strike will be equal to the outstanding principal amount % which has been calculated using the function 'amortize.m'. OptSpec = 'call'; Strike = [MortgageAmount OutstandingBalance]; ExerciseDates =[Settle CFlowDates]; AmericanOpt = 0; Maturity = CFlowDates(end); % Compute the price of the prepayment option: [PricePrepaymentOption, PriceTreePrepaymentOption] = prepaymentbybdt(BDTTree, OptSpec, Strike, ExerciseDates, AmericanOpt, ... 0, Settle, Maturity,[], [], [], ... [], [], [], [], 0, [], CFlowAmounts); % Look at the price of the prepayment option today (tObs = 0) PricePrepaymentOption % The value of the prepayment option is $17.47 as expected. % Visualize the price tree for the prepayment option treeviewer(PriceTreePrepaymentOption)

PricePrepaymentOption = 17.47

**Calculate the Price Tree of the Prepayable Mortgage.**

% Compute the price of the prepayable mortgage. PricePrepayableMortgage = PriceNonPrepayableMortgage - PricePrepaymentOption; PriceTreePrepayableMortgage = PriceTreeNonPrepayableMortgage; for iLevel = 1:length(PriceTreeNonPrepayableMortgage.PTree) PriceTreePrepayableMortgage.PTree{iLevel}(:,:)= PriceTreeNonPrepayableMortgage.PTree{iLevel}(:,:) - ... PriceTreePrepaymentOption.PTree{iLevel}(:,:); end % Look at the price of the prepayable mortgage today (tObs = 0) PricePrepayableMortgage % The value of the prepayable mortgage is $10000 as expected. % Visualize the price and price tree for the prepayable mortgage treeviewer(PriceTreePrepayableMortgage) set(0, 'format', OldFormat);

PricePrepayableMortgage = 10000.00

Was this topic helpful?