A question about fmincon
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a object function(f(x)), which is nonlinear,with 3 parameters(say a,b,c). I want to find the max value of this function by changing these parameters subject to some constraints(st1: a>0,b>0,c>0.st2:b+c<1). Because I want to the max value not the min value, I change the object function to -f(x) so that fmincon could give me the max value of f(x). However when I type
A = [0,1,1];
b = 1;
initial = [0.00002,0.03,0.9] ;
lb = [0,0,0];
[x,fval] = -fmincon(@SimpleGARCH_1_1,initial,A,b,[],[],lb,[]) fmincon gives me this answer:
Warning: The default trust-region-reflective algorithm does not solve problems with the constraints you have specified. FMINCON will use the active-set algorithm instead. For information on applicable algorithms, see Choosing the Algorithm in the documentation. > In fmincon at 486
Solver stopped prematurely.
fmincon stopped because it exceeded the function evaluation limit, options.MaxFunEvals = 300 (the default value).
x =
NaN + NaNi NaN + NaNi NaN + NaNi
fval =
NaN + NaNi
I don't know what happened...I'm just a beginner of Matlab. The following is my code. I want to know what should I do to get the right answer. I use the same data with Excel Solver and I can get the right answer.
function [Sum_MLE] = SimpleGARCH_1_1(initial)
%SIMPLEGARCH_1_1 Summary of this function goes here
% Detailed explanation goes here
% This function calcualate the updataed volatility using a GARCH(1,1)
% process % % Inputs:
% 1- initial: a 3*1 vector which contains the initial value for % omega,alpha and beta.
% % omega = 1.67073058944028E-06;
% alpha = 0.0625323009098825;
% beta = 0.900001208378727;
load JPY
price = JPY;
Return = diff(price)./price(1:end-1);
% arithmetic return, we could also use log return
Returnsquare = Return.^2;
NumReturn = length(Return);
omega = initial(1);
alpha = initial(2);
beta = initial(3);
Vol = zeros(NumReturn-1,1);
Likelihood = zeros(NumReturn-1,1);
Vol(1) = Returnsquare(1);
for i = 2:NumReturn-1
Vol(i) = omega+alpha*Returnsquare(i)+beta*Vol(i-1);
end
% Likelihood(1:end) = -log(Vol(1:end))-Returnsquare(2:end)./Vol(1:end);
Likelihood(1:end) = log(Vol(1:end))+Returnsquare(2:end)./Vol(1:end);
%this is because there is no max function in matlab, so we use -Likelihood and find its min value so that we find the max value of Likelihood
Sum_MLE = sum(Likelihood);
end
1 Commento
Andrew Newell
il 18 Dic 2011
I'm having trouble reproducing your problem. I don't have the file JPY, so I put in a random vector, and got an answer. I see one error:
[x,fval] = -fmincon(@SimpleGARCH_1_1,initial,A,b,[],[],lb,[]);
is an invalid use of UMINUS because there are two outputs. Use this instead:
[x,fval] = fmincon(@SimpleGARCH_1_1,initial,A,b,[],[],lb,[]);
x = -x; fval = -fval;
If JPY is small, it would help if you provided the contents.
Risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!