# Black-Karasinski trinomial tree implementation

I have implemented the Black-Karasinski model aiming to fit the interest rate curve for particular dates. The way I implemented it was:

1. Defined the volatility.
2. Defined $$\Delta x = \sigma \sqrt{3\Delta t}$$.
3. Then defined $$p_{u}$$, $$p_{m}$$ and $$p_{d}$$ using the general formulae. After that randomly chose one of the path to follow.
4. Repeated the simulation 500 times, generating 500 possible paths of the interest rate.
5. Obtained the interest rate as $$r_{t}=exp(x_{t})$$.
6. The mean of all interest rates for a particular $$t$$ is the expected value (i.e. the interest rate value for that forward in specific).
7. Then, I adjusted the drift for the $$n$$ simulations by taking into consideration the interest rate value in the market curve \textbf{and here is my doubt}. I applied Newton-Raphson to minimize the difference function between the discount factor of the market rate ($$r_{t}^{*}$$) vs the discount factor of the simulated interest rate $$exp(x_{n,t})$$.

$$$$Dif(r^{*}_{t},x_{n,t},\phi_{t}) = \frac{1}{({1+r^{*}_{t})^{t/365}}} - \frac{1}{n} \sum_{i=1}^{n}\frac{1}{({1+exp(x_{n,t}}+\phi_{t}))^{t/365}}$$$$

1. Then, after obtaining the $$\phi_{t}$$ for each forward of the IR curve in $$t$$, I adjust the $$n$$ simulations using:

$$$$r_{n,t}=exp(x_{n,t}+d_{t})$$$$

1. And recompute the average $$\overline{r_{t}}$$ of all the simulations.

My doubt is regarding step (7). Is it right? If I made an analysis of my IR simulations outcome using this step-by-step routine, is it completely useless if step (7) is not the right implementation?

I am really worried about that because my implementation does not aim to fit bond prices in the market, just the discount factor of the interest rate curve is the input for the drift adjustment.