[R] help with operations inside matrix

Frenando fenicio.pz at gmail.com
Wed Feb 9 04:50:26 CET 2011


Hello World! 
I'm working on my thesis right now (something about financial immunization)
I'm currently working in the basics, doing a matrix that lists the present
value (or weight) of every combination of coupon rate and term to maturity, 
this is the code I have right now which is giving me a "longer object length
is not a multiple of shorter object length"

#start
rm(list=ls())
          #test
yrt <- c(0.065,0.069,0.075,0.082)          
coupon <- c(0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12)
term <- c(2:7)
          #test#         
          
PV <- function(coupon, term) 
{
PV <- sum(coupon/(1+yrt)^(1:term)) + 1/((1+yrt[term])^term)
}


matrizPV <- matrix(, nrow=6, ncol=6)
for (j in 1:6)
{
for (i in 1:6)
             {
matrizPV[i, j] = PV(coupon[i], term[j]) 
             }                                                 
}
I would appreciate any help or advice received,
greetings
-- 
View this message in context: http://r.789695.n4.nabble.com/help-with-operations-inside-matrix-tp3296581p3296581.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list