Question: I'm getting the following error message in R when I'm attempting to use a par calculation function I created to calculate a bond's par value
I'm getting the following error message in R when I'm attempting to use a par calculation function I created to calculate a bond's par value given bond value, coupon rate, time to maturity and yield:
" print(par(1,319.8278, .05, 13, .04)) Error in par(1, 319.8278, 0.05, 13, 0.04) : unused argument (0.04)
I created the function using the following code:
par <- function (bond_value, c_rate, ttm, y) { t <- seq(1,ttm,1) pv_factor <- 1/(1 + y)^t par = bond_value / (sum(c_rate*pv_factor) + (1 / (1+y)^ttm)) }
I then tried to use my created par function above to calculate the par value given
bond_value = $1,319.8278 c_rate = 5% ttm = 13 years y = 4%
by inputting the R code print(par(1,319.8278, .05, 13, .04))
Please advise how to correct my above R code to create a "par" function that works properly to calculate a bond's par value. The steps provided to us to calculate par value are below:
Therefore, if you invest in a bond that has $1,070.919 of current bond price, 7% of annual coupon rate, 4 years to maturity, and 5% of yield, you can calculate par value as follows:
# Create time t t <- seq(1, 4, 1)
# Create present value factor pv_factor <- 1 / (1 + 0.05)^t
# Coupon rate times pv_factor c_pv_factor <- 0.07 * pv_factor
# Current bond price bond_value <- 1070.919
# Par value
par <- bond_value / (sum(c_pv_factor) + (1 / (1+0.05)^4)) par
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
