-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from davidakelley/revision
Revision to "A Practitioner's Guide and Matlab Toolbox for Mixed Frequency State Space Models"
- Loading branch information
Showing
20 changed files
with
331 additions
and
40 deletions.
There are no files selected for viewing
Binary file modified
BIN
+111 KB
(110%)
A_Practitioners_Guide_and_Matlab_Toolbox_for_Mixed_Frequency_State_Space_Models.pdf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
% 2-variable VAR that generates a daily series from a weekly series | ||
% | ||
% The data in rateLevels and rateChanges are 2 time series: | ||
% - The 10-Year Treasury Constant Maturity Rate | ||
% - The 30-Year Fixed Rate Mortgage Average in the United States | ||
% Data retrieved from FRED as of April 1, 2020. | ||
% | ||
% See Also: | ||
% pgmtmfss_replication.m - Replication code runner script | ||
|
||
load('data_var_disagg'); | ||
|
||
%% Code Example 3: Estimating a daily VAR weekly mortgage rate survey | ||
Y = rateLevels; | ||
|
||
% Set up accumulator | ||
cal = [repmat([1; 2; 3; 1; 1;], size(Y,1)/5, 1); 1]; | ||
accum = Accumulator(2, cal, ones(size(cal))); | ||
|
||
% Set up MFVAR object and estimate | ||
mdl = MFVAR(Y, 1, accum); | ||
mdlE = mdl.estimate(); | ||
|
||
% Get daily interest rate changes | ||
alpha = mdlE.smooth(mdl.Y); | ||
|
||
|
||
%% Plot time series of interest rates | ||
% Make a plot of the spread using the daily mortgage rate and the weekly rate | ||
% where the weekly rate is the average of Mon-Wed rate placed on Tuesday. | ||
startInx = 9394; | ||
rateDisaggRS = alpha(:,2); | ||
rateDisaggNan = rateLevels(:,2); | ||
|
||
figure('Color', ones(1,3)); | ||
plot(dates(startInx:end), rateDisaggRS(startInx:end), 'LineWidth', 2); | ||
hold on; | ||
plot(dates(startInx:end), rateDisaggNan(startInx:end), 'x', 'MarkerSize', 10); | ||
box off; | ||
datetick('x', 'keeplimits') | ||
xlim([dates(startInx), dates(end)]); | ||
legend('Related series disaggregation', 'Observed data', ... | ||
'Location', 'sw', 'Orientation', 'vertical'); | ||
legend boxoff | ||
ylabel('Percent'); | ||
|
||
print 'pgmtmfss3_var_disagg.png' -dpng |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
% | ||
% | ||
|
||
% See Also: | ||
% pgmtmfss_replication.m - Replication code runner script | ||
|
||
load('data_trade'); | ||
|
||
%% Code Example 3: | ||
Y = log(data_diffl.^2); | ||
|
||
% Set up accumulator | ||
accum = Accumulator.GenerateFromDates(dates, 1, {'Month'}, {'avg'}); | ||
|
||
% Set up state space parameters | ||
Z = ones(2,1); | ||
d = nan(2,1); | ||
H = diag(nan(2,1)); | ||
T = nan; | ||
Q = nan; | ||
|
||
% Set up MFVAR object with one lag and estimate coefficients | ||
mdl = StateSpaceEstimation(Z, H, T, Q, 'd', d); | ||
mdlA = accum.augmentStateSpaceEstimation(mdl); | ||
mdlA.P0 = diag(Inf(2,1)); | ||
|
||
% Estimate parameters | ||
mdlMLE = mdlA.estimate(Y); | ||
|
||
% Get smoothed estimate of volatility parameter | ||
alpha = mdlMLE.smooth(Y); | ||
alphaSim = mdlMLE.smoothSample(Y, [], [], [], 100); | ||
sigmaHat = exp(0.5 .* alpha(:,1)); | ||
sigmaHatDraws = squeeze(exp(0.5 .* alphaSim(:,1,:))); | ||
sigmaHatBands = prctile(sigmaHatDraws, [5 95], 2); | ||
|
||
%% Plot time series of estimated volatility | ||
startInx = 1; | ||
|
||
figure('Color', ones(1,3)); | ||
hold on | ||
fill([dates(startInx:end); flipud(dates(startInx:end))], ... | ||
[sigmaHatBands(startInx:end,1); flipud(sigmaHatBands(startInx:end,2))], ... | ||
0.6 * ones(1,3), 'EdgeColor', 'none'); | ||
plot(dates(startInx:end), sigmaHat(startInx:end), ... | ||
'LineWidth', 2, 'Color', [0 0.4470 0.7410]); | ||
box off; | ||
datetick('x', 'keeplimits') | ||
ylabel('Estimated volatility'); | ||
xlim([dates(startInx)-15, dates(end)+15]); | ||
|
||
print 'pgmtmfss3_vol.png' -dpng |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
% 2-variable VAR that generates a daily series from a weekly series | ||
% | ||
% The data in rateLevels and rateChanges are 2 time series: | ||
% - The 10-Year Treasury Constant Maturity Rate | ||
% - The 30-Year Fixed Rate Mortgage Average in the United States | ||
% Data retrieved from FRED as of April 1, 2020. | ||
% | ||
% See Also: | ||
% pgmtmfss_replication.m - Replication code runner script | ||
|
||
load('data_var_disagg'); | ||
|
||
%% Code Example 3: Estimating a daily VAR weekly mortgage rate survey | ||
Y = rateLevels; | ||
|
||
% Set up accumulator | ||
calendar = [repmat([1; 2; 3; 1; 1;], size(Y,1)/5, 1); 1]; | ||
accum = Accumulator(2, calendar, ones(size(calendar))); | ||
|
||
% Set up MFVAR object with one lag and estimate coefficients | ||
mdl = MFVAR(Y, 1, accum); | ||
mdlE = mdl.estimate(); | ||
|
||
% Get daily interest rate changes | ||
alpha = mdlE.smooth(mdl.Y); | ||
|
||
|
||
%% Plot time series of interest rates | ||
% Make a plot of the spread using the daily mortgage rate and the weekly rate | ||
% where the weekly rate is the average of Mon-Wed rate placed on Tuesday. | ||
startInx = 9394; | ||
rateDisaggRS = alpha(:,2); | ||
rateDisaggNan = rateLevels(:,2); | ||
|
||
figure('Color', ones(1,3)); | ||
plot(dates(startInx:end), rateDisaggRS(startInx:end), 'LineWidth', 2); | ||
hold on; | ||
plot(dates(startInx:end), rateDisaggNan(startInx:end), 'x', 'MarkerSize', 10); | ||
box off; | ||
datetick('x', 'keeplimits') | ||
xlim([dates(startInx), dates(end)]); | ||
legend('Related series disaggregation', 'Observed data', ... | ||
'Location', 'sw', 'Orientation', 'vertical'); | ||
legend boxoff | ||
ylabel('Percent'); | ||
|
||
print 'pgmtmfss3_var_disagg.png' -dpng |
Oops, something went wrong.