I am trying to price a bond that will pay coupons (c) semiannually for 4 years (which means 8 coupon payments in total) and return the principal (p) amount along with the 8th payment (c+p). The discount rate (dr) to discount each cashflows will be different.
inputs:
dr = [0.10, 0.12, 0.15, 0.22, 0.37, 0.6, 0.8, 0.85], p = 1000, c = 2, T = 4, freq = 2
I found the below code in stackoverflow but this does not use different 'dr' to discount each cashflows and also do not sum all the cashflows after discounting. Can someone please help? '''
par = 1000
coupon_rate = 3
T = 5
freq = 2
def cf_calculator(par, r, T, freq):
for i in range(0,(T * freq)+1):
if i < (T * freq):
coupon = ((r/100) * par) / freq
print(coupon)
else:
coupon = (((r/100) * par) / freq) + par
print(coupon)
print(cf_calculator(par,coupon_rate,T,freq))
'''