I am trying to calculate the accrued interest for a set of Treasury Bonds. I am comparing the answer from the code below with that for the 1st Bond(row) over here. In the link the AI is 0.061
whereas from the Python code I get 0.125
and am therefore trying to understand where I'm going wrong. I use the formula for AI available here.
#l contains the months to maturity
accrued_interest = 0
d_ordered = {}
l = [0]*59 # My set of Bonds (not included here) includes a 30 year to maturity Semi-Annual coupon bearing bond and hence l will have 59 periods
l[0] = 3 # I have a function (not included here) which calculates the difference in months between each of the coupon payments (and the settlement date and first coupon payment)
d_ordered[0] = l
coupon = 0.250
days_in_coupon_period = 180 #The Link contains half-yearly bonds
for i in range(0,1,1):
months_to_maturity_array = numpy.array(d_ordered[i])
for k in range(0,59,1):
# Adding the AI associated with each period k
accrued_interest = accrued_interest + ((coupon) * ((30*months_to_maturity_array[k]) /days_in_coupon_period))
print('AI', accrued_interest)
Thank You