bond(f,r,c,n,i,ic=1,cf=1,t=NA,plot=FALSE)
$j=(1+eff.i)^{\frac{1}{cf}}-1$
coupon $=\frac{f*r}{cf}$ (per period)
price = coupon$*{a_{\left. {\overline {\, n \,}}\! \right |j}}+c*(1+j)^{-n}$
$MAC D=\frac{\sum_{k=1}^n k*(1+j)^{-k}*coupon+n*(1+j)^{-n}*c}{price}$
$MOD D=\frac{\sum_{k=1}^n k*(1+j)^{-(k+1)}*coupon+n*(1+j)^{-(n+1)}*c}{price}$
$MAC C=\frac{\sum_{k=1}^n k^2*(1+j)^{-k}*coupon+n^2*(1+j)^{-n}*c}{price}$
$MOD C=\frac{\sum_{k=1}^n k*(k+1)*(1+j)^{-(k+2)}*coupon+n*(n+1)*(1+j)^{-(n+2)}*c}{price}$
Price (for period t):
If t is an integer: price =coupon$*{a_{\left. {\overline {\, n-t \,}}\! \right |j}}+c*(1+j)^{-(n-t)}$
If t is not an integer then $t=t^*+k$ where $t^*$ is an integer and $0 full price $=($ coupon$*{a_{\left. {\overline {\, n-t^* \,}}\! \right |j}}+c*(1+j)^{-(n-t^*)})*(1+j)^k$ clean price = full price$-k*$coupon If price > c : premium = price$-c$ Write-down amount (for period t) $=($coupon$-c*j)*(1+j)^{-(n-t+1)}$ If price < c : discount $=c-$price Write-up amount (for period t) $=(c*j-$coupon$)*(1+j)^{-(n-t+1)}$
bond(f=100,r=.04,c=100,n=20,i=.04,ic=1,cf=1,t=1)
bond(f=100,r=.05,c=110,n=10,i=.06,ic=1,cf=2,t=5)
Run the code above in your browser using DataLab