F = 100 lam = 0.10 m= 1 ## one coupon payments a year C = 0.08 * F ## the coupon payment n = 10*m ## how many payments do we make ## The price: ## one_plus_lam = 1 + lam/m P = F / one_plus_lam^n + (C/lam) * ( 1 - 1 / one_plus_lam^n ) print(P) ## The duration: ## y = lam/m c = C/F pt_1 = (1+y)/(m*y) numer = 1 + y + n*(c-y) denom = m*c*((1+y)^n - 1) + m*y pt_2 = - numer / denom D = pt_1 + pt_2 print(D)