Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
How can I get my parameters after running fmincon ?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, How can I get the value of my parameters (par) after achieving minimization by fmincon and the value of intermediate variables (c(i,j) and e(i,j)) used in the code ? please help I am a big newbie in Matlab !
My code :
function monOptimisation
%Optimisation
%Matrice des contraintes
A = [0 1 1 1 ; 0 -1 0 0 ; 0 0 -1 0 ; 0 0 0 -1 ; 0 0 0 0];
b = [1 ; 0 ; 0 ; 0 ; 0];
x0=[0.5;0.5;0.5;0.5];
prix_array = cell(1)
load data
prix_array {1} = data
strike_array = cell(1)
load data2
strike_array {1}= data2
mat_vec = [67]
s0_vec = [1121]
sig0_vec = 0.0005
rest_vec = 0
r = 0
nbr_sim = 5
options=optimset('algorithm','interior-point')
par = fmincon (@(x)erreursfun(x,prix_array,strike_array,mat_vec,s0_vec,sig0_vec,rest_vec,r,nbr_sim),x0,A,b,[],[],[],[],[],options);
function f = erreursfun (par,prix_array,strike_array,mat_vec,s0_vec,sig0_vec,rest_vec,r,nbr_sim)
% GÈnÈration et stockage en mÈmoire des tous les nombres al»atoires
nbr_mat = size(mat_vec,1);
eps2=cell(nbr_mat);
for i = 1:nbr_mat
mat = mat_vec(i);
vec_strike = strike_array{i};
nbr_strike = size(vec_strike,1);
eps1=cell(nbr_strike);
for j = 1: nbr_strike
eps1{j}=randn(nbr_sim,mat);
end
eps2{i}= eps1{j};
end
c=zeros(nbr_mat,nbr_strike);
for i = 1:nbr_mat
vec_strike = strike_array{i};
prix=prix_array{i};
nbr_strike = size(vec_strike,1);
mat = mat_vec(i);
sig0=sig0_vec(i);
s0=s0_vec(i);
nbr_obs=mat_vec(i)-rest_vec(i);
e=zeros(nbr_mat,nbr_obs);
c=zeros(nbr_mat,nbr_strike);
for j =1 : nbr_strike
strike = vec_strike (j);
payoff=zeros(nbr_sim);
eps1{j}= eps2{i};
epss = eps1{j};
somme=zeros(nbr_mat,nbr_strike);
for k = 1 : nbr_sim
sigma=zeros(nbr_sim,mat+1);
Z = zeros(nbr_sim,mat);
zzero = zeros(nbr_sim);
for l = 2 : mat+1
sigma (1,1)=sig0;
Z(1,1)=1;
sigma (k,l)=(par(1) + (par(2) * (epss(k,l-1)-(0.5+ par(3)))^2)*sigma(k,l-1)^2+par(4)*sigma(k,l- 1)^2)^0.5;
Z(k,l) = Z(k,l-1)*exp((-0.5 *(sigma(k,l)^2))+(sigma(k,l)*epss(k,l-1)));
end
st(k) = s0 * (exp(r * mat)) * Z(k,mat+1);
payoff(k)= max(st(k)-strike,0);
somme(i,j)=somme(i,j)+payoff(k);
end
c(i,j)= somme(i,j)/nbr_sim;
end
end
%%%%%%%Calcul des erreurs
e=zeros(nbr_mat,nbr_strike);
for i =1 : nbr_mat
for j = 1: nbr_strike
for l = 1 : mat_vec(i)-rest_vec(i)
e(i,j)=e(i,j)+(prix(l,j)-c(i,j)*exp(r*(l-mat)))^2;
end
end
end
ee =zeros(nbr_mat);
eee = 0;
for i =1 : nbr_mat
for j =1 :nbr_strike
ee(i)=ee+e(i,j);
end
eee=eee+ ee(i);
end
f= eee;
댓글 수: 0
답변 (3개)
Jorrit
2011년 6월 20일
I asked more or less the same question a couple of days ago. The question is not exactly the same, but the answer is.
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!