## Computing Instrument Sensitivities

Sensitivities can be reported either as dollar price changes or percentage price changes. The delta, gamma, and vega sensitivities that the toolbox computes are dollar sensitivities.

The functions `hjmsens` and `bdtsens` compute the delta, gamma, and vega sensitivities of instruments using an interest-rate tree. They also optionally return the calculated price for each instrument. The sensitivity functions require the same two input arguments used by the pricing functions (`HJMTree` and `HJMInstSet` for HJM; `BDTTree` and `BDTInstSet` for BDT).

Sensitivity functions calculate the dollar value of delta and gamma by shifting the observed forward yield curve by 100 basis points in each direction, and the dollar value of vega by shifting the volatility process by 1%. To obtain the per-dollar value of the sensitivities, divide the dollar sensitivity by the price of the corresponding instrument.

### HJM Sensitivities Example

The calling syntax for the function is:

```[Delta, Gamma, Vega, Price] = hjmsens(HJMTree, HJMInstSet)```

Use the previous example data to calculate the price of instruments.

```load deriv.mat [Delta, Gamma, Vega, Price] = hjmsens(HJMTree, HJMInstSet); ```
```Warning: Not all cash flows are aligned with the tree. Result will be approximated. ```

Note

The warning appears because some of the cash flows for the second bond do not fall exactly on a tree node.

You can conveniently examine the sensitivities and the prices by arranging them into a single matrix.

`All = [Delta, Gamma, Vega, Price]`
```All = -272.65 1029.90 0.00 98.72 -347.43 1622.69 -0.04 97.53 -8.08 643.40 34.07 0.05 -272.65 1029.90 0.00 98.72 -1.04 3.31 0 100.55 294.97 6852.56 93.69 6.28 -47.16 8459.99 93.69 0.05 -282.05 1059.68 0.00 3.69 ```

As with the prices, each row of the sensitivity vectors corresponds to the similarly indexed instrument in `HJMInstSet`. To view the per-dollar sensitivities, divide each dollar sensitivity by the corresponding instrument price.

### BDT Sensitivities Example

The calling syntax for the function is:

```[Delta, Gamma, Vega, Price] = bdtsens(BDTTree, BDTInstSet);```

Arrange the sensitivities and prices into a single matrix.

`All = [Delta, Gamma, Vega, Price]`
```All = -232.67 803.71 -0.00 95.50 -281.05 1181.93 -0.01 93.91 -50.54 246.02 5.31 1.77 -232.67 803.71 0 95.50 0.84 2.45 0 100.49 78.38 748.98 13.54 1.49 -4.36 382.06 2.50 0.02 -253.23 863.81 0 7.42```

To view the per-dollar sensitivities, divide each dollar sensitivity by the corresponding instrument price.

`All = [Delta ./ Price, Gamma ./ Price, Vega ./ Price, Price]`
```All = -2.44 8.42 -0.00 95.50 -2.99 12.59 -0.00 93.91 -28.63 139.34 3.01 1.77 -2.44 8.42 0 95.50 0.01 0.02 0 100.49 52.73 503.92 9.11 1.49 -177.89 15577.42 101.87 0.02 -34.12 116.38 0 7.42```