Skip to content

Nowcast GDP

Estimate this quarter's GDP growth before the official figure, from monthly indicators that come out sooner: the data as they stood on a day, a dynamic factor model with a block structure, the nowcast with an interval around it, the news, how each new monthly figure moved the nowcast when the data were updated, and the news flow, the nowcast followed week by week through the quarter with each week's change split by indicator.

The news window: each new monthly figure between February and April, what the model expected, and its impact on the GDP nowcast.
The news between two nowcasts: each figure's surprise and its impact.

Before you start

  • Quarterly GDP and monthly indicators, each with its publication lag in days. This page uses the examples sample_macro (GDP, published 30 days after the quarter) and sample_monthly: industrial production (45 days), retail sales (15), employment (5) and a survey, the PMI (1 day).
  • Stationary series: annualised growth rates for GDP and the hard indicators, the survey as it is. The model is statsmodels' DynamicFactorMQ, which needs stationary inputs.
  • The day of the nowcast: 15 February 2025. GDP for 2024Q4 is out (30 January), so the quarter to nowcast is 2025Q1; retail sales, employment and the PMI are out for January, industrial production only for December.
  • The blocks: which series load on which factors. Here a global factor on every series, a real factor on the hard data and GDP, and a soft factor on the survey alone, after the New York Fed's model.

In the app, or in code

The dynamic factor model dialog: monthly series gr, gip, gemp and pmi from feb, the quarterly series gy, and the factor blocks Global, Real and Soft.
Estimate → Mixed frequency → Dynamic factor model (nowcasting)…, as in step 4.

Follow this step by step in the app

View → Guide → How do I → Nowcast GDP. The Guide panel takes you through these steps one at a time: Open… opens each step's dialog filled in, Show me runs it, and each step is ticked when its result is there. In the app's help, the page's Walk me through this opens it. The Guide is in the pymetrix-guide plugin, which is experimental (pip install --pre "pymetrix[guide]"; the walkthroughs come with its release after 0.1.0a1).

  1. File → Load example data…, with Example dataset: sample_macro and Save as: data; again with Example dataset: sample_monthly and Save as: monthly.
  2. Data → Derived series…, with Data: data, New series name: gy and Formula: 400*dlog(y) (GDP growth, annualised). Again with Data: monthly for the indicators' growth: New series name: gr, Formula: 1200*dlog(retail); New series name: gip, Formula: 1200*dlog(ip); New series name: gemp, Formula: 1200*dlog(emp).
  3. Estimate → Mixed frequency → Data as known on a day…, with On the day: 2025-02-15, Data: monthly and Save as: feb. Each value published after that day (its month's end plus its publication lag) is removed. Estimate → Mixed frequency → Ragged edge… shows where each series ends.
  4. Estimate → Mixed frequency → Dynamic factor model (nowcasting)…, with Monthly series: gr, gip, gemp, pmi, Monthly data: feb, Quarterly series: gy, Quarterly data: data, Factor blocks: Global: gr, gip, gemp, pmi, gy; Real: gr, gip, gemp, gy; Soft: pmi and Save as: dfm. Each block is a factor that loads on the series listed after it.
  5. In the model's window: Summary (the loadings, blank where a series is not in a block), Factors, and Nowcast: GDP growth for 2025Q1, its standard error and a 90% interval.
  6. Estimate → Mixed frequency → Data as known on a day…, with On the day: 2025-04-15, Data: monthly and Save as: apr: two more months of figures.
  7. In View → Immediate, type april = dfm.update(data, apr) and press Enter: the same model, its parameters unchanged, on the April data. Then type news = april.news(dfm, "gy"): the news window lists each new figure, what the model expected, and its impact on the nowcast; By series adds them up.
  8. Estimate → Mixed frequency → Track a nowcast…, with Nowcasting model: dfm, Series to nowcast: gy, Quarter: 2025Q1, Quarterly data: data, Monthly data: monthly, Days before the quarter's end: 90 and Save as: flow: the nowcast each week from 6 January until GDP for 2025Q1 is out. In its window, News flow draws the nowcast as steps over bars of each week's change by indicator, Waterfall steps from the first nowcast to the last with each indicator's total, and Contributions table gives the numbers, with the indicator that moved the nowcast most each week.
from pymetrix import Dataset, DynamicFactor

data = Dataset.example("sample_macro").derive(gy="400*dlog(y)")
monthly = Dataset.example("sample_monthly").derive(gr="1200*dlog(retail)", gip="1200*dlog(ip)", gemp="1200*dlog(emp)")
feb = monthly.as_of("2025-02-15")                 # the data as known on 15 February
feb.ragged_edge("2025-02-15")                     # ip ends in December, the others in January

blocks = {"gr": ["Global", "Real"], "gip": ["Global", "Real"], "gemp": ["Global", "Real"],
          "pmi": ["Global", "Soft"], "gy": ["Global", "Real"]}
dfm = DynamicFactor(monthly=["gr", "gip", "gemp", "pmi"], quarterly=["gy"], factors=blocks).fit(data, feb)
band = dfm.nowcast_density("gy")                  # 2025Q1: 8.19, standard error 3.01
band.to_frame()                                   # 90% interval 3.25 to 13.13
apr = monthly.as_of("2025-04-15")                 # two more months of figures
april = dfm.update(data, apr)                     # the same parameters, the new data
news = april.news(dfm, "gy")                      # 8.19 before, 3.85 after
news.by_series                                    # gr -1.78, gip -1.57, pmi -1.02, gemp +0.02
april.nowcast_density("gy")                       # standard error 2.66, interval -0.52 to 8.22

The news flow: the nowcast each week through the quarter, its changes split by indicator.

from pymetrix import nowcast_tracking

flow = nowcast_tracking(dfm, data, monthly, "gy", "2025Q1", days=(-90, 30))   # every 7 days from 6 January
flow.plot_news_flow()                             # the nowcast as steps over each week's news by indicator
flow.contributions_table()                        # by week; 3 March: the February PMI takes 2.24 off
flow.plot_waterfall()                             # 5.35 to 3.69: pmi -1.33, gip -1.31, gr +0.64, gemp +0.21, gy +0.13
flow.plot_news_flow(by="kind")                    # news, revisions and re-estimation apart (all news here)

Real-time data: the pandemic months masked, and the release dates behind as_of.

from pymetrix import ReleaseCalendar

masked = DynamicFactor(monthly=["gr", "gip", "gemp", "pmi"], quarterly=["gy"], factors=blocks,
                       mask={"2020-03": "2021-06"}).fit(data, feb)   # those months set to missing for estimation
masked.nowcast_density("gy")                      # 2025Q1: 8.13, standard error 3.00
len(masked.masked)                                # 70 values: 16 months of each indicator, 6 quarters of GDP

cal = ReleaseCalendar.from_lags(Dataset.example("sample_monthly"))   # or ReleaseCalendar.from_table("releases.csv")
cal.release_date("ip", "2025-01")                 # 17 March 2025: January's industrial production
raw = Dataset.example("sample_monthly").as_of("2025-02-15", calendar=cal)   # the same data as the fixed lags give

Growth at risk now: quantile regressions on the monthly indicators, and the skewed t through their quantiles.

from pymetrix import QuantileBridge, nowcast_backtest

qb = QuantileBridge("gy ~ gr + gip + pmi").fit(data, feb)   # quantile regressions at 5%, 25%, 50%, 75% and 95%
now = qb.nowcast_quantiles(data, feb)             # 2025Q1: 5% quantile 4.64, median 5.97, 95% quantile 8.40
risk = now.at_risk()                              # growth at risk 4.64, expected shortfall 4.17
bt = nowcast_backtest(QuantileBridge("gy ~ gr + gip + pmi"), data, monthly, "gy", ("2021Q3", "2024Q4"),
                      days=(-30, 0), step=30, reestimate="once")
bt.quantile_scores()                              # mean pinball loss 0.68 a month before the quarter ends, 0.45 at its end
bt.density_scores()                               # CRPS 1.48 and 1.02

Bottom up, as the Atlanta Fed's GDPNow does: each expenditure component nowcast by its own bridge equation, then added up with the previous quarter's nominal shares. The sample economy's GDP is consumption, investment and government spending (y = c + i + g), so its components make a small illustrative set, not a real GDPNow.

from pymetrix import Bridge, ComponentBridge, nowcast_tracking

comp = data.derive(gc="400*dlog(c)", gi="400*dlog(i)", gg="400*dlog(g)")   # GDP and its components
parts = {"gc": Bridge("gc ~ gr + gemp"), "gi": Bridge("gi ~ gip + pmi"), "gg": Bridge("gg ~ gemp")}
cb = ComponentBridge(parts, levels={"gc": "c", "gi": "i", "gg": "g"}, name="gy").fit(comp, feb)
known = comp.as_of("2025-02-15", lags={"gc": 60, "gi": 60, "gg": 60})   # the components come out with their levels
bottom = cb.nowcast_components(known, feb)        # 2024Q4: 7.54; 2025Q1: 7.14, standard error 2.44
bottom.contributions                              # 2025Q1: consumption 5.40, investment 0.45, government 1.29
bottom.plot()                                     # the contributions as stacked bars, GDP as a line
cbt = nowcast_backtest(ComponentBridge(parts, levels={"gc": "c", "gi": "i", "gg": "g"}, name="gy"), comp, monthly, "gy",
                       ("2021Q3", "2024Q4"), days=(-30, 0), step=30, reestimate="once")
cbt.component_scores()                            # RMSE 1.94 at the quarter's end: consumption 2.03, government 8.18
track = nowcast_tracking(cb, comp, monthly, "gy", "2024Q4", step=30)
track.by_group()                                  # consumption +1.89, investment +0.12, government +0.75

Check the result

  • The nowcast for 2025Q1 on 15 February is 8.19 (annualised growth), with a standard error of 3.01 and a 90% interval from 3.25 to 13.13. The standard error is statsmodels' own variance of the smoothed prediction (DynamicFactorMQ's get_prediction(...).var_pred_mean), and the interval is its conf_int(alpha=0.1).
  • The blocks: in the loadings, pmi has no Real loading and the hard data no Soft one. Fitted with statsmodels' DynamicFactorMQ directly, with factors=blocks and the data from February 2000 (the first month every indicator has data), the parameters are the same.
  • The news adds up: 3.85 - 8.19 = -4.34, the sum of the impacts (gr -1.78, gip -1.57, pmi -1.02, gemp +0.02) and of revised data (none here). Weaker retail sales and industrial production in February and March account for most of it.
  • The band narrows as the quarter's data come in: a standard error of 2.66 in April against 3.01 in February.
  • The news flow adds up: from 5.35 on 6 January to 3.69 on 28 April (-1.66), the PMI -1.33, industrial production -1.31, retail sales +0.64, employment +0.21 and GDP's own figure for 2024Q4 +0.13, the bars of each week adding up to that week's step. The largest move is the February PMI, in the data by 3 March: 4.28 points below what the model expected, with a weight of 0.52, it took 2.24 off. The nowcast of 17 February, 8.45, is not the 8.19 above: the tracking estimates the parameters once, on the data of its first day.
  • With the pandemic months masked (March 2020 to June 2021, 70 values set to missing), the nowcast is 8.13 with a standard error of 3.00: the same parameters as DynamicFactorMQ fitted on the data with those values set to NaN. A calendar built from the fixed lags gives exactly the data as_of gives without one.
  • Growth at risk on 15 February: the quantile regressions put 2025Q1's 5% quantile at 4.64, its median at 5.97 and its 95% quantile at 8.40; each quantile's coefficients are statsmodels' QuantReg on the quarterly averages of the indicators, and the months not yet out are forecast first by AR(2) models, as in a bridge equation. The skewed t (location 5.41, scale 1.27, shape 1.37, 6.93 degrees of freedom) passes through the 5%, 25%, 75% and 95% quantiles, so growth at risk is the 5% quantile, 4.64, and the expected shortfall below it 4.17. Its median, 6.21, is the skewed t's, not the regression's.
  • Over the 14 quarters from 2021Q3, a month before each quarter ends and at its end, the mean pinball loss falls from 0.68 to 0.45 and the CRPS from 1.48 to 1.02, as the quarter's figures come in; 7% of the outturns fell below the 5% quantile at the quarter's end.

  • Bottom up, on 15 February: consumption's bridge equation nowcasts 2025Q1 at 7.01, investment's at 4.27 and government's at 10.38; with the shares of 2024Q4 (0.77, 0.11 and 0.12, its levels rolled forward from 2024Q3 by the 2024Q4 nowcasts, since the components for 2024Q4 are not out until March) GDP grows 7.14, the shares times the components' growth. Each component's nowcast is its bridge equation's alone. The standard error, 2.44 (90% interval 3.13 to 11.16), combines the components' own with the correlation of their equations' residuals (-0.29 between consumption and investment). 2024Q4's 7.54 compares with GDP's published 7.24. Chained (Fisher) aggregation (aggregation="chained") gives 7.14 too: without deflators it differs from the shares only by the log growth rates' second-order term, 0.003 points.

  • Over the same 14 quarters the component bridge's RMSE falls from 2.85 a month before each quarter ends to 1.94 at its end (0.53 of the AR(1)'s); tracking 2024Q4 from July, its nowcast rises from 3.40 to 6.17 by 31 December, of which consumption +1.89, investment +0.12 and government +0.75, the parts adding up to each day's change.

Pitfalls

  • The band leaves out the parameters' uncertainty. It is the uncertainty of the factors given the data and the estimated model; the estimation error of the loadings and the VAR is not in it. Out of sample the nowcast errs by more: check the band's coverage over past quarters before quoting it.
  • One nowcast is not a record. How good the model is shows only over many quarters, made each time with the data known on the day: nowcast_backtest (Estimate → Mixed frequency → Nowcast backtest by release day…) scores the model by days from the quarter's end against a benchmark, and nowcast_tracking (Track a nowcast…) follows one quarter's nowcast with the news of each release.
  • Not every change is news. With the parameters re-estimated during the quarter (Re-estimate: once a quarter or each day) or earlier figures revised, part of a week's change is re-estimation or revisions, drawn apart (plot_news_flow(by="kind"), News flow by kind); estimate once to read every change as the news of a figure.
  • Values are removed, not revised. as_of drops what was not yet published; it does not restore earlier vintages. With a FRED API key, read_vintages("GDPC1") reads every ALFRED vintage of GDP, revision_analysis shows how its figures were revised (news or noise), and nowcast_backtest(..., vintages={"y": gdp}) uses on each day the vintage published by then: a real-time evaluation, usually with larger errors.
  • Fixed lags misdate releases. Offices publish on set weekdays and move around holidays: give the actual dates as a ReleaseCalendar (calendar= in as_of, the backtest and tracking), which also groups series published together so news adds up by release.
  • The pandemic months dominate the estimates. Mask them (mask=, or Masked periods under Advanced settings in the dialog) or set outliers to missing (outliers=10, ten interquartile ranges from the median).
  • The sample starts when every monthly series has data. A series with a short history cuts everyone's. Tick Keep each series' full history (under Advanced settings) to start with the earliest series instead, the months before the others start treated as missing.
  • Growth rates, not levels. The quarterly series enters as the average of the monthly factors' growth (Mariano and Murasawa), so give growth rates of the same kind on both sides, annualised alike.
  • Components must add up to the aggregate. A component bridge weights the components by their nominal shares, so they must exhaust GDP (give imports with a negative level), and each component's series must be published on its own schedule: give the growth rates the publication lag of their levels (lags= in as_of), as the backtest and tracking do by themselves.
  • A 5% quantile rests on few quarters. With a hundred quarters, about five lie below it: its coefficients are imprecise and its coverage in a backtest of 14 quarters says little. Read growth at risk with the density's spread, and score it by the pinball loss and the CRPS over as many quarters as there are.

See also