I'm currently trying to compute the accrued interest in a trinomial Hull-White tree.
The setup is a bond with a facevalue of 100 that matures in 6 years with a coupon of 5% (annually compounding).
The tree has 10 time steps, meaning that dt = 0.6.
For each node time, i.e. 0,0.6,1.2,1.6 etc. I made a loop, that asks if the node-time has reached a coupon date, i.e. 0,1,2,3.. etc.
If a coupon is reached (e.g the coupon date 1 is reached at node-time 1.2 and 1.6) the accrued should be (1.2-1)*5=1 and (1.6-1)*5=4 respectively. I want to end up with a accrued at each node from 0 to 9 of [0,3,1,4,2,0,3,1,4,2]
But what i get now is [0,3,1,9,2,0,3,1,24,2].
My code is:
´´´
timesteps = 10
maturity = 6
coupon_dates = np.full(maturity+1, range(maturity+1))
dt = maturity/timesteps
node_times = [i * dt for i in range(timesteps)]
accrued = np.zeros(timesteps)
for i in range(len(node_times)):
accrued[i] = round(node_times[i] * 5)
for j in range(len(coupon_dates)):
if (node_times[i]-dt < coupon_dates[j] and node_times[i] >= coupon_dates[j]):
accrued[i] = round((node_times[i] - coupon_dates[j]) * 5)
´´´
Can anyone help me with this problem? And do someone have a more efficient way to compute the accrued?
Thanks in advance!