## Pricing Using Interest-Rate Tree Models

### Introduction

For purposes of illustration, this section relies on the HJM and BDT models. The HW and BK functions that perform price and sensitivity computations are not explicitly shown here. Functions that use the HW and BK models operate similarly to the BDT model.

### Computing Instrument Prices

The portfolio pricing functions `hjmprice` and `bdtprice` calculate the price of any set of supported instruments, based on an interest-rate tree. The functions are capable of pricing these instrument types:

• Bonds

• Bond options

• Bond with embedded options

• Arbitrary cash flows

• Fixed-rate notes

• Floating-rate notes

• Floating-rate notes with options or embedded options

• Caps

• Floors

• Range Notes

• Swaps

• Swaptions

For example, the syntax for calling `hjmprice` is:

`[Price, PriceTree] = hjmprice(HJMTree, InstSet, Options)`

Similarly, the calling syntax for `bdtprice` is:

`[Price, PriceTree] = bdtprice(BDTTree, InstSet, Options)`

Each function requires two input arguments: the interest-rate tree and the set of instruments, `InstSet`. An optional argument, `Options`, further controls the pricing and the output displayed. (See Pricing Options Structure for information about the `Options` argument.)

`HJMTree` is the Heath-Jarrow-Morton tree sampling of a forward-rate process, created using `hjmtree`. `BDTTree` is the Black-Derman-Toy tree sampling of an interest-rate process, created using `bdttree`. See Building a Tree of Forward Rates to learn how to create these structures.

`InstSet` is the set of instruments to be priced. This structure represents the set of instruments to be priced independently using the model.

`Options` is an options structure created with the function `derivset`. This structure defines how the tree is used to find the price of instruments in the portfolio, and how much additional information is displayed in the command window when calling the pricing function. If this input argument is not specified in the call to the pricing function, a default Options structure is used. The pricing options structure is described in Pricing Options Structure.

The portfolio pricing functions classify the instruments and call the appropriate instrument-specific pricing function for each of the instrument types. The HJM instrument-specific pricing functions are `bondbyhjm`, `cfbyhjm`, `fixedbyhjm`, `floatbyhjm`, `optbndbyhjm`, `rangefloatbyhjm`, `swapbyhjm`, and `swaptionbyhjm`. A similarly named set of functions exists for BDT models. You can also use these functions directly to calculate the price of sets of instruments of the same type.

#### HJM Pricing Example

Consider the following example, which uses the portfolio and interest-rate data in the MAT-file `deriv.mat` included in the toolbox. Load the data into the MATLAB® workspace.

```load deriv.mat ```

Use the MATLAB `whos` command to display a list of the variables loaded from the MAT-file.

`whos`
```Name Size Bytes Class Attributes BDTInstSet 1x1 15956 struct BDTTree 1x1 5138 struct BKInstSet 1x1 15946 struct BKTree 1x1 5904 struct CRRInstSet 1x1 12434 struct CRRTree 1x1 5058 struct EQPInstSet 1x1 12434 struct EQPTree 1x1 5058 struct HJMInstSet 1x1 15948 struct HJMTree 1x1 5838 struct HWInstSet 1x1 15946 struct HWTree 1x1 5904 struct ITTInstSet 1x1 12438 struct ITTTree 1x1 8862 struct ZeroInstSet 1x1 10282 struct ZeroRateSpec 1x1 1580 struct ```

`HJMTree` and `HJMInstSet` are the input arguments required to call the function `hjmprice`.

Use the `instselect` command to select `Floor` and `Cap` instruments.

```HJMSubSet = instselect(HJMInstSet,'Type', {'Floor','Cap'}); ```

Use the function `instdisp` to examine the set of instruments contained in the variable `HJMSubSet`.

 ```instdisp(HJMSubSet) ``` ```Index Type Strike Settle Maturity CapReset Basis Principal Name Quantity 1 Cap 0.03 01-Jan-2000 01-Jan-2004 1 NaN NaN 3% Cap 30 Index Type Strike Settle Maturity FloorReset Basis Principal Name Quantity 2 Floor 0.03 01-Jan-2000 01-Jan-2004 1 NaN NaN 3% Floor 40 ```

Now use `hjmprice` to calculate the price of the `Cap` and `Floor` instruments in the instrument set.

`Price = hjmprice(HJMTree, HJMSubSet)`
```Price = 6.2831 0.0486```

#### BDT Pricing Example

Load the MAT-file `deriv.mat` into the MATLAB workspace.

```load deriv.mat ```

Use the MATLAB `whos` command to display a list of the variables loaded from the MAT-file.

`whos`
``` Name Size Bytes Class Attributes BDTInstSet 1x1 15956 struct BDTTree 1x1 5138 struct BKInstSet 1x1 15946 struct BKTree 1x1 5904 struct CRRInstSet 1x1 12434 struct CRRTree 1x1 5058 struct EQPInstSet 1x1 12434 struct EQPTree 1x1 5058 struct HJMInstSet 1x1 15948 struct HJMTree 1x1 5838 struct HWInstSet 1x1 15946 struct HWTree 1x1 5904 struct ITTInstSet 1x1 12438 struct ITTTree 1x1 8862 struct ZeroInstSet 1x1 10282 struct ZeroRateSpec 1x1 1580 struct ```

`BDTTree` and `BDTInstSet` are the input arguments required to call the function `bdtprice`.

Use the `instselect` command to select `Float` and `Cap` instruments.

`BDTSubSet = instselect(BDTInstSet,'Type', {'Float', 'Cap'});`

Use the function `instdisp` to examine the set of instruments contained in the variable `BDTSubSet`.

 `instdisp(BDTSubSet)` ```Index Type Spread Settle Maturity FloatReset Basis Principal Name Quantity 1 Float 20 01-Jan-2000 01-Jan-2003 1 NaN NaN 20BP Float 8 Index Type Strike Settle Maturity CapReset Basis Principal Name Quantity 2 Cap 0.15 01-Jan-2000 01-Jan-2004 1 NaN NaN 15% Cap 30 ```

Now use `bdtprice` to calculate the price of the `Cap` and `Float` instruments in the instrument set.

```[Price, PriceTree] = bdtprice(BDTTree, BDTSubSet) ```
```Price = 100.4865 1.4375 PriceTree = struct with fields: FinObj: 'BDTPriceTree' PTree: {[2×1 double] [2×2 double] [2×3 double] [2×4 double] [2×4 double]} AITree: {[2×1 double] [2×2 double] [2×3 double] [2×4 double] [2×4 double]} tObs: [0 1 2 3 4] ```

#### Price Vector Output

The prices in the output vector `Price` correspond to the prices at observation time zero `(tObs = 0)`, which is defined as the valuation date of the interest-rate tree. The instrument indexing within `Price` is the same as the indexing within `InstSet`.

In the HJM example, the prices in the `Price` vector correspond to the instruments in this order.

`InstNames = instget(HJMInstSet, 'FieldName','Name')`
```InstNames = 4% bond 4% bond Option 101 4% Fixed 20BP Float 3% Cap 3% Floor 6%/20BP Swap ```

So, in the `Price` vector, the fourth element, 98.7159, represents the price of the fourth instrument (4% fixed-rate note); the sixth element, 6.2831, represents the price of the sixth instrument (3% cap).

In the BDT example, the prices in the `Price` vector correspond to the instruments in this order.

`InstNames = instget(BDTInstSet, 'FieldName','Name')`
```InstNames = 10% Bond 10% Bond Option 95 10% Fixed 20BP Float 15% Cap 9% Floor 15%/10BP Swap ```

So, in the `Price` vector, the fourth element, 95.5030, represents the price of the fourth instrument (10% fixed-rate note); the sixth element, 1.4863, represents the price of the sixth instrument (15% cap).

#### Price Tree Structure Output

If you call a pricing function with two output arguments, for example,

```[Price, PriceTree] = hjmprice(HJMTree, HJMInstSet) ```
```Warning: Not all cash flows are aligned with the tree. Result will be approximated. > In checktree (line 292) In hjmprice (line 85) Price = 98.7159 97.5280 0.0486 98.7159 100.5529 6.2831 0.0486 3.6923 PriceTree = struct with fields: FinObj: 'HJMPriceTree' PBush: {[8×1 double] [8×1×2 double] [8×2×2 double] [8×4×2 double] [8×8 double]} AIBush: {[8×1 double] [8×1×2 double] [8×2×2 double] [8×4×2 double] [8×8 double]} ExBush: {[8×1 double] [8×1×2 double] [8×2×2 double] [8×4×2 double] [8×8 double]} tObs: [0 1 2 3 4]```

you generate a price tree along with the price information.

The optional output price tree structure `PriceTree` holds all the pricing information.

HJM Price Tree.  In the HJM example, the first field of this structure, `FinObj`, indicates that this structure represents a price tree. The second field, `PBush`, is the tree holding the price of the instruments in each node of the tree. The third field, `AIBush`, is the tree holding the accrued interest of the instruments in each node of the tree. Finally, the fourth field, `tObs`, represents the observation time of each level of `PBush` and `AIBush`, with units in terms of compounding periods.

In this example, the price tree looks like this:

```FinObj: 'HJMPriceTree' PBush: {[8x1 double] [8x1x2 double] ...[8x8 double]} AIBush: {[8x1 double] [8x1x2 double] ... [8x8 double]} tObs: [0 1 2 3 4] ```

Both `PBush` and `AIBush` are `1`-by-`5` cell arrays, consistent with the five observation times of `tObs`. The data display has been shortened here to fit on a single line.

Using the command-line interface, you can directly examine `PriceTree.PBush`, the field within the `PriceTree` structure that contains the price tree with the price vectors at every state. The first node represents ```tObs = 0```, corresponding to the valuation date.

`PriceTree.PBush{1}`
```ans = 98.7159 97.5280 0.0486 98.7159 100.5529 6.2831 0.0486 3.6923 ```

With this interface, you can observe the prices for all instruments in the portfolio at a specific time.

BDT Price Tree.  The BDT output price tree structure `PriceTree` holds all the pricing information. The first field of this structure, `FinObj`, indicates that this structure represents a price tree. The second field, `PTree`, is the tree holding the price of the instruments in each node of the tree. The third field, `AITree`, is the tree holding the accrued interest of the instruments in each node of the tree. The fourth field, `tObs`, represents the observation time of each level of `PTree` and `AITree`, with units in terms of compounding periods.

You can directly examine the field within the `PriceTree` structure, which contains the price tree with the price vectors at every state. The first node represents `tObs = 0`, corresponding to the valuation date.

```[Price, PriceTree] = bdtprice(BDTTree, BDTInstSet) PriceTree.PTree{1}```
```ans = 95.5030 93.9079 1.7657 95.5030 100.4865 1.4863 0.0245 7.4222 ```