The objective function, scarti, needs a vector as input and not 4 separate
arguments.
constrOptim will call

pp<- c(0.0088,0.3339,0.3092,1.7530)
scarti(pp)

which produces the error

hth, Ingmar

On Thu, Mar 4, 2010 at 10:27 AM, <Barbara.Rogo@uniroma1.it> wrote:

>
> I have to calculate the value of a set of parameter that minimize a
> function ("scarti") with constrains. I know that "scarti" is
> right.
> Then, why I have error??? I don't understand!!! Help, thanks, it's very
> important!!!
> This is the routine:
> ---------------------------------------------------------------------
> #Stima su tassi swap del modello CIR
>
>
>
> swap=c(1.311,1.878,2.248,2.556,2.81,3.031,3.216,3.3525,3.491,3.583,3.786,3.963,4.062,4.022,3.944)
> scadswap=c(1,2,3,4,5,6,7,8,9,10,12,15,20,25,30)
>
> swapint=approx(scadswap,swap,xout=1:30,method="linear")$y
>
> flussi=mat.or.vec(nr=30,nc=30)
>
> for (k in 1:30){
>      flussi[k,]=c(rep(swapint[k],k-1),100+swapint[k],rep(0,30-k))
>
> }
>
> A=rbind(flussi)
>
> PMerc=rep(100,30)
>
> scarti=function(r,d,fi,ni){
>      vs=mat.or.vec(nr=30,nc=1)
>      for (s in 1:30){
>            a=(d*exp(fi*s)/(fi*(exp(d*s)-1)+d))^(ni)
>            b=((exp(d*s)-1)/(fi*(exp(d*s)-1)+d))
>            vs[s]=a*exp(-r*b)
>      }
>      PMod=A%*%vs
>      return(sum((PMerc-PMod)^2))
> }
>
>
> parCIR=constrOptim(c(0.0088,0.3339,0.3092,1.7530),scarti,NULL,ui=rbind(c(1,0,0,0),c(0,1,-1,0),c(0,1,0,0),c(0,0,0,1)),ci=c(0,0,0,1))$par
> ---------------------------------------------------------------------------
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> 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.
>

	[[alternative HTML version deleted]]

