RGe=data(:,6);
RGe(length(RGe))=[];
Ribm=data(:,4);
Ribm(length(Ribm))=[];
Rm=data(:,14);
Rm(length(Rm))=[];
param_set0=[0.00002 .00008 .06 .001 -0.003 0.005]';
myoptions = optimset('Display','iter','TolFun',1e-8,'MaxIter',2500,'MaxFunEvals',2000);
param_setOptimumGe=fminsearch(@(param_set) LogLH(param_set,RGe,Rm),param_set0,myoptions);
param_setOptimumIbm=fminsearch(@(param_set) LogLH(param_set,Ribm,Rm),param_set0,myoptions);
[XtpIbm,YtpIbm,YteIbm,PpIbm,kIbm,PIbm,XtpAdjIbm,VarYtpIbm, EXtpAdjIbm, EYtpIbm...
    ,RstockEstimatedAdjIbm,RstockEstimatedPreIbm,rEeAdjIbm,rEePreIbm]=kalman_filt(Ribm,Rm,param_setOptimumIbm);
[XtpGe,YtpGe,YteGe,PpGe,kGe,PGe,XtpAdjGe,VarYtpGe, EXtpAdjGe, EYtpGe...
    ,RstockEstimatedAdjGe,RstockEstimatedPreGe,rEeAdjGe,rEePreGe]=kalman_filt(RGe,Rm,param_setOptimumGe);

plot(1:length(RGe),rEeAdjGe,'b')
hold;
plot(1:length(RGe),rEePreGe,'r')

figure
plot(1:length(Ribm),rEeAdjIbm,'b')
hold;
plot(1:length(Ribm),rEePreIbm,'r')

w=[.5 .5]';
beta=[XtpAdjGe XtpAdjIbm]';
z=1.96;
for i=1:length(Rm)
    Var_Market(i)=var(Rm(1:i));
    VaR(i,1)=z*sqrt(w'*beta(:,i)*beta(:,i)'*w*Var_Market(i));
end


