IMF-辅助宏框架预测的Python包_概念和示例(英)-2025.8_19页_1015kb
报告摘要
Summary of "A Python Package to Assist Macroframework Forecasting: Concepts and Examples"
Core Content
This paper introduces macroframe-forecast, a Python package designed to assist in macroframework forecasting by systematically imposing constraints while maintaining smoothness in the forecasts. The package is particularly useful for economic forecasting where time series need to be adjusted to meet specific constraints and exhibit temporal smoothness, which is essential for consistency and accuracy.
The package follows a two-step approach:
- First-step forecast: Uses any forecasting model (e.g., machine learning or traditional econometric methods) to generate initial forecasts.
- Second-step reconciliation: Adjusts the first-step forecasts to satisfy constraints and ensure smoothness over time using quadratic programming.
Main Views
1. Importance of Constraints and Smoothness
- Forecasting economic time series often requires incorporating constraints to ensure internal consistency, such as accounting identities.
- Smoothness is important to reduce volatility in forecasts, making them more interpretable and aligned with expert expectations.
- The challenge lies in reconciling these two objectives without breaking the smoothness or violating constraints.
2. Advantages of the Package
- Model agnostic: Users can choose any forecasting model from the sktime library for the first step.
- User-friendly: The package provides a simple interface for applying constraints without requiring complex mathematical inputs.
- Flexibility: Users can fine-tune both the first-step forecasts and the reconciliation process, including custom constraints, smoothness parameters, and weight matrices.
- Simulation-based confidence intervals: Although the package currently supports only point forecasts, confidence intervals can be constructed using forecast errors from the first step.
3. Technical Implementation
- The MFF class is the primary tool for generating forecasts. It takes a dataframe with missing values and a list of constraints.
- The weight matrix $ W $ is estimated using the Oracle Shrinkage Approximating (OAS) method or the Oracle Approximating Estimator with Diagonal target (OASD). The default is OAS, which shrinks the sample covariance matrix towards the diagonal.
- The smoothness matrix $ \Phi $ is derived from the Hodrick-Prescott (HP) filter and is used to penalize forecast jumps over time.
- The smoothness parameters $ \lambda_i $ are normalized by the standard HP smoothness parameter $ \lambda_i^* $ and the forecast error variance $ \sigma_i^2 $.
Key Information
Constraints
- Constraints are specified as strings using the column names of the dataframe and time periods.
- Constraints can be either equality or inequality and can be applied to specific periods or across the entire forecast horizon.
Smoothness
- Smoothness is controlled by the parameter $ \lambda_i $, which determines how much the forecast should be adjusted to remove volatility.
- The default value of $ \lambda_i $ is calculated by minimizing the mean-squared forecast error from time-series cross validation.
- Users can override this with custom values or even set it to 0 to disable smoothing.
Weight Matrix
- The weight matrix $ W $ is used to measure the distance between the first-step forecast and the adjusted forecast.
- It is estimated using the sample covariance matrix of the forecast errors, and when the matrix is large, shrinkage methods like OAS or OASD are used to ensure invertibility.
Package Features
- Installation: The package can be installed via pip (
pip install macroframe-forecast) or from the GitHub repository. - Inputs:
df: A pandas dataframe with missing values (NaN) to be forecasted.equalityConstraints: A list of strings defining the equality constraints.inequalityConstraints: A list of strings defining the inequality constraints.parallelize: Boolean indicating whether parallel computing is used.n_forecast_error: Number of cross-validation splits used to estimate forecast error covariance.shrinkage_method: Method for shrinking the covariance matrix (OAS, OASD, identity, or monotone diagonal).
- Outputs:
df2: Final forecast dataframe with NaN replaced by forecasts that satisfy constraints.- Additional attributes like
df0,df1,df1_model,pred,true,model,C_eq,d_eq,C_ineq,d_ineq,W,Phi,shrinkage, andsmoothnessstore intermediate results and parameters.
Examples
1. Single Variable Example
- Data: US nominal GDP data from 1950 to 2024, with NaN values for 2025–2030.
- Constraint: The GDP growth rate for 2030 is constrained to 4%.
- Code:
m = MFF(df=df0, equalityConstraints=['GDP_2030 - 1.04 * GDP_2029']) m.fit() - Result: The final forecast
df2satisfies the constraint and is smoothed over time.
2. Multivariable Example
- Data: US fiscal variables (revenue, expenditure, interest payments, and primary balance) from the April 2025 WEO.
- Constraint: The primary balance is defined as revenue minus expenditure plus interest payments.
- Code:
m = MFF(df=df, equalityConstraints=['Primary Balance = Revenue - Expenditure + Interest Payments']) m.fit() - Result: The package ensures that the forecasts of these variables satisfy the accounting identity constraint and maintain smoothness over time.
Conclusion
The macroframe-forecast package fills a critical gap in the forecasting literature by enabling users to systematically impose constraints and smoothness in a unified framework. It provides a flexible, user-friendly, and robust solution for reconciling forecasts while maintaining their smoothness, which is particularly valuable for macroeconomic forecasting tasks. The package is compatible with various machine learning models and supports simulation-based confidence interval generation.
试读结束,高清完整版pdf/doc/ppt,请点下载