Instead of giving nls() start=0.01, give it a named vector of
parameters, start=c(theta=0.01).
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Mon, Nov 16, 2015 at 6:19 AM, roberto marrone
<robertomarrone at hotmail.it> wrote:> Dear all,
>
> I have a problem using the R finction nls. I am trying to perform an
optimisation of the volatility parameter in the Black and Scholes formula. In
the function nls I wrote as a formula the call option price with the only
unknown parameter the volatility that I called theta. The code is the following
and I have recevied some errors, one is that below. In my code I use as data a
dataset of simuleted option price of length 99, and the same I did for subset.
I would like to have a code that compare my model with the volatility as an
unknown parameter with a set of gien option data. Thanks in advance.
>
>
>
> optim<- nls(call ~
S*pnorm((log(15/14)+(0.015+theta^2/2)*0.17)/(theta*sqrt(0.17))) -
14*exp(-0.015*0-17)*pnorm((log(15/14)+(0.015+theta^2/2)*0.17)/(theta*sqrt(0.17))
- theta * sqrt(0.17)), data=data, start= 0.01, control= nls.control(maxiter =
50, tol = 1e-05, minFactor = 1/1024, printEval = FALSE,
warnOnly = FALSE), subset= "data1")
>
>
> Error in nls(call ~ S * pnorm((log(15/14) + (0.015 + theta^2/2) *
0.17)/(theta * :
> parameters without starting value in 'data': theta
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.