MATLAB Examples

# Topology of the Simulated Rates in Short Rate Models

In this script we will produce a number of visuals for the simulated rates when using HW model.

## Rates Dimensions

The rate is dependent on three parameters , where is As of Time, is Tenor, and is a random state.

## Generating Rates Paths using HW Example

We will generate rates paths using Simulate Term Structures for the HullWhite1F Model.

```SimulateTermStructuresfortheHullWhite1FModelExample ```
```HW1F = HullWhite1F with properties: ZeroCurve: [1x1 IRDataCurve] Alpha: @(t,V)inAlpha Sigma: @(t,V)inSigma ```

## Initial Term Structure

We will now plot the initial terms structure .

```figure plot(SimPaths(1,:,1)) xlabel('Tenor') ```

## Future Term Structures

Future rates can be implied from the initial term structure.

```figure surf(SimPaths(:,:,1)) ylabel('As of Time') xlabel('Tenor') ```

## Simulated Future Term Structures

Simulated future rates can be visualized as surfaces corresponding to different random states . Let's call it a rates pie. The meaning of the % perfect terminal correlation can be expressed by looking at the different slices of the rates pie.

```figure surf(SimPaths(:,:,1)) hold on surf(SimPaths(:,:,10)) ylabel('As of Time') xlabel('Tenor') ```

## Fixed Tenor Behavior

Rates corresponding to a fixed tenor can go in any direction for any given interest rate path . They can be obtained by slicing the % surfaces with a plane. The 3D space dimensions are As of Time, Tenor, and Rates.

```figure colormap(jet) a=0; b=0; for i=1:5 surf(SimPaths(:,:,i)) hold on if min(min(SimPaths(:,:,i)))<a a=min(min(SimPaths(:,:,i))); else end if max(max(SimPaths(:,:,i)))>b b=max(max(SimPaths(:,:,i))); else end end c=(b-a)/10; [x,y,z] = meshgrid(0:1:8, 0:1:15, a:c:b); v=zeros(size(x)); slice(x,y,z,v,5,[],[]) ylabel('As of Time') xlabel('Tenor') % The slices can be viewed in the following graph. figure for i=1:5 plot(SimPaths(:,2,i)) hold on xlabel('As of Time') end ```

## Fixed IR Path

Rates corresponding to different tenors move in the same direction for any given interest rate path , but not in parallel manner.

```figure colormap(jet) a=0; b=0; surf(SimPaths(:,:,2)) hold on a=min(min(SimPaths(:,:,2))); b=max(max(SimPaths(:,:,2))); c=(b-a)/10; [x,y,z] = meshgrid(0:1:8, 0:1:15, a:c:b); v=zeros(size(x)); slice(x,y,z,v,2,[],[]) slice(x,y,z,v,6,[],[]) ylabel('As of Time') xlabel('Tenor') % The slices can be viewed in the following graph. figure plot(SimPaths(:,2,2)) xlim([1 11]) title('2-Year and 7-Year Tenors') xlabel('As of Time') hold on plot(SimPaths(:,6,2),'--') ```

## Fixed As of Time

As stated earlier, rates corresponding to different tenors move in the same direction for any given interest rate path . So, the simulated term structures for any fixed time do not cross.

```figure colormap(jet) a=0; b=0; for i=1:5 surf(SimPaths(:,:,i)) hold on if min(min(SimPaths(:,:,i)))<a a=min(min(SimPaths(:,:,i))); else end if max(max(SimPaths(:,:,i)))>b b=max(max(SimPaths(:,:,i))); else end end c=(b-a)/10; [x,y,z] = meshgrid(0:1:8, 0:1:15, a:c:b); v=zeros(size(x)); slice(x,y,z,v,[],6,[]) ylabel('As of Time') xlabel('Tenor') % The slices can be viewed in the following graph. figure for j=1:5 plot(SimPaths(6,:,j)) xlim([1 8]) xlabel('Tenor') hold on end ```