Financial Derivatives Toolbox    

Using HJM Trees in MATLAB

When working with the HJM model, the Financial Derivatives Toolbox uses trees to represent forward rates, prices, etc. At the highest level, these trees have structures wrapped around them. The structures encapsulate information needed to interpret completely the information contained in a tree.

Consider this example, which uses the interest rate and portfolio data in the MAT-file deriv.mat included in the toolbox.

Load the data into the MATLAB workspace.

Display the list of the variables loaded from the MAT-file.

Structure of an HJM Tree

You can now examine in some detail the contents of the HJMTree structure.

FwdTree contains the actual forward rate tree. It is represented in MATLAB as a cell array with each cell array element containing a tree level.

The other fields contain other information relevant to interpreting the values in FwdTree. The most important of these are VolSpec, TimeSpec, and RateSpec, which contain the volatility, time structure, and rate structure information respectively.

First Node.   Observe the forward rates in FwdTree. The first node represents the valuation date, tObs = 0.

Look closely at the RateSpec structure used in generating this tree to see where these values originate. Arrange the values in a single array.

If you find the corresponding inverse discounts of the interest rates in the third column, you have the values at the first node of the tree. You can turn interest rates into inverse discounts using the function rate2disc.

Second Node.   The second node represents the first rate observation time, tObs = 1. This node displays two states: one representing the branch going up and the other representing the branch going down.

Note that HJMTree.VolSpec.NumBranch = 2.

Examine the rates of the node corresponding to the up branch.

Now examine the corresponding down branch.

Third Node.   The third node represents the second observation time, tObs = 2. This node contains a total of four states, two representing the branches going up and the other two representing the branches going down.

Examine the rates of the node corresponding to the up states.

Next examine the corresponding down states.

Isolating a Specific Node.   Starting at the third level, indexing within the tree cell array becomes complex, and isolating a specific node can be difficult. The function bushpath isolates a specific node by specifying the path to the node as a vector of branches taken to reach that node. As an example, consider the node reached by starting from the root node, taking the branch up, then the branch down, and then another branch down. Given that the tree has only two branches per node, branches going up correspond to a 1, and branches going down correspond to a 2. The path up-down-down becomes the vector [1 2 2].

bushpath returns the spot rates for all the nodes touched by the path specified in the input argument, the first one corresponding to the root node, and the last one corresponding to the target node.

Isolating the same node using direct indexing obtains

As expected, this single value corresponds to the last element of the rates returned by bushpath.

You can use these techniques with any type of tree generated with the Financial Derivatives Toolbox, such as forward rate trees or price trees.

Graphical View of Forward Rate Tree

The function treeviewer provides a graphical view of the path of forward rates specified in HJMTree. For example, here is a treeviewer representation of the rates along both the up and the down branches of HJMTree.

A previous example used bushpath to find the path of forward rates taking the first branch up and then two branches down the rate tree.

The treeviewer function displays the same information obtained by clicking along the sequence of nodes, as shown next.


  Heath-Jarrow-Morton (HJM) Model Pricing and Sensitivity from HJM