[R] optimization problem
tedzzx
zengzhenxing at gmail.com
Fri Nov 28 08:30:56 CET 2008
Hi, all
I am facing an optimization problem. I am using the function optim(par,fun),
but I find that every time I give different original guess parameter, I can
get different result. For example
I have a data frame named data:
head(data)
price s x t
1 1678.0 12817 11200 0.1495902
2 1675.5 12817 11200 0.1495902
3 1678.0 12817 11200 0.1495902
4 1688.0 12817 11200 0.1495902
5 1677.0 12817 11200 0.1495902
6 1678.5 12817 11200 0.1495902
…….
…….
…….
f<-function(p,...){
v=exp(p[1]+p[2]*(x/s)+p[3]*(x/s)^2)
d1=(log(s/x)+(v^2)*t/2)/(v*sqrt(t))
d2=(log(s/x)-(v^2)*t/2)/(v*sqrt(t))
sum((price-(s*pnorm(d1)-x*pnorm(d2)))^2)
}
p=c(-0.1,-0.1,0.01)
optim(par=p,f) # use the default algorism
$par
[1] -1.2669459 0.4840307 -0.6607008
$value
[1] 14534.56
$counts
function gradient
154 NA
$convergence
[1] 0
If I try a different original guess estimes, I can get different number
> p=c(-1,-0.1,0.5)
> optim(par=p,f)
$par
[1] -0.7784273 -0.4776970 -0.1877029
$value
[1] 14292.19
$counts
function gradient
76 NA
$convergence
[1] 0
$message
NULL
I have other different original estimes, It also show me different result.
Why?
Thanks.
--
View this message in context: http://www.nabble.com/optimization-problem-tp20730032p20730032.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list