diff --git a/README.md b/README.md index 8866a14afcef119ea964c1193f010d4d9e32a376..20d0a5fda269ccb460e40221705ae70fdf6a29bb 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,13 @@ Main functionalities: How to run it: -------------- -- Temporarly add the dynare/matlab folder to the matlab's path. +- Temporarily add the dynare/matlab folder to the matlab's path. ```matlab >> addpath c:\dynare\4.x.y\matlab ``` -- Temporarly add folder containing the fonction Dynare_GUI to the matlab's path +- Temporarily add the folder containing the function Dynare_GUI to the Matlab's path ```matlab >> addpath c:\dynare\dynare-gui\src @@ -41,7 +41,6 @@ How to run it: >> Dynare_GUI ``` -- Important note: - -Following folder is not on GitHub, but it is necessary for running the application: \src\resources +- Important notes: +The following folder is not on GitHub, but it is necessary for running the application: \src\resources diff --git a/src/+gui_auxiliary/pf_unanticipated.m b/src/+gui_auxiliary/pf_unanticipated.m new file mode 100644 index 0000000000000000000000000000000000000000..de040310db4a028590a37eeb91584239d0696e5a --- /dev/null +++ b/src/+gui_auxiliary/pf_unanticipated.m @@ -0,0 +1,97 @@ +function pf_unanticipated(data) +% Allows deterministic simulation with unanticipated shocks +% +% INPUTS +% none +% +% OUTPUTS +% none +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2017 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +global oo_; +global M_; + +num = rows(data); +ant = {} ; unant = {}; +shock_matrix_array = {}; + +% Create two matrices for anticipated and unexpected shocks + +for i = 1:num + aux = data(i,1:5); + if aux{1,2} == 1 + aux{1,5} = true; + end + + if ~aux{1,5} + ant = sortrows([ant;aux],2); + else + unant = sortrows([unant;aux],2); + end +end + +for i = 1:rows(unant) + + % Sort both matrices by increasing number of periods + det_aux = unant(i,:); + for j = 1:rows(ant) + if ant{j,2} > unant{i,2} + det_aux = [det_aux; ant(j,:)]; + end + end + + % Re-index periods + idx = det_aux{1,2} - 1; + for k = 1:rows(det_aux) + det_aux{k,2} = det_aux{k,2} - idx; + end + + % Create "provisional" M_.det_shocks for each unanticipated shock + det_shocks_prov = struct([]); + + for n = 1:size(det_aux,1) + exo_id = find(ismember(M_.exo_names, det_aux{n,1}, 'rows')); + if(~isempty(exo_id)) + det_shocks_prov = [det_shocks_prov; struct('exo_det',0,'exo_id',exo_id,'multiplicative',0,... + 'periods',det_aux{n,2},'value',det_aux{n,3})]; + else + gui_tools.show_error('Error while saving deterministic shocks!'); + end + end + % Store each "provisional" M_.det_shocks in cell + shock_matrix_array{i,1} = det_shocks_prov; +end + +M_.det_shocks = shock_matrix_array{1,1}; +yy = oo_.steady_state; +perfect_foresight_setup; +perfect_foresight_solver; +yy = [yy, oo_.endo_simul(:,shock_matrix_array{1,1}(end).periods - 1)]; + +for i = 2:rows(shock_matrix_array) + M_.det_shocks = shock_matrix_array{i,1}; + oo_.endo_simul(:,1) = yy(:,end); + perfect_foresight_solver; + yy = [yy, oo_.endo_simul(:,shock_matrix_array{i,1}(end).periods - 1)]; +end + +end \ No newline at end of file diff --git a/src/gui_determ_simulation.m b/src/gui_determ_simulation.m index f7107fb35ce709d00fd4af095107c2a69805fee7..7f50636fac8da7cb1b4a91317f400a2e0f695f1f 100644 --- a/src/gui_determ_simulation.m +++ b/src/gui_determ_simulation.m @@ -176,25 +176,23 @@ handles.pushbuttonCommandDefinition = uicontrol( ... 'Enable', 'Off',... 'Callback', @pussbuttonAddValue_Callback); - column_names = {'Shock ','Period ','Value ', 'Remove '}; - column_format = {'char','numeric','numeric', 'logical'}; + column_names = {'Shock ','Period ','Value ', 'Remove ','Unanticipated?'}; %%% + column_format = {'char','numeric','numeric', 'logical','logical'};%%% data = get_det_shocks(); handles.shocks_table = uitable(handles.shocks_panel,'Data',data, ... 'Units','normalized','Position',[0.02 0.10 0.96 0.6],... 'ColumnName', column_names,... 'ColumnFormat', column_format,... - 'ColumnEditable', [false true true true],... - 'ColumnWidth', {150, 90, 90, 60}, ... + 'ColumnEditable', [false true true true true],... %%% + 'ColumnWidth', {200, 50, 90, 60, 100}, ... %%% 'RowName',[],... - 'CellEditCallback',@savedata); - + 'CellEditCallback',@savedata); handles.pussbuttonRemoveValue = uicontrol('Parent',handles.shocks_panel,'Style','pushbutton','Units','normalized','Position',[0.73 0.03 0.25 0.06],... 'String', 'Remove all selected', ... 'Enable', 'Off',... 'Callback', @pussbuttonRemoveValues_Callback); - %initval and endval column_names = {'Shock ','Initval ','Endval '}; column_format = {'char','numeric','numeric'}; @@ -225,6 +223,7 @@ handles.pushbuttonCommandDefinition = uicontrol( ... shocks_data_items = shocks_data_items +1; shocks_data{shocks_data_items,1} = selected_shock; shocks_data{shocks_data_items,4} = false; + shocks_data{shocks_data_items,5} = false; %%% set(handles.shocks_table, 'Data', shocks_data); end end @@ -233,7 +232,7 @@ handles.pushbuttonCommandDefinition = uicontrol( ... shocks_data = get(handles.shocks_table, 'Data'); shocks_data_items = size(shocks_data,1); num=0; - new_data = cell(0,4); + new_data = cell(0,5); %%% for(i=1:shocks_data_items) if(~shocks_data{i,4}) num = num+1; @@ -257,18 +256,17 @@ handles.pushbuttonCommandDefinition = uicontrol( ... end end - function data = get_det_shocks() - data = cell(0,4); + data = cell(0,5); %%% if(isfield(M_,'det_shocks') && ~isempty(M_.det_shocks)) num = size(M_.det_shocks); for i=1:num - data{i,1} = M_.exo_names(M_.det_shocks(i).exo_id); + data{i,1} = M_.exo_names(M_.det_shocks(i).exo_id,:); data{i,2} = M_.det_shocks(i).periods; data{i,3} = M_.det_shocks(i).value; data{i,4} = false; - end - + data{i,5} = false; %%% + end end end @@ -282,13 +280,12 @@ handles.pushbuttonCommandDefinition = uicontrol( ... M_.det_shocks = [ M_.det_shocks; struct('exo_det',0,'exo_id',exo_id,'multiplicative',0,'periods',data{i,2},'value',data{i,3}) ]; else - gui_tools.show_error('Error while saving deterministic shocks!'); - + gui_tools.show_error('Error while saving deterministic shocks!'); end end - end - + end end + function data = get_exo_steady_states() data = cell(M_.exo_nbr,3); for i=1:M_.exo_nbr @@ -329,7 +326,6 @@ handles.pushbuttonCommandDefinition = uicontrol( ... end end - function pussbuttonSimulation_Callback(hObject,evendata) comm_str = get(handles.simul, 'String'); @@ -377,12 +373,32 @@ handles.pushbuttonCommandDefinition = uicontrol( ... end model_settings.varlist_.simul = var_list_; - try - set_det_shocks(); - set_exo_steady_states(); + + data = get(handles.shocks_table, 'Data'); + aux = data(:,5); + is_unant = 0; + + for i = 1:rows(aux) + if aux{i} + is_unant = is_unant + 1; + end + end + + try + if is_unant == 0 + set_det_shocks(); + set_exo_steady_states(); + perfect_foresight_setup; + perfect_foresight_solver; + else + set_exo_steady_states(); + unanticipated_shocks(); + % Uncomment the following if you want to keep the + % original M_.det_shocks after simulation + % + % set_det_shocks(); + end - perfect_foresight_setup; - perfect_foresight_solver; vars = getVariablesSelected; for ii=1: size(vars,2) rplot(vars{ii}); @@ -406,7 +422,6 @@ handles.pushbuttonCommandDefinition = uicontrol( ... end end - function pussbuttonReset_Callback(hObject,evendata) for ii = 1:handles.numVars set(handles.vars(ii),'Value',0); @@ -478,11 +493,9 @@ handles.pushbuttonCommandDefinition = uicontrol( ... if get(handles.vars(ii),'Value') num=num+1; varName = get(handles.vars(ii),'TooltipString'); - vars(num) = cellstr(varName); - + vars(num) = cellstr(varName); end - end - + end end function pussbuttonCloseAll_Callback(hObject,evendata) @@ -493,4 +506,10 @@ handles.pushbuttonCommandDefinition = uicontrol( ... gui_tabs.delete_tab(hTab); end -end \ No newline at end of file + + function unanticipated_shocks() + data = get(handles.shocks_table, 'Data'); + gui_auxiliary.pf_unanticipated(data); + end + +end