# HJM simulation problem

I'm trying to simulate a 3-factor HJM model. I got the algorithms from Glasserman book. In my case, I have $3$ maturity:$0.25y, 0.5y, 0.75y$. So my time grid is: $t_0=0,t_1=0.25,t_2=0.5,t_3=0.75$.

I'm trying to price the zero-coupon bonds with:

$B(0,t_j)=\exp(-\sum_{i=0}^{j-1}r(t_i)h_i),\quad \text{where}\quad h_i=t_i-t_{i-1}$

formula. $h_i=\frac{3}{12} \forall i$

$D(t_j)=B(0,t_j)$ and the starting value of $D$ is $1$, as its written in the algorithm.

In the first "for" cycle the index is going only untill $M-1$, which is $2$, so it wont be multipled with $r(t_2)$.

In other words:

$i=1$ $\rightarrow$ $D=D*\exp(-r(t_0)\frac{3}{12} )$,

$i=2$ $\rightarrow$ $D=D*\exp(-r(t_1)\frac{3}{12} ).$

After that the algorithm stops, so I either have to change the max indext to $M$ or just multiple with $\exp(-r(t_2))$ in the end, but i dont think these are the good solutions. Or if in the $i=1$ case, my first update on bondprice would be $r(t_1)$, that would be good too, but then I dont know where $\exp(-r(0))$ is in the algorithm.

-
Could you please use latex for the formulas. –  Richard Apr 11 at 15:53
Sorry, I corrected it. –  user7778 Apr 11 at 18:36

I am not sure about this specific algorithmic implementation, but I am a bit confused by your indexes and suspect you might be as well (e.g. $M$ not defined, you're showing cases of $i$ looping when it seems you mean $j$). I think it would be useful to revisit the basics:

Let $D_t \in (0,1]$ be the present value factor for a cash flow at time $t$. By construction, $D_0 = 1$.

Often, $B(0,t_j) = \text{exp}\{\int_0^{t_j} r(t) \ dt\}$ denotes a money market account as a numeraire. The discrete equivalent, as in your implementation, is $B(0,t_j) = \text{exp}\{\sum_{i=0}^{j} r(t_i) \Delta t_i\}$.

If you are building your rates from data from zeroes, you would take the reciprocal $B(0,t_j)^{-1}$, and equate this with the price for the zero with maturity $t_j$ (adjusting for quoting by multiplying by 100). It looks like this is what your $B(0,t_j)$ denotes, from the $-1$ in the exponential. This makes sense (since Bond begins with a "b"), but it could be initially confusing if you are reading papers with the other notation. Anyway, I will use your notation hereafter.

Anyway, in your implementation: Since your $\Delta t$ is constant, $$B(0,t_j) = \text{exp}\left(-\Delta t \sum_{i=0}^{j} r(t_i)\right) \\$$ where $r(0) = 0$ and $r$ is the annualized rate.

For clarity, the first iteration, $j=1$, yields: $$B(0,t_1) = \text{exp}\{-0.25(0+r(t_1))\} \\$$ and the second iteration, $j=2$, yields: $$B(0,t_1) = \text{exp}\{-0.25(0+r(t_1)+r(t_2))\} \\$$ Iterating this for all of your $t$ values should give you what you are looking for.

-
Can I use the inst. forward rates, that I simulate in the algorithm with $f(t_i,t_j)=f(t_{i-1},t_j)+\mu(t_{i-1},t_j)+\sum_{k=1}^{d}\sigma_k(t_{i-1},t_j)*‌​Z_i$ formula to price a bond? The price of bind is $B(t_i,t_j)=\exp\left(-\sum_{l=i}^{j-1}f(t_i,t_l)(t_{l+1}-t_l)\right)$. Thanks for help in advance. –  user7778 Apr 26 at 8:31