dfm-python 0.2.3__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dfm_python-0.2.3 → dfm_python-0.2.4}/CHANGELOG.md +34 -0
- dfm_python-0.2.4/Nowcasting/LICENSE +29 -0
- dfm_python-0.2.4/Nowcasting/README.md +24 -0
- dfm_python-0.2.4/Nowcasting/ResDFM.mat +0 -0
- dfm_python-0.2.4/Nowcasting/Spec_US_example.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-06-29.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-01.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-05.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-06.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-08.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-12.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-13.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-14.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-15.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-19.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-21.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-26.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-27.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-07-29.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-01.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-02.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-03.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-04.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-05.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-09.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-10.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-11.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-12.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-15.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-16.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-18.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-23.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-24.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-25.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-26.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-08-29.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-01.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-02.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-06.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-07.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-08.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-14.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-15.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-16.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-20.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-26.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-27.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-28.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-29.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-09-30.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-03.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-05.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-07.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-12.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-13.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-14.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-17.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-18.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-19.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-20.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-26.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-27.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-28.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-10-31.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-11-01.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-11-03.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-11-04.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-11-08.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-11-15.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-11-16.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-11-17.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-11-23.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-11-29.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-11-30.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-12-01.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-12-02.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-12-06.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-12-07.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-12-13.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-12-14.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-12-15.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-12-16.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-12-22.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2016-12-23.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/2017-01-27.xls +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/mat/2016-06-29.mat +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/mat/2016-12-07.mat +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/mat/2016-12-16.mat +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/mat/2016-12-23.mat +0 -0
- dfm_python-0.2.4/Nowcasting/data/US/mat/2017-01-27.mat +0 -0
- dfm_python-0.2.4/Nowcasting/data/yyyy-mm-dd.xls +0 -0
- dfm_python-0.2.4/Nowcasting/example_DFM.m +81 -0
- dfm_python-0.2.4/Nowcasting/example_Nowcast.m +50 -0
- dfm_python-0.2.4/Nowcasting/functions/dfm.m +1109 -0
- dfm_python-0.2.4/Nowcasting/functions/load_data.m +168 -0
- dfm_python-0.2.4/Nowcasting/functions/load_spec.m +94 -0
- dfm_python-0.2.4/Nowcasting/functions/remNaNs_spline.m +134 -0
- dfm_python-0.2.4/Nowcasting/functions/summarize.m +90 -0
- dfm_python-0.2.4/Nowcasting/functions/update_nowcast.m +651 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/PKG-INFO +58 -15
- {dfm_python-0.2.3 → dfm_python-0.2.4}/README.md +57 -14
- dfm_python-0.2.4/demo_korean.ipynb +123 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/pyproject.toml +1 -1
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/__init__.py +1 -1
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/config.py +7 -4
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/core/__init__.py +11 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/core/em.py +266 -108
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/core/numeric.py +302 -1
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/dfm.py +4 -2
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/kalman.py +46 -47
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/utils/data_utils.py +34 -1
- dfm_python-0.2.4/src/test/test_api.py +456 -0
- dfm_python-0.2.4/tutorial/basic_tutorial.py +460 -0
- dfm_python-0.2.4/tutorial/hydra_tutorial.py +252 -0
- dfm_python-0.2.3/src/test/test_api.py +0 -251
- dfm_python-0.2.3/tutorial/basic_tutorial.py +0 -236
- dfm_python-0.2.3/tutorial/hydra_tutorial.py +0 -255
- {dfm_python-0.2.3 → dfm_python-0.2.4}/.gitignore +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/.python-version +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/LICENSE +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/MANIFEST.in +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/config/blocks/default.yaml +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/config/default.yaml +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/config/series/default.yaml +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/data/sample_data.csv +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/data/sample_spec.csv +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/__init__.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/api.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/core/diagnostics.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/core/grouping.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/core/helpers.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/core/results.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/data_loader.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/news.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/utils/__init__.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/dfm_python/utils/aggregation.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/test/__init__.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/test/test_config.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/test/test_dfm.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/test/test_kalman.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/src/test/test_news.py +0 -0
- {dfm_python-0.2.3 → dfm_python-0.2.4}/uv.lock +0 -0
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.4] - 2025-01-XX
|
|
4
|
+
|
|
5
|
+
### Major Refactoring and Code Quality Improvements
|
|
6
|
+
|
|
7
|
+
This release includes extensive refactoring focused on code maintainability, robustness, and documentation.
|
|
8
|
+
|
|
9
|
+
#### Code Refactoring
|
|
10
|
+
- **Consolidated covariance/variance computation**: Created `_compute_covariance_safe()` and `_compute_variance_safe()` functions to eliminate code duplication (17 patterns → 3 functions)
|
|
11
|
+
- **Named constants**: Replaced 30+ magic numbers with named constants for better maintainability:
|
|
12
|
+
- `DEFAULT_AR_COEFFICIENT`, `DEFAULT_INNOVATION_VARIANCE`
|
|
13
|
+
- `MIN_INNOVATION_VARIANCE`, `MIN_OBSERVATION_VARIANCE`
|
|
14
|
+
- `DEFAULT_OBSERVATION_VARIANCE`, etc.
|
|
15
|
+
- **Improved naming**: Consistent variable naming throughout codebase (e.g., `res_block` → `block_residuals`, `resNaN` → `residuals_with_nan`)
|
|
16
|
+
- **Code deduplication**: Reduced code by ~80 lines through consolidation of repeated patterns
|
|
17
|
+
|
|
18
|
+
#### Documentation
|
|
19
|
+
- **Enhanced docstrings**: Comprehensive docstrings with examples for all major functions (`init_conditions`, `em_step`, `em_converged`)
|
|
20
|
+
- **Updated README**: Added "Code Quality" section highlighting refactoring improvements
|
|
21
|
+
- **Improved tutorials**: Enhanced `basic_tutorial.py` and `hydra_tutorial.py` with better explanations and examples
|
|
22
|
+
|
|
23
|
+
#### Robustness
|
|
24
|
+
- **Safe variance computation**: Automatic handling of edge cases (empty data, NaN values, numerical instability)
|
|
25
|
+
- **Safe covariance computation**: Robust error handling with automatic fallback strategies
|
|
26
|
+
- **Enhanced error messages**: More informative logging messages with context information
|
|
27
|
+
|
|
28
|
+
#### Testing
|
|
29
|
+
- All 38+ tests passing
|
|
30
|
+
- No linter errors
|
|
31
|
+
- Verified compatibility with existing functionality
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
- Internal refactoring: No breaking changes to public API
|
|
35
|
+
- Improved numerical stability through consolidated utility functions
|
|
36
|
+
|
|
3
37
|
## [0.2.3] - 2025-01-XX
|
|
4
38
|
|
|
5
39
|
### Changed
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018, Federal Reserve Bank of New York
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
* Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Nowcasting
|
|
2
|
+
|
|
3
|
+
This code implements the nowcasting framework described in "[Macroeconomic Nowcasting and Forecasting with Big Data](https://www.newyorkfed.org/research/staff_reports/sr830.html)" by Brandyn Bok, Daniele Caratelli, Domenico Giannone, Argia M. Sbordone, and Andrea Tambalotti, *Staff Reports 830*, Federal Reserve Bank of New York (prepared for Volume 10 of the *Annual Review of Economics*).
|
|
4
|
+
|
|
5
|
+
**Note:** These example files do not exactly reproduce the New York Fed Staff Nowcasting Report released every Friday because data redistribution restrictions prevent us from providing the complete data set used in our model.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Download instructions
|
|
9
|
+
|
|
10
|
+
Download the code as a ZIP file by clicking the green 'Clone or download' button and selecting 'Download ZIP'.
|
|
11
|
+
|
|
12
|
+
## File and folder description
|
|
13
|
+
|
|
14
|
+
* `data/` : example US data downloaded from [FRED](https://fred.stlouisfed.org/)
|
|
15
|
+
* `functions/` : functions for loading data, estimating model, and updating predictions
|
|
16
|
+
* `example_DFM.m` : example script to estimate a dynamic factor model (DFM) for a panel of monthly and quarterly series
|
|
17
|
+
* `example_Nowcast.m` : example script to produce a nowcast or forecast for a target variable, e.g., real GDP growth
|
|
18
|
+
* `ResDFM.mat` : example DFM estimation output
|
|
19
|
+
* `Spec_US_example.xls` : example model specification for the US
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## Required software and versioning
|
|
23
|
+
|
|
24
|
+
MATLAB is required to run the code. The code was tested in MATLAB R2015b and later versions. Functionality with earlier versions of MATLAB is not guaranteed.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
%%% Dynamic factor model (DFM) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
2
|
+
% This script estimates a dynamic factor model (DFM) using a panel of
|
|
3
|
+
% monthly and quarterly series.
|
|
4
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
%% Clear workspace and set paths.
|
|
8
|
+
close all; clear; clc;
|
|
9
|
+
addpath('functions');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
%% User inputs.
|
|
13
|
+
vintage = '2016-06-29'; % vintage dataset to use for estimation
|
|
14
|
+
country = 'US'; % United States macroeconomic data
|
|
15
|
+
sample_start = datenum('2000-01-01','yyyy-mm-dd'); % estimation sample
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
%% Load model specification and dataset.
|
|
19
|
+
% Load model specification structure `Spec`
|
|
20
|
+
Spec = load_spec('Spec_US_example.xls');
|
|
21
|
+
% Parse `Spec`
|
|
22
|
+
SeriesID = Spec.SeriesID; SeriesName = Spec.SeriesName; Units = Spec.Units; UnitsTransformed = Spec.UnitsTransformed;
|
|
23
|
+
% Load data
|
|
24
|
+
datafile = fullfile('data',country,[vintage '.xls']);
|
|
25
|
+
[X,Time,Z] = load_data(datafile,Spec,sample_start);
|
|
26
|
+
summarize(X,Time,Spec,vintage); % summarize data
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
%% Plot raw and transformed data.
|
|
30
|
+
% Industrial Production (INDPRO) <fred.stlouisfed.org/series/INDPRO>
|
|
31
|
+
idxSeries = strcmp('INDPRO',SeriesID); t_obs = ~isnan(X(:,idxSeries));
|
|
32
|
+
figure('Name',['Data - ' SeriesName{idxSeries}]);
|
|
33
|
+
|
|
34
|
+
subplot(2,1,1); box on;
|
|
35
|
+
plot(Time(t_obs),Z(t_obs,idxSeries)); title('raw observed data');
|
|
36
|
+
ylabel(Units{idxSeries}); xlim(Time([1 end])); datetick('x','yyyy','keeplimits');
|
|
37
|
+
|
|
38
|
+
subplot(2,1,2); box on;
|
|
39
|
+
plot(Time(t_obs),X(t_obs,idxSeries)); title('transformed data');
|
|
40
|
+
ylabel(UnitsTransformed{idxSeries}); xlim(Time([1 end])); datetick('x','yyyy','keeplimits');
|
|
41
|
+
pause(1); % to display plot
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
%% Run dynamic factor model (DFM) and save estimation output as 'ResDFM'.
|
|
45
|
+
threshold = 1e-4; % Set to 1e-5 for more robust estimates
|
|
46
|
+
|
|
47
|
+
Res = dfm(X,Spec,threshold);
|
|
48
|
+
save('ResDFM','Res','Spec');
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
%% Plot common factor and standardized data.
|
|
52
|
+
idxSeries = strcmp('INDPRO',SeriesID);
|
|
53
|
+
figure('Name','Common Factor and Standardized Data');
|
|
54
|
+
plot(Time,Res.x_sm,':'); hold on;
|
|
55
|
+
h = plot(Time,Res.Z(:,1)*Res.C(idxSeries,1),'k','LineWidth',1.5); box on;
|
|
56
|
+
xlim(Time([1 end])); datetick('x','yyyy','keeplimits');
|
|
57
|
+
legend(h,'common factor'); legend boxoff;
|
|
58
|
+
pause(5); % to display plot
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
%% Plot projection of common factor onto Payroll Employment and GDP.
|
|
62
|
+
idxSeries = strcmp('PAYEMS',SeriesID); t_obs = ~isnan(X(:,idxSeries));
|
|
63
|
+
figure('Name','Common Factor Projection');
|
|
64
|
+
|
|
65
|
+
subplot(2,1,1); % projection of common factor onto PAYEMS
|
|
66
|
+
CommonFactor = Res.C(idxSeries,1:5)*Res.Z(:,1:5)'*Res.Wx(idxSeries)+Res.Mx(idxSeries);
|
|
67
|
+
plot(Time,CommonFactor,'k'); hold on;
|
|
68
|
+
plot(Time(t_obs),X(t_obs,idxSeries),'b'); box on;
|
|
69
|
+
title(SeriesName{idxSeries}); xlim(Time([1 end])); datetick('x','yyyy','keeplimits');
|
|
70
|
+
ylabel({Units{idxSeries}, UnitsTransformed{idxSeries}});
|
|
71
|
+
legend('common component','data'); legend boxoff;
|
|
72
|
+
|
|
73
|
+
subplot(2,1,2); % projection of common factor onto GDPC1
|
|
74
|
+
idxSeries = strcmp('GDPC1',SeriesID); t_obs = ~isnan(X(:,idxSeries));
|
|
75
|
+
CommonFactor = Res.C(idxSeries,1:5)*Res.Z(:,1:5)'*Res.Wx(idxSeries)+Res.Mx(idxSeries);
|
|
76
|
+
plot(Time,CommonFactor,'k'); hold on;
|
|
77
|
+
plot(Time(t_obs), X(t_obs,idxSeries),'b'); box on;
|
|
78
|
+
title(SeriesName{idxSeries}); xlim(Time([1 end])); datetick('x','yyyy','keeplimits');
|
|
79
|
+
ylabel({Units{idxSeries},UnitsTransformed{idxSeries}});
|
|
80
|
+
legend('common component','data'); legend boxoff;
|
|
81
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
%%% Nowcasting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
2
|
+
% This script produces a nowcast of US real GDP growth for 2016:Q4
|
|
3
|
+
% using the estimated parameters from a dynamic factor model.
|
|
4
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
%% Clear workspace and set paths.
|
|
8
|
+
close all; clear; clc;
|
|
9
|
+
addpath('functions');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
%% User inputs.
|
|
13
|
+
series = 'GDPC1' ; % Nowcasting real GDP (GDPC1) <fred.stlouisfed.org/series/GDPC1>
|
|
14
|
+
period = '2016q4'; % Forecasting target quarter
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
%% Load model specification and first vintage of data.
|
|
18
|
+
% Load model specification structure `Spec`
|
|
19
|
+
Spec = load_spec('Spec_US_example.xls');
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
%% Load DFM estimation results structure `Res`.
|
|
23
|
+
Res = load('ResDFM'); % example_DFM.m used the first vintage of data for estimation
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
%% Update nowcast and decompose nowcast changes into news.
|
|
27
|
+
|
|
28
|
+
%%% Nowcast update from week of December 7 to week of December 16, 2016 %%%
|
|
29
|
+
vintage_old = '2016-12-16'; datafile_old = fullfile('data','US',[vintage_old '.xls']);
|
|
30
|
+
vintage_new = '2016-12-23'; datafile_new = fullfile('data','US',[vintage_new '.xls']);
|
|
31
|
+
% Load datasets for each vintage
|
|
32
|
+
[X_old,~ ] = load_data(datafile_old,Spec);
|
|
33
|
+
[X_new,Time] = load_data(datafile_new,Spec);
|
|
34
|
+
|
|
35
|
+
% check if spec used in estimation is consistent with the current spec
|
|
36
|
+
if isequal(Res.Spec,Spec)
|
|
37
|
+
Res = Res.Res;
|
|
38
|
+
else
|
|
39
|
+
threshold = 1e-4; % Set to 1e-5 for robust estimates
|
|
40
|
+
Res = dfm(X_new,Spec,threshold);
|
|
41
|
+
save('ResDFM','Res','Spec');
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
update_nowcast(X_old,X_new,Time,Spec,Res,series,period,vintage_old,vintage_new);
|
|
45
|
+
|
|
46
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|