[R] Simultaneous equations
Cren
oscar.soppelsa at bancaakros.it
Fri Jun 8 12:49:40 CEST 2012
Hi all,
I was wondering why I get errors trying to solve this:
*simeq <- function(x) {
f <- numeric(length(x))
f[1] <- x[1] * dnorm((log(x[1]/D) + (r + x[2]^2/2) * T)/(x[2] * sqrt(T)))
- D * exp(-r * T) * dnorm((log(x[1]/D) + (r + x[2]^2/2) * T)/(x[2] *
sqrt(T)) - x[2] * sqrt(T))
f[2] <- dnorm((log(x[1]/D) + (r + x[2]^2/2) * T)/(x[2] * sqrt(T))) * x[2]
* x[1]
}
x.start <- c(1000000,0.2)
nleqslv(x.start, simeq)*
or, alternatively, this
*simeq <- function(V_0, sigma_v) {
f <- numeric(2)
f[1] <- V_0 * dnorm((log(V_0/D) + (r + sigma_v^2/2) * T)/(sigma_v *
sqrt(T))) - D * exp(-r * T) * dnorm((log(V_0/D) + (r + sigma_v^2/2) *
T)/(sigma_v * sqrt(T)) - sigma_v * sqrt(T))
f[2] <- dnorm((log(V_0/D) + (r + sigma_v^2/2) * T)/(sigma_v * sqrt(T))) *
sigma_v * V_0
}
x.start <- c(1000000,0.2)
nleqslv(x.start, simeq)*
It says the length of function results is different from that of *x* or
that '*sigma_v*' is missing... what does this mean? I thought I did not need
to initialize *sigma_v*'s value 'cause this is a function's variable...
Thank you
--
View this message in context: http://r.789695.n4.nabble.com/Simultaneous-equations-tp2524645p4632788.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list