%% Initial setup:
tic;clear all;filename5='specs';
%% Define specs:
saveasfilename=v25_asymshocks_specs(filename5);

%% Solve model:
solvepar.startat=1;
solvepar.endat=3;
v25_call_solving(filename5,solvepar);

%% Simulate model:
load(['results/' saveasfilename]);
[SSIM,XSIM,ESIM,STAT]=v25_run_simulation(saveasfilename,filename5);
%save(['results/' saveasfilename '_simresults']);

%% Analyze the results:

% clear all;
% v25_specs_defaultvalues;
% load('results/v25_defaultvalues50');
% [SSIM,XSIM,ESIM,STAT]=v25_run_simulation(saveas);

%Calculate data:
for i=1:size(STAT,1) %Delete first 20 observations from XSIM
    XSIM(i).x=XSIM(i).x(:,:,21:end,:);
end;
pctls_values=[0.01 0.1 1 5 10 25 50 75 90 95 99 99.9 99.99];
freqs_range=[0 0; 0.99 1.01];
[moments,pricestat,pctls,freqs]=v25_calcstatistics(STAT,XSIM,pctls_values,freqs_range);
toc;
costs=moments(:,:,5,1).*(0.06);

%Devide costs by agricultural GDP:
% for i=1:size(XSIM,2)
%     agriGDP(i,:)=sum(sum(XSIM(i).x(:,7,2:end,:).*XSIM(i).x(:,5,2:end,:).*ESIM(:,1,2:end,:)))/(size(XSIM(i).x,1)*size(XSIM(i).x,3)-size(XSIM(i).x,3));
% end;
% costs=costs./agriGDP;

%Clear unnecessary variables and save the rest:
%clear ESIM SSIM XSIM interp model
%save(['results/' saveasfilename '_stats']);
%FIRST RUN BEGINNING AND THEN: load(['results/' saveasfilename '_stats'])

figure;
plot(xaxisp,pctls(1,:,7,11),'b');
 pos = get(gca, 'Position');
    pos(1) = 0.1;
%     pos(2) = 0.72;
%     pos(3) = 0.325;
%     pos(4) = 0.26;
    set(gca, 'Position', pos);
hold on;
plot(xaxisp,pctls(2,:,7,11),'b:');
plot(xaxisp,pctls(2,:,8,11),'b--');
plot(xaxisp,pctls(1,:,7,9),'r');
plot(xaxisp,pctls(2,:,7,9),'r:');
plot(xaxisp,pctls(2,:,8,9),'r--');
% plot(xaxisp,pctls(1,:,7,9),'g');
% plot(xaxisp,pctls(2,:,7,9),'g:');
% plot(xaxisp,pctls(2,:,8,9),'g--');
% plot(xaxisp,pctls(1,:,7,7),'m');
plot(xaxisp,pctls(1,:,7,6),'c');
plot(xaxisp,pctls(2,:,7,6),'c:');
plot(xaxisp,pctls(2,:,8,6),'c--');
% ylim([0.8 1.97]);
hold off;ylim([0.7 2.5]);
xlabel('SD of shocks in second country');ylabel('Price');

saveas(gcf,'figures/asymshocks.png');

export_fig 'figures/asymshocks' -pdf -nocrop -transparent


% ax1 = gca; % current axes
% set(ax1,'XColor','b');set(ax1,'YColor','b');
% ax1_pos = get(ax1,'Position'); % position of first axes
% ax2 = axes('Position',ax1_pos,'XAxisLocation','top','YAxisLocation','right','Color','none');
% axes(ax2);hold on;
% plot(xaxisp,100*costs,'k--');ylabel('Costs');
%  pos = get(gca, 'Position');
%     pos(1) = 0.1;
% %     pos(2) = 0.72;
% %     pos(3) = 0.325;
% %     pos(4) = 0.26;
%     set(gca, 'Position', pos);
% hold off;
% 
% 
% % PP_old=get(gcf,'PaperPosition');
% % PS_old=get(gcf,'PaperSize');
% % set(gcf, 'PaperPosition', [-1 0 9.5 11]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
% % set(gcf, 'PaperSize', [8.5 11]); %Keep the same paper size
% 
% % saveas(gcf,'figures/privstorsubsidies.png');
% export_fig 'figures/privstorsubsidies' -pdf -nocrop -transparent
% 
