[R] first and second derivative calculation

jeemba2012 jabrown10 at mail.usf.edu
Mon Oct 8 07:40:45 CEST 2012

```I have a similar problem .
Here are functions I know that work properly
## PAnnuity function definition
PAnnuity <- function(A,y,m,n)
{
f<-(A/(y/m))*(1-1/((1+y/m)^n))
}

##BondPrice function
BondPrice <- function(c,y,m,n)
{
B <-100
f<-PAnnuity((c/m)*B,y,m,n) + B /((1+y/m)^n)
}

My function of question is which uses the latter function is
Co <- function(c,y,m,n)
{
f<- D(D(as.expression(BondPrice(c,y,m,n)),"y"),"y")/BondPrice(c,y,m,n)
}

when I test it using
convexity <- C0(0.09, 0.10, 2, 10)
>[1] 0.

I believe it is passing the parameters and taking the derivative of a
constant.
How do I get the 2nd Derivative and then pass the parameters for evaluation.

Thanks

--
View this message in context: http://r.789695.n4.nabble.com/first-and-second-derivative-calculation-tp1126069p4645388.html
Sent from the R help mailing list archive at Nabble.com.

```

More information about the R-help mailing list