Documentation for the Macroframework Forecasting package.

This repository contains the Python code for the forecasting method described in:

Systematizing Macroframework Forecasting: High-Dimensional Conditional Forecasting with Accounting Identities.

Smooth Forecast Reconciliation.

Installation

To install the macroframe-foreacst package, run the following from the repository root:

python -m pip install .

Alternatively, use the following command to install from PyPI.

python -m pip install macroframe-forecast

Quick start

The relevant import from macroframe-foreacst is MFF:

import numpy as np
import pandas as pd
from sktime.datasets import load_macroeconomic

from macroframe_forecast import MFF

df_true = load_macroeconomic().iloc[:, :5]

 # input dataframe
 df = df_true.copy()
 fh = 5
 df.iloc[-fh:, 0] = np.nan

 # apply MFF
 m = MFF(df, equality_constraints=[])
 df2 = m.fit()
 df0 = m.df0
 df1 = m.df1
 df1_model = m.df1_model
 smoothness = m.smoothness
 shrinkage = m.shrinkage

 # plot results
 t0 = -30
 ax = df0.iloc[t0:, 0].plot(label="df0")
 df1.iloc[t0:, 0].plot(ax=ax, label="df1")
 df2.iloc[t0:, 0].plot(ax=ax, label="df2")
 df_true.iloc[t0:, 0].plot(ax=ax, label="df_true")
 ax.axvline(x=df0.index[-fh])
 ax.legend()

 print("smoothness", smoothness.values)
 print("shrinkage", np.round(shrinkage, 3))
 for ri, ci in np.argwhere(df.isna()):
     print(df1_model.index[ri], df1_model.columns[ci], df1_model.iloc[ri, ci].best_params_)