The output gap from a published potential output, or by the Hodrick-Prescott, Hamilton, Baxter-King and Christiano-Fitzgerald filters, with the trend, the cycle and the latest gap.
light: A short numerical method; a hosted run may take up to 10 seconds.
Formula
Where
The output gap in period t gap
Actual output actual
Potential output potential
The Hodrick-Prescott trend trend
The series being filtered series
The smoothing parameter smoothing
Observations in a year frequency
Hamilton's horizon: how many periods ahead the series is projected horizon
Number of lags in Hamilton's regression lags
The cycle: the part of the series the projection misses cycle
The Baxter-King cycle cycle
Leads and lags the Baxter-King filter uses on each side lead_lag
The filter's weight on the observation j periods away
The ideal band-pass filter's weight, before the weights are made to sum to zero
The lower frequency of the band, from its longest period high
The upper frequency of the band, from its shortest period low
Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.
Variables
Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.
Inputs
The gap from a published potential output (from_potential): 4 inputs
Inputs of the calculation from_potential
Name
Unit
Bounds
Description
Formformtext
text
How the gap is stated: 'ratio' is output over trend less one; 'log' the difference of their logarithms
Calculationcalculationtext
text
The gap from a published potential output
Actualactualmoney (array) · length min 1, max 2000; each (0, 1e+15]
money (array)
length min 1, max 2000; each (0, 1e+15]
Real output each period, positive
Potentialpotentialmoney (array) · length min 1, max 2000; each (0, 1e+15]
money (array)
length min 1, max 2000; each (0, 1e+15]
Potential output each period, in the units of actual
The Hodrick-Prescott filter (hp): 5 inputs
Inputs of the calculation hp
Name
Unit
Bounds
Description
Formformtext
text
How the gap is stated: 'ratio' is output over trend less one; 'log' the difference of their logarithms
Seriesseriesmoney (array) · length min 3, max 2000; each (0, 1e+15]
money (array)
length min 3, max 2000; each (0, 1e+15]
Real output each period, positive; the filter runs on its log
Frequencyfrequencytext
text
How often the series is observed; it sets the filter's defaults
Calculationcalculationtext
text
The Hodrick-Prescott filter
Smoothingsmoothingratio · (0, 1e+08]
ratio
(0, 1e+08]
Lambda, the penalty on the trend's curvature; left out, 1,600 for quarterly data, 6.25 annual and 129,600 monthly (Ravn and Uhlig)
Trendtrendmoney (array) · length max 2000; each (0, 1e+18]
money (array)
length max 2000; each (0, 1e+18]
The trend (potential output) in each period the cycle covers, in the series' units
Cyclecyclerate (array) · length max 2000; each [-100, 1e+06]
rate (array)
length max 2000; each [-100, 1e+06]
The gap in each period, in the stated form
Gapgaprate · [-100, 1e+06]
rate
[-100, 1e+06]
The gap in the last period the cycle covers
Startstartcount · [0, 2000]
count
[0, 2000]
The position in the series (from 0) of the first period the trend and cycle cover
Calculationcalculationtext
text
Hamilton's (2018) regression filter
Horizonhorizoncount · [1, 100]
count
[1, 100]
The h it used
Lagslagscount · [1, 19]
count
[1, 19]
The p it used
The Baxter-King (1999) band-pass filter (baxter_king): 8 outputs
Outputs of the calculation baxter_king
Name
Unit
Bounds
Description
Trendtrendmoney (array) · length max 2000; each (0, 1e+18]
money (array)
length max 2000; each (0, 1e+18]
The trend (potential output) in each period the cycle covers, in the series' units
Cyclecyclerate (array) · length max 2000; each [-100, 1e+06]
rate (array)
length max 2000; each [-100, 1e+06]
The gap in each period, in the stated form
Gapgaprate · [-100, 1e+06]
rate
[-100, 1e+06]
The gap in the last period the cycle covers
Startstartcount · [0, 2000]
count
[0, 2000]
The position in the series (from 0) of the first period the trend and cycle cover
Calculationcalculationtext
text
The Baxter-King (1999) band-pass filter
Lowlowperiods · [2, 1000]
periods
[2, 1000]
The band's low end
Highhighperiods · [2, 1000]
periods
[2, 1000]
The band's high end
Lead laglead_lagcount · [1, 1000]
count
[1, 1000]
The K it used
The Christiano-Fitzgerald (2003) band-pass filter (christiano_fitzgerald): 7 outputs
Outputs of the calculation christiano_fitzgerald
Name
Unit
Bounds
Description
Trendtrendmoney (array) · length max 2000; each (0, 1e+18]
money (array)
length max 2000; each (0, 1e+18]
The trend (potential output) in each period the cycle covers, in the series' units
Cyclecyclerate (array) · length max 2000; each [-100, 1e+06]
rate (array)
length max 2000; each [-100, 1e+06]
The gap in each period, in the stated form
Gapgaprate · [-100, 1e+06]
rate
[-100, 1e+06]
The gap in the last period the cycle covers
Startstartcount · [0, 2000]
count
[0, 2000]
The position in the series (from 0) of the first period the trend and cycle cover
Calculationcalculationtext
text
The Christiano-Fitzgerald (2003) band-pass filter
Lowlowperiods · [2, 1000]
periods
[2, 1000]
The band's low end
Highhighperiods · [2, 1000]
periods
[2, 1000]
The band's high end
Calculator
Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.
Loading the calculator…
Worked example
Chain the gap into a policy rule: `gap = pyeconomics.run(pyeconomics.bind("macro.output_gap", calculation="hp", frequency="quarterly")).outputs.gap`, then `pyeconomics.run(pyeconomics.bind("macro.policy_rule", profile="us_output_gap", calculation="taylor_1993", output_gap=gap))`. The manifest records output_gap as user-supplied beside the rule's bound data.
The filters run on the natural log of output; the trend is reported in the series' units and the gap as a ratio (CBO's definition, the default) or a log difference.
Defaults follow the papers and scale with the frequency: lambda 1,600 quarterly (Ravn and Uhlig: 6.25 annual, 129,600 monthly); Hamilton's h of two years and p of one; a band of 1.5 to 8 years with K of three years (two to eight years for annual data). Each can be overridden.
The Christiano-Fitzgerald filter is the asymmetric random-walk form, on the series less the line from its first to its last value (as statsmodels' cffilter computes it).
Profiles: default binds 120 quarters of US real GDP and CBO's real potential GDP; ca, de, fr, gb, it and jp bind 40 years of the Penn World Table's real GDP (rgdpna) for a filter, with frequency='annual'.
Limitations
Potential output is not observed: the filters' trends are statistical and revised as data arrive, and the HP and Christiano-Fitzgerald trends are least reliable at the ends of the sample (Hamilton 2018).
Hamilton's cycle starts h + p - 1 periods into the series, and Baxter-King's starts K periods in and ends K periods early: its gap is the one K periods before the last observation, and it warns.
A series whose recent values are collinear (an exactly log-linear one) has no Hamilton regression, and a series that moves by factors no output series does leaves the trend or gap bounds: both raise DomainError.
Chain into macro.policy_rule by passing the gap as its output_gap override; the manifest records it as user-supplied, apart from a published gap.
In hosted mode, where FRED is refused, the originators serve too short a history for the default windows (BLS about three years, CBO's potential and natural rate from 2021), so the bind raises: supply the series instead.
Evidence
Status: standard. Textbook consensus, such as bond duration or the CAPM formula.
Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).
Syllabus
The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.
This model can read its data for you: each bound field names a data series, and the sources listed can fill it, in the order they are tried. This website reads only the sources whose terms let it serve their data (marked "hosted"); every source is available when you run pyeconomics on your own computer.
the last 40 observations on or before the date; real time: as published by the date
Penn World Table (hosted-safe; hosted)
Citations
Hodrick, R. J. and Prescott, E. C. (1997). Postwar U.S. Business Cycles: An Empirical Investigation. Journal of Money, Credit and Banking, 29(1), 1-16. doi:10.2307/2953682 (Section 2: the trend that minimizes the penalized sum of squares)
Ravn, M. O. and Uhlig, H. (2002). On Adjusting the Hodrick-Prescott Filter for the Frequency of Observations. Review of Economics and Statistics, 84(2), 371-376. doi:10.1162/003465302317411604 (Lambda scales with the fourth power of the observation frequency)
Hamilton, J. D. (2018). Why You Should Never Use the Hodrick-Prescott Filter. Review of Economics and Statistics, 100(5), 831-843. doi:10.1162/rest_a_00706 (Section 4: the regression of y(t+h) on y(t), ..., y(t-p+1))
Baxter, M. and King, R. G. (1999). Measuring Business Cycles: Approximate Band-Pass Filters for Economic Time Series. Review of Economics and Statistics, 81(4), 575-593. doi:10.1162/003465399558454 (The truncated ideal filter with weights summing to zero; K = 12)
Christiano, L. J. and Fitzgerald, T. J. (2003). The Band Pass Filter. International Economic Review, 44(2), 435-465. doi:10.1111/1468-2354.t01-1-00076 (The random-walk filter with end weights that sum the rest to zero)
Congressional Budget Office. Budget and Economic Data: Potential GDP and Underlying Inputs. https://www.cbo.gov/data/budget-economic-data (Quarterly real GDP, real potential GDP and the output gap)
Seabold, S. and Perktold, J. (2010). statsmodels: Econometric and statistical modeling with Python. Proceedings of the 9th Python in Science Conference, 92-96. doi:10.25080/Majora-92bf1922-011 (statsmodels.tsa.filters: hpfilter, bkfilter and cffilter (oracles))
Changelog
Version 1: First version.
Related models
Neutral rate of interestr* from the New York Fed's Laubach-Williams and Holston-Laubach-Williams estimates, the SEP's longer-run…
Monetary-policy rulesTaylor (1993 and 1999), balanced-approach, shortfalls, adjusted and first-difference rules, smoothed and…
Yield-curve recession probabilityThe New York Fed's probit of a US recession twelve months ahead from the spread of the 10-year Treasury…
Okun's lawOkun's law estimated in its gap form (the output gap on the unemployment gap) and its first-difference form…