| Financial Derivatives Toolbox | ![]() |
Pricing and Sensitivity from HJM
This section explains how to use the Financial Derivatives Toolbox to compute prices and sensitivities of several financial instruments using the Heath-Jarrow-Morton (HJM) model. For information, see:
hjmprice function to compute prices for a portfolio of instruments.
hjmsens function to compute delta, gamma, and vega portfolio sensitivities.
Pricing and the Price Tree
For the HJM model, the function hjmprice calculates the price of any set of supported instruments, based on an interest rate tree. The function is capable of pricing these instrument types:
The syntax used for calling hjmprice is
This function requires two input arguments: the interest rate tree, HJMTree, and the set of instruments, InstSet. An optional argument Options further controls the pricing and the output displayed.
HJMTree is the Heath-Jarrow-Morton tree sampling of a forward rate process, created using hjmtree. See Building an HJM Forward Rate Tree to learn how to create this structure.
InstSet is the set of instruments to be priced. This structure represents the set of instruments to be priced independently using the HJM model. The section Creating and Managing Instrument Portfolios explains how to create this variable.
Options is an options structure created with the function derivset. This structure defines how the HJM 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 hjmprice, a default Options structure is used.
hjmprice classifies the instruments and calls the appropriate pricing function for each one of the instrument types. The pricing functions are bondbyhjm, cfbyhjm, fixedbyhjm, floatbyhjm, optbndbyhjm, and swapbyhjm. You can also use these functions directly to calculate the price of sets of instruments of the same type. See the documentation for these individual functions for further information.
Example: HJM Pricing
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.
Use the MATLAB whos command to display a list of the variables loaded from the MAT-file.
whosName Size Bytes ClassBDTInstSet 1x1 22708 struct array BDTTree 1x1 5522 struct array HJMInstSet 1x1 22700 struct array HJMTree 1x1 6318 struct array ZeroInstSet 1x1 14442 struct array ZeroRateSpec 1x1 1580 struct array
HJMTree and HJMInstSet are the input arguments needed to call the function hjmprice.
Use the function instdisp to examine the set of instruments contained in the variable HJMInstSet.
instdisp(HJMInstSet)
Note that there are eight instruments in this portfolio set: two bonds, one bond option, one fixed rate note, one floating rate note, one cap, one floor, and one swap. Each instrument has a corresponding index that identifies the instrument prices in the price vector returned by hjmprice.
Now use hjmprice to calculate the price of each instrument in the instrument set.
Price = hjmprice(HJMTree, HJMInstSet) Warning: Not all cash flows are aligned with the tree. Result will be approximated. Price = 98.7159 97.5280 0.0486 98.7159 100.5529 6.2831 0.0486 3.6923
| Note The warning shown above appears because some of the cash flows for the second bond do not fall exactly on a tree node. This situation is discussed further in HJM Pricing Options Structure. |
Price Vector
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 this example, the prices in the Price vector correspond to the instruments in the following order.
InstNames = instget(HJMInstSet, 'FieldName','Name') InstNames = 4% bond 4% bond Option 101 4% Fixed 20BP Float 3% Cap 3% Floor 6%/20BP Swap
Consequently, 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).
Price Tree Structure
If you call the hjmprice function with two output arguments, e.g.,
you generate a price tree along with the price information.
The optional 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, 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
PriceTree = 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 actually 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.
With this interface you can observe the prices for all instruments in the portfolio at a specific time.
| Using HJM Trees in MATLAB | Using treeviewer to View Instrument Prices Through Time | ![]() |