Dear R Helpers

I have following data -

cash_flow = c(7, 7, 107)  # 107 = Principle 100 + interest of 7%
t = c(1,2,3)

and zero rate table as

rating         year1           year2           year3
AAA            3.60            4.17              4.73
AA              3.65            4.22             
 4.78
A                 3.72           4.32              4.93 
BBB            4.10            4.67             5.25


For each of these ratings I need to calculate the Present Value as (say e.g. for AAA)

PV(AAA)  =  7/(1+3.60/100) + 7/(1+4.17/100)^2 +  107/(1+4.73/100)^3 which is equal to 106.3549

Similarly when used the respective rates,  PV(A) = 106.2122, PV(A) = 105.7969 and PV(BBB) = 104.8871

#########################################################

## My problem

I have tried the following R code.

zero_rate =
 read.csv('zero_rate_table.csv')
zero_rate1 = zero_rate[, -1]

cash_flow = c(7, 7, 107)

t = c(1,2,3)


PV_table = cash_flow / (1+zero_rate1/100)^t

## Then using rowSums, I should get the required result. However, I am getting following output as

> PV_table

        year_1        year_2       year_3
[1,]  6.756757     6.45078      93.147342
[2,]  6.515675   94.521493      6.680664
[3,] 95.895064    6.710123      6.357680
[4,]   6.724304   6.389305     91.773536


rowSums(PV_table) gives 

[1] 106.35489 107.71783 108.96287 104.88714.

Thus, the result is correct only in first case. In second case onwards, there is a shift of final cashflow e.g. in 2nd case, pertaining to year 2, value is 94.521493 which means it includes principal of 100. 

Likewise
 in third case, the principal is included in the first cash-flow itself. Again the fourth result is correct. So there is pre-shift of capital.

I am not sure whether I am making any mistake in reading the zero_rate csv file or my formula is incorrect. Please guide. 

Thanking you all in advance

Sarah


 





      
	[[alternative HTML version deleted]]

