From: joseph Frank on
I have never used the golabal optimization toolbox and i am facing problems in running the global search.
I am trying to minimize the function WargaNSTR3
(Loss=WargaNSTR3(b,Qtc))
Loss is the difference between theoretical and actual prices. So I am trying to minimize the difference between the prices . The theoretical prices depend on 4 parameters in the par0 vector. So I am trying to find the values of the par0. The codes that I have written are as follows:

tol = opt(1);
MaxIter = opt(2);
gs = GlobalSearch;
options = optimset('Display','notify','TolX',tol,'MaxIter',MaxIter,...
'MaxFunEvals',500);
problem =createOptimProblem('fmincon','objective',WargaNSTR3(x,Qtc),'x0',par0,'options',options);

[NSb] = run(gs,problem);

%%%%%Is this true? is the NSB the solution to the par0 unknowns that are equivalent to b in the wargaNSTR3 function. (I feel there is something wrong as I didn't pass the par0 starting values to WargaNSTR3 function unless the program does it automatically).
Any help is greatly appreciated as the toolbox is new and I am finiding difficulties understanding the explanations of the help section
From: Walter Roberson on
joseph Frank wrote:
> I have never used the golabal optimization toolbox and i am facing
> problems in running the global search.
> I am trying to minimize the function WargaNSTR3
> (Loss=WargaNSTR3(b,Qtc))
> Loss is the difference between theoretical and actual prices. So I am
> trying to minimize the difference between the prices . The theoretical
> prices depend on 4 parameters in the par0 vector. So I am trying to find
> the values of the par0. The codes that I have written are as follows:
>
> tol = opt(1);
> MaxIter = opt(2);
> gs = GlobalSearch;
> options = optimset('Display','notify','TolX',tol,'MaxIter',MaxIter,...
> 'MaxFunEvals',500);
> problem
> =createOptimProblem('fmincon','objective',WargaNSTR3(x,Qtc),'x0',par0,'options',options);

That looks likely to be wrong to me. You have not defined x, and Qtc is not
defined either (unless it is a function), so the call to WargaNSTR3 in your
createOptimProblem call looks likely to fall. An objective that was a file
handle would make more sense to me.
From: joseph Frank on
Thanks Walter.
I modified the codes:
par0 = [0.1045,-0.03,-0.0562,1.2];
Qtc = [Q,ttmaturity,c];
tol = 1e-4;
MaxIter = 1000;
gs = GlobalSearch;
NSTR3=@(x)WargaNSTR3(x,Qtc);
options = optimset('Display','notify','TolX',tol,'MaxIter',MaxIter,...
'MaxFunEvals',5000);
problem =createOptimProblem('fmincon','objective',NSTR3,'x0',par0,'options',options);

[x]=run(gs, problem);

Matlab is running and taking time to converge :
GlobalSearch stopped because it analyzed all the trial points.
All 8 local solver runs converged with a positive local solver exit flag.


but I am always getting for x the starting values of par0. I am getting this for 120 different samples that I have. There must be something wrong. x should be the solution to the optimization problem right?

I am
From: Alan Weiss on
On 8/12/2010 6:28 PM, joseph Frank wrote:
> Thanks Walter.
> I modified the codes:
> par0 = [0.1045,-0.03,-0.0562,1.2]; Qtc = [Q,ttmaturity,c];
> tol = 1e-4;
> MaxIter = 1000;
> gs = GlobalSearch;
> NSTR3=@(x)WargaNSTR3(x,Qtc);
> options = optimset('Display','notify','TolX',tol,'MaxIter',MaxIter,...
> 'MaxFunEvals',5000);
> problem
> =createOptimProblem('fmincon','objective',NSTR3,'x0',par0,'options',options);
>
>
> [x]=run(gs, problem);
>
> Matlab is running and taking time to converge :
> GlobalSearch stopped because it analyzed all the trial points.
> All 8 local solver runs converged with a positive local solver exit flag.
>
>
> but I am always getting for x the starting values of par0. I am getting
> this for 120 different samples that I have. There must be something
> wrong. x should be the solution to the optimization problem right?
> I am

For testing, did you run
x = fmincon(problem)
If so, was x = par0? Did you try evaluating NSTR3(x) for various values
of x to make sure it is calculating what you think it should calculate?

And what do you mean "I am getting this for 120 different samples that I
have." What are you changing in your samples? Do you recreate your
function handles after changing parameters? What I mean is, if you
change, for example, Qtc, then you need to recreate NSTR3 and problem,
because they retain the old value of Qtc until you refresh them.

Are there any reasonable bounds you can put on x? If so, GlobalSearch
will have a much easier time finding better solutions, supposing they exist.

Alan Weiss
MATLAB mathematical toolbox documentation
From: joseph Frank on
I'll be able to solve it if I manage to put constraints. The codes evolved to become:

Loss=@(x)sum((nansum(NS4(ti,x(1),x(2),x(3),1.2).*ci,2) + min(NS4(ti,abs(x(1)),x(2),x(3),abs(x(4))),[],2) - Q).^2 );
gs = GlobalSearch;
options = optimset('Algorithm','interior-point');
problem =createOptimProblem('fmincon','objective',Loss,'x0',[0.1045,-0.03,-0.0562,1.2],'options',options);
[x]=run(gs, problem);

but I need to put in the creatOptimProblem function a constraint (the function is myconstrTR:
function [c]=myconstrTR(b)


m=[1:1:10]';
b0=b(1);
b1=b(2);
b2=b(3);
tau=b(4);
if tau ==0
tau=1e-6+eps;
end

s = b0 + b1*(1 - exp(-m/tau))./(m/tau) ...
+ b2*((1 - exp(-m/tau)) ./(m/tau) - exp(-m/tau)) ...
+ b3*((1 - exp(-m/tau2))./(m/tau2) - exp(-m/tau2));

c3=s(1,2)-s(1,3);
c4= s(1,3)-s(1,4);
c5=s(1,4)-s(1,5);
c6= s(1,5)-s(1,6);
c7=s(1,6)-s(1,7);
c8= s(1,7)-s(1,8);
c9= s(1,8)-s(1,9);
c=[c3 c4 c5 c6 c7 c8 c9 ];

I want c3 c4 c5 c6 c7 c8 c9 to be negative. How can I put this constraint . Note that b in the mycontrTR is the x from [x]=run(gs, problem); (in otherwords b is the unknown that I want to compute)