%------------------
clear all;
close all;
clc;

%------------------
load('try_1.mat');
load('example_ssm.mat');
fig_fmt = 'png';
fields = {'k', 'c', 'r', 'z'};

%------------------
% Compute Diff: Dynare's Filtered vs Smoothed States
% for i = 1:length(fields)
%     diffVar(:, i) = SmoothedVariables.(fields{i}) - FilteredVariables.(fields{i});
% end
% 
% diffVar;


%----------------
% Plot Diff: Matlab vs Dynare Smoothed States
fig = figure();
set(fig, 'units', 'inches', 'position', [0 0 13 10]);
state_names = {'k_t', 'c_t', 'r_t', 'z_t'};

for i = 1:4
    subplot(2, 2, i);
    plot(dates, X(:,i), 'LineWidth', 1.5, 'Color', 'r'); % Matlab's State
    hold on;
    plot(dates, SmoothedVariables.(fields{i}), 'LineWidth', 1.5, 'Color','b'); % Dynare's State
    hold on;
    plot(dates, X(:,i)-SmoothedVariables.(fields{i}),'LineWidth', 0.5, 'Color','k','LineStyle', '--'); % Difference
    grid on;
    title(['State: ', state_names{i}]);
    xlabel('Date');
    ylabel('Value');
    datetick('x', 'yyyy');
    legend('Matlab', 'Dynare', 'Diff', 'Location', 'best');
end
sgtitle('Matlab vs Dynare Smoothed States');
print(fig, 'eg_Matlab_vs_Dyanre', ['-d' fig_fmt]);


%----------------
% Compute Diff: Matlab vs Dynare Filtered States
for i = 1:length(fields)
    diffVar(:, i) = X(:,i) - SmoothedVariables.(fields{i});
end







