# Calculating Accrued Interest of Bonds

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

• @haginile I kindly request your help in this question as you provided the document against which I am comparing the Accrued Interest. – Jojo Aug 5 '15 at 15:38

Let's assume that the settlement date (T + 1 for US Treasuries) is 8/6/2015, the previous coupon date for a bond is 7/31/2015, and the next coupon date is 1/31/2016. Then the number of days in the coupon period is 184 days, and the accrual period is 4 days. The accrued interest, assuming a 5% coupon rate, must be $4/184 \times 5/2 = 0.054347826$.
• Thank you once again. One thing I'm unsure of is how to set the settlement dates for each coupon payment. I've previously assumed its just 1 day after the coupon payment is due. And hence, if I were to have a 30 year to maturity bond, then the formula would be : $accrued interest = accrued interest from last period + (1/coupon period × coupon/2)$. Is this correct? – Jojo Aug 5 '15 at 16:21
• Thanks. So, if there is a bond with 12 months to maturity and it has settlement date 8/6/2015 and has the same description as you described in you answer, and a coupon date on 7/31/2016, would the Accrued Interest for this bond be $0.054347826 + 4/184×5/2$? I'm sort of confused how to calculate the Accrued Interest for the next period. – Jojo Aug 5 '15 at 16:34