# How does one estimate theta in the Ho-Lee model from a yield curve?

I have a yield curve constructed using linear interpolation with data points every 3-months for US treasuries.

I would like to use that calibrate a Ho-Lee model, but I can't wrap my head around how to calibrate theta.

Is there any implementation that I could use (preferably matlab, r or c++) or a detailed description of the algorithm that I could use for reference? I have found some notes on the optimal form of theta*, but it's described in continuous rather than discrete terms, so it's of limited use in my case.

Given the Ho-Lee interest rate model of the form \begin{align*} dr_t = \theta_t dt + \sigma dW_t, \end{align*} the price at time $t>0$ of a zero-coupon bond, with maturity $T$ and unit face, has the form \begin{align*} B(t, T) &=E\Big(e^{-\int_t^T r_s ds} \mid r_t \Big)\\ &=e^{-(T-t)r_t - \int_t^T (T-u)\theta_u du + \frac{\sigma^2}{6}(T-t)^3}. \end{align*} See this question for the details. In particular, \begin{align*} B(0, t) = e^{t\, r_0 - \int_0^t(t-u)\theta_u du + \frac{\sigma^2}{6}t^3}. \end{align*} Moreover, \begin{align*} \theta_t = \sigma^2 t - \frac{\partial^2 \ln B(0, t)}{\partial t^2}, \end{align*} which can be computed piecewise-analytically based on the interpolation scheme of the yield curve.