  filename='new1ss';
disp('Solving');
    eval(sprintf('!dynare++ --per 15 --sim 3 --ss-tol 1e-40 %s.mod',filename));
    disp('Done');
    toc
    
    eval(sprintf('load %s.mat',filename));
    randn('state',372228);
    
    nsim=10000;
    
    for k=1:nsim
        disp(k);
        start = dyn_ss;
        bad_draw=1;
        while bad_draw==1
            shocks = mvnrnd([0 0 0 0 0 ], dyn_vcov_exo, 100)';
            runs = dynare_simul(filename, shocks, start);
            if any(any(isnan(runs)))
                bad_draw=1;
                disp('Bad draw.');
            else bad_draw=0;
            end
        end
    end