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.