# optim function multi variables -newbie

6 messages
Open this post in threaded view
|

## optim function multi variables -newbie

 Hi , can i ask if somebody know the syntax for optim function with multiple variables: I have function  f  (params,y,g,h,j) returnig z y<-C(0.2,0.5,0.6) where params<-c(x1,x2) I define g,h,j and then I define params, then use optim to structure it ..however if i use syntax optim(params , f,y=y,g=g,h=h,j=j) to optimize params , but i got result equalling to my params ..which is kind of wrong. I and if i use optim(params , f(params,y=y,g=g,h=h,j=j)) I get Error in function (par)  : could not find function "fn" how ever none of them seems to be producing meaningful results Please I am newbie and could not find a proper answer to that.. Help me.!! Thanks
Open this post in threaded view
|

## Re: optim function multi variables -newbie

 On 27.01.2011 14:08, michalseneca wrote: > > Hi , > can i ask if somebody know the syntax for optim function with multiple > variables: > > I have function  f  (params,y,g,h,j) returnig z > y<-C(0.2,0.5,0.6) > where > params<-c(x1,x2) > I define g,h,j and then I define params, then use > optim to structure it ..however if i use syntax > > optim(params , f,y=y,g=g,h=h,j=j) to optimize params , but i got result > equalling to my params ..which is kind of wrong. The syntax above is correct, hence you need to describe the problem you try to solve, ideally including the full code for f and some example data. Uwe Ligges > I and if i use > optim(params , f(params,y=y,g=g,h=h,j=j)) I get  > > > Error in function (par)  : could not find function "fn" > > how ever none of them seems to be producing meaningful results > > Please I am newbie and could not find a proper answer to that.. > > Help me.!! > > Thanks > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: optim function multi variables -newbie

 Hi, Basically what I am trying is to rewrite matlab code into R ...This is code for famous SABR model Calibration. I did most of the code up to optimalization issue. In the attachment you can find matlab and my unfinished R code..This is very helpful code...Basically I am trying to achieve the same results. Thank you very much for your help..This might help me much with my thesis Best regards Michal MichaloptimtestHagan_Figure_33.zip
Open this post in threaded view
|

## Re: optim function multi variables -newbie

 michalseneca gmail.com> writes: > Hi, > Basically what I am trying is to rewrite matlab code into R ...This is code > for famous SABR model Calibration. > I did most of the code up to optimalization issue. > In the attachment you can find matlab and my unfinished R code..This is very > helpful code...Basically I am trying to achieve the same results. > > Thank you very much for your help..This might help me much with my thesis > > Best regards > Michal Apparently, you are resetting the input 'params' within the function EstimateRhoAndVol() to c(0.5, 0.5) regardless of what the actual input is. No wonder that 'optim' returns the starting values: it sees a constant function. Besides that, you have to be more careful with NAs in the SABR model. Did you try out the function? --- Are you testing the list? --Hans Werner ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.