I am having difficulty transitioning a bond value function into a par value function. I believe it should be based around modifying the bond value function, but I am not seeing the process. Any help would be appreciated. After writing the correct par value function, I will have to verify it works with some known inputs.
> bond_value <- function(par, c_rate, ttm, y) {
+ cf <- c(rep(par*c_rate, ttm - 1), par*(1+c_rate))
+ cf <- data.frame(cf)
+ cf$t <- as.numeric(rownames(cf))
+ cf$pv_factor <- 1 / (1 + y)^cf$t
+ cf$pv <- cf$cf * cf$pv_factor
+ sum(cf$pv)
+ }