% subscript to run the case for static Sigma and dynamic coeffiecient


k = 0;
for t = ts
    k = k+1;
    Factors = [];
    for jj = 0:FactNumLags
        timeFrame = t-RW-jj + 1:t-jj;
        if k < 4
            Factors =[Factors;
                [ Commodity(:, timeFrame); MPx(:, timeFrame); TFP(:, timeFrame)]];
        else
            Factors =[Factors;
                [ Commodity(:, timeFrame); MPx2(:, timeFrame); TFP(:, timeFrame)]];
        end
    end
    
    X = [Y(:,t-RW+1:t)]; Z = [ones(1,size(X,2));  Factors; Y(:,t-RW:t-1)];
    [Est.Ahat, Est.Areg, Est.Sighat, Est.SigReg, RegInfo(t)] =...
        RegularizeApp(X,Z,RegA,'Sample-Cov',deltas,Kfold,[],[]);
    globalAreg(:,:,k) = Est.Areg;
    overwriteRes(:,(k-1)*RW+(1:RW)) = X - Est.Areg*Z;
end

globaldfA = (RegInfo(ts(1)).dfA +RegInfo(ts(2)).dfA +RegInfo(ts(3)).dfA+RegInfo(ts(4)).dfA)*[0;1;0];

RW2 = RW*length(ts);
ts = ts(end);

MPxAux = MPx2;
MPxAux(:,1:449) = MPx(:,1:449);
Factors = [];
for jj = 0:FactNumLags
    timeFrame = t-RW2-jj + 1:t-jj;
    Factors =[Factors;
        [ Commodity(:, timeFrame); MPxAux(:, timeFrame); TFP(:, timeFrame)]];
end

X = [Y(:,t-RW2+1:t)];  Z = [ones(1,size(X,2));  Factors; Y(:,t-RW2:t-1)];

[~, ~, ~, ~, RegInfo] =...
    RegularizeApp(X,Z,'OLS',RegSigma,deltas,Kfold,overwriteRes,globaldfA);
disp(['AIC for VAR dynamic and Sigma static is: ' num2str(min(RegInfo.AICcSig),'%1.4s.')])