Type: | Package |
Title: | An Alternative to the Hodrick-Prescott Filter |
Version: | 0.5-0 |
Description: | In the working paper titled "Why You Should Never Use the Hodrick-Prescott Filter", James D. Hamilton proposes a new alternative to economic time series filtering. The neverhpfilter package provides functions and data for reproducing his work. Hamilton (2017) <doi:10.3386/w23429>. |
Depends: | R (≥ 3.5.0), xts (≥ 0.11-0), zoo (≥ 1.8-0) |
License: | GPL-3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
Suggests: | simplermarkdown, tinytest |
VignetteBuilder: | simplermarkdown |
URL: | https://justinmshea.github.io/neverhpfilter/ |
BugReports: | https://github.com/JustinMShea/neverhpfilter/issues |
NeedsCompilation: | no |
Packaged: | 2025-08-21 13:09:06 UTC; impartial-spec |
Author: | Justin M. Shea [aut, cre] |
Maintainer: | Justin M. Shea <jshea01@uic.edu> |
Repository: | CRAN |
Date/Publication: | 2025-08-21 13:40:02 UTC |
Real Exports of Goods and Services
Description
EXPGSC1
Real Exports of Goods and Services
Usage
data(EXPGSC1)
Format
An xts
object of Real Exports of Goods and Services.
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2017 Dollars
Date Range: 1947-01-01 to 2025-04-01
Notes
BEA Account Code: A020RX
A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
Source
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/EXPGSC1
Examples
data(EXPGSC1)
tail(EXPGSC1)
plot(EXPGSC1,grid.col = "white", col="blue")
Effective Federal Funds Rate
Description
FEDFUNDS
All Employees: Total Nonfarm
Usage
data(FEDFUNDS)
Format
An xts
object of the Fed Funds figures.
Release: H.15 Selected Interest Rates
Seasonal Adjustment: Not Seasonally Adjusted
Frequency: Monthly
Units: Percent
Date Range: 1954-07-01 to 2025-07-01
Notes
Averages of daily figures.
The federal funds rate is the interest rate at which depository institutions trade federal funds (balances held at Federal Reserve Banks) with each other overnight. When a depository institution has surplus balances in its reserve account, it lends to other banks in need of larger balances. In simpler terms, a bank with excess cash, which is often referred to as liquidity, will lend to another bank that needs to quickly raise liquidity. (1) The rate that the borrowing institution pays to the lending institution is determined between the two banks; the weighted average rate for all of these types of negotiations is called the effective federal funds rate.(2) The effective federal funds rate is essentially determined by the market but is influenced by the Federal Reserve through open market operations to reach the federal funds rate target.(2) The Federal Open Market Committee (FOMC) meets eight times a year to determine the federal funds target rate. As previously stated, this rate influences the effective federal funds rate through open market operations or by buying and selling of government bonds (government debt). (2) More specifically, the Federal Reserve decreases liquidity by selling government bonds, thereby raising the federal funds rate because banks have less liquidity to trade with other banks. Similarly, the Federal Reserve can increase liquidity by buying government bonds, decreasing the federal funds rate because banks have excess liquidity for trade. Whether the Federal Reserve wants to buy or sell bonds depends on the state of the economy. If the FOMC believes the economy is growing too fast and inflation pressures are inconsistent with the dual mandate of the Federal Reserve, the Committee may set a higher federal funds rate target to temper economic activity. In the opposing scenario, the FOMC may set a lower federal funds rate target to spur greater economic activity. Therefore, the FOMC must observe the current state of the economy to determine the best course of monetary policy that will maximize economic growth while adhering to the dual mandate set forth by Congress. In making its monetary policy decisions, the FOMC considers a wealth of economic data, such as: trends in prices and wages, employment, consumer spending and income, business investments, and foreign exchange markets.
The federal funds rate is the central interest rate in the U.S. financial market. It influences other interest rates such as the prime rate, which is the rate banks charge their customers with higher credit ratings. Additionally, the federal funds rate indirectly influences longer- term interest rates such as mortgages, loans, and savings, all of which are very important to consumer wealth and confidence.(2)
References (1) Federal Reserve Bank of New York. “Federal funds.” Fedpoints, August 2007. (2) Board of Governors of the Federal Reserve System. “Monetary Policy”. http://www.federalreserve.gov/monetarypolicy/default.htm.
Source
Board of Governors of the Federal Reserve System (US) https://fred.stlouisfed.org/data/FEDFUNDS
Examples
data(FEDFUNDS)
tail(FEDFUNDS)
plot(FEDFUNDS, grid.col = "white", col="green")
Real Government Consumption Expenditures and Gross Investment
Description
GCEC1
Real Government Consumption Expenditures and Gross Investment
Usage
data(GCEC1)
Format
An xts
object containing observations of Real Exports of Goods and Services.
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2017 Dollars
Date Range: 1947-01-01 to 2025-04-01
Notes
BEA Account Code: A822RX
A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
Source
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GCEC1
Examples
data(GCEC1)
tail(GCEC1)
plot(GCEC1, grid.col = "white", col="blue")
Gross Domestic Product
Description
GDPC1
Real Gross Domestic Product
Usage
data(GDPC1)
Format
An xts
object of Real Gross Domestic Product.
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2017 Dollars
Date Range: 1947-01-01 to 2025-04-01
Notes
Real gross domestic product is the inflation adjusted value of the goods and services produced by labor and property located in the United States.
For more information see the Guide to the National Income and Product Accounts of the United States (NIPA) - https://www.bea.gov/resources/methodologies/nipa-handbook.
BEA Account Code: A191RX
Source
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GDPC1
Examples
data(GDPC1)
log_RGDP <- 100*log(GDPC1)
gdp_cycle <- yth_filter(log_RGDP, h = 8, p = 4, output = c("cycle", "random"), family = gaussian)
main <- "Log of Real GDP cycle and random walk"
plot(gdp_cycle, grid.col = "white", legend.loc = "topright", main = main)
Gross Domestic Product: Implicit Price Deflator
Description
GDPDEF
Gross Domestic Product: Implicit Price Deflator
Usage
data(GDPDEF)
Format
An xts
object containing quarterly observations of the
Gross Domestic Product: Implicit Price Deflator.
- **Release:**
Gross Domestic Product
- **Seasonal Adjustment:**
Seasonally Adjusted Annual Rate
- **Frequency:**
Quarterly
- **Units:**
Index 2017 = 100
- **Date Range:**
1947-01-01 to 2025-04-01
Notes
BEA Account Code: A191RD
The number of decimal places reported varies over time. A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
Source
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GDPDEF
Examples
data(GDPDEF)
head(GDPDEF)
tail(GDPDEF)
plot(GDPDEF, col = "blue")
Real Gross Private Domestic Investment
Description
GPDIC1
Real Gross Private Domestic Investment
Usage
data(GPDIC1)
Format
An xts
object containing quarterly observations of
Real Gross Private Domestic Investment.
- **Release:**
Gross Domestic Product
- **Seasonal Adjustment:**
Seasonally Adjusted Annual Rate
- **Frequency:**
Quarterly
- **Units:**
Billions of Chained 2017 Dollars
- **Date Range:**
1947-01-01 to 2025-04-01
Notes
BEA Account Code: A006RX
A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
Source
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GPDIC1
Examples
data(GPDIC1)
tail(GPDIC1)
plot(GPDIC1, grid.col = "white", col = "blue")
10-Year Treasury Constant Maturity Rate
Description
GS10
10-Year Treasury Constant Maturity Rate
Usage
data(GS10)
Format
An xts
object containing observations of the
10-Year Treasury Constant Maturity Rate.
- **Release:**
H.15 Selected Interest Rates
- **Seasonal Adjustment:**
Not Seasonally Adjusted
- **Frequency:**
Monthly
- **Units:**
Percent
- **Date Range:**
1953-04-01 to 2025-07-01
Notes
Averages of business days.
For further information regarding treasury constant maturity data, please refer to: - http://www.federalreserve.gov/releases/h15/current/h15.pdf - http://www.treasury.gov/resource-center/data-chart-center/interest-rates/Pages/yieldmethod.aspx
Source
Board of Governors of the Federal Reserve System (US) https://fred.stlouisfed.org/data/GS10
Examples
data(GS10)
tail(GS10)
plot(GS10, grid.col = "white", col = "green")
Hamilton_table_2
Description
Standard deviation of cyclical component and correlation with cyclical component of GDP for assorted macroeconomic series.
Usage
data("Hamilton_table_2")
Format
A data.frame
containing 13 economic time series observations
of 5 variables:
- **cycle.sd:**
Standard deviation of the cycle component, computed with function
yth_filter(x, output = "cycle")
.- **gdp.cor:**
Correlation of
cycle.sd
with the cycle.sd of100 * log(RealGDP)
.- **random.sd:**
Standard deviation of a random walk, computed by rolling differencing the series by period
h
, the sameh
passed toyth_filter(x, output = "cycle")
to computecycle.sd
.- **gdp.rand.cor:**
Correlation of
random.sd
with the random.sd of100 * log(RealGDP)
.
Notes
Filtered series were based on the full sample available for that variable, while correlations were calculated using the subsample of overlapping values for the two indicators. Note that the regression residuals lose the first 11 observations and the random-walk calculations lose the first 8 observations.
Source
Hamilton, James D. (2018). *Why You Should Never Use the Hodrick-Prescott Filter*, pg. 40. http://econweb.ucsd.edu/~jhamilto/hp.pdf
Examples
print(Hamilton_table_2)
Real Imports of Goods and Services
Description
IMPGSC1
Real Imports of Goods and Services
Usage
data(IMPGSC1)
Format
An xts
object containing quarterly observations of
Real Imports of Goods and Services.
- **Release:**
Gross Domestic Product
- **Seasonal Adjustment:**
Seasonally Adjusted Annual Rate
- **Frequency:**
Quarterly
- **Units:**
Billions of Chained 2017 Dollars
- **Date Range:**
1947-01-01 to 2025-04-01
Notes
BEA Account Code: A021RX
A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
Source
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/IMPGSC1
Examples
data(IMPGSC1)
tail(IMPGSC1)
plot(IMPGSC1, grid.col = "white", col = "blue")
Employment Situation
Description
PAYEMS
All Employees: Total Nonfarm
Usage
data(PAYEMS)
Format
An xts
object containing observations of
All Employees: Total Nonfarm.
- **Release:**
Employment Situation
- **Seasonal Adjustment:**
Seasonally Adjusted
- **Frequency:**
Monthly
- **Units:**
Thousands of Persons
- **Date Range:**
1939-01-01 to 2025-07-01
Notes
All Employees: Total Nonfarm, commonly known as Total Nonfarm Payroll, is a measure of the number of U.S. workers in the economy that excludes proprietors, private household employees, unpaid volunteers, farm employees, and the unincorporated self-employed. This measure accounts for approximately 80 percent of the workers who contribute to Gross Domestic Product (GDP).
This measure provides useful insights into the current economic situation because it can represent the number of jobs added or lost in an economy. Increases in employment might indicate that businesses are hiring which might also suggest that businesses are growing. Additionally, those who are newly employed have increased their personal incomes, which means (all else constant) their disposable incomes have also increased, thus fostering further economic expansion.
Generally, the U.S. labor force and levels of employment and unemployment are subject to fluctuations due to seasonal changes in weather, major holidays, and the opening and closing of schools. The Bureau of Labor Statistics (BLS) adjusts the data to offset the seasonal effects to show non-seasonal changes: for example, women's participation in the labor force; or a general decline in the number of employees, a possible indication of a downturn in the economy. To closely examine seasonal and non-seasonal changes, the BLS releases two monthly statistical measures: the seasonally adjusted All Employees: Total Nonfarm (PAYEMS) and All Employees: Total Nonfarm (PAYNSA), which is not seasonally adjusted.
The series comes from the 'Current Employment Statistics (Establishment Survey).
The source code is: CES0000000001
Source
U.S. Bureau of Labor Statistics https://fred.stlouisfed.org/data/PAYEMS
Examples
data(PAYEMS)
tail(PAYEMS)
PAYEMS_qtr <- xts::to.quarterly(PAYEMS["1947/"], OHLC = FALSE)
log_Employment <- 100*log(PAYEMS_qtr)
employ_trend <- yth_filter(log_Employment, h = 8, p = 4,
output = c("x", "trend"), family = gaussian)
main <- "Log of Employment and trend"
plot(employ_trend, grid.col = "white", legend.loc = "topleft", main = main)
employ_cycle <- yth_filter(log_Employment, h = 8, p = 4,
output = c("cycle", "random"), family = gaussian)
main <- "Log of Employment cycle and random walk"
plot(employ_cycle, grid.col = "white", legend.loc = "topright", main = main)
Real Personal Consumption Expenditures
Description
PCECC96
Real Personal Consumption Expenditures
Usage
data(PCECC96)
Format
An xts
object containing quarterly observations of
Real Personal Consumption Expenditures.
- **Release:**
Gross Domestic Product
- **Seasonal Adjustment:**
Seasonally Adjusted Annual Rate
- **Frequency:**
Quarterly
- **Units:**
Billions of Chained 2017 Dollars
- **Date Range:**
1947-01-01 to 2025-04-01
Notes
BEA Account Code: DPCERX
A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
Source
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/PCECC96
Examples
data(PCECC96)
tail(PCECC96)
plot(PCECC96, grid.col = "white", col = "blue")
U.S. Stock Markets and CAPE Ratio
Description
SP500
Robert Shiller's data set for U.S. Stock Markets 1871–2021 and CAPE Ratio.
Usage
data(SP500)
Format
An xts
object containing observations of U.S. Stock Markets
1871–Present and CAPE Ratio.
- **Frequency:**
Monthly
- **Date Range:**
1871-01 to 2023-09
- **SP500:**
Nominal prices of the S&P composite index, April 2021 observation is 04/05 close
- **Dividends:**
Nominal dividends
- **Earnings:**
Nominal earnings, S&P 500 estimated
- **CPI:**
Shiller's Consumer Price Index data used for transformation to real prices
- **GS10:**
Shiller's Long-term interest rate, 10-Year Treasury Constant Maturity Rate, April 2021 observation is 04/05 close
- **Real_SP500:**
Real prices of the S&P 500 composite index
- **Real_Dividends:**
Real dividends
- **Real_SP500_TR:**
Real total return price of the S&P 500 composite index
- **Real_Earnings:**
Real earnings
- **Real_Earnings_TR:**
Real total return scaled earnings
- **CAPE:**
Cyclically Adjusted Price Earnings Ratio (P/E10 or CAPE)
- **CAPE_TR:**
Cyclically Adjusted Total Return Price Earnings Ratio (P/E10_TR or CAPE_TR)
- **CAPE_Yield:**
Excess CAPE Yield
- **Bond_TR:**
Total bond returns
- **Real_Bond_TR:**
Real total bond returns
Notes from Shiller
This data set consists of monthly stock price, dividends, and earnings data and the consumer price index (to allow conversion to real values), all starting January 1871. The price, dividend, and earnings series are from the same sources as described in Chapter 26 of my earlier book (Market Volatility, Cambridge, MA: MIT Press, 1989), although now I use monthly data, rather than annual data.
Monthly dividend and earnings data are computed from the S&P four-quarter totals for the quarter since 1926, with linear interpolation to monthly figures. Dividend and earnings data before 1926 are from Cowles and associates (Common Stock Indexes, 2nd ed., Bloomington, Ind.: Principia Press, 1939), interpolated from annual data. Stock price data are monthly averages of daily closing prices.
The CPI-U (Consumer Price Index–All Urban Consumers) published by the U.S. Bureau of Labor Statistics begins in 1913; for years before 1913, Shiller spliced Warren and Pearson's price index by multiplying it by the ratio of the indexes in January 1913. December 1999 and January 2000 values for the CPI-U are extrapolated. See George F. Warren and Frank A. Pearson, *Gold and Prices* (New York: John Wiley and Sons, 1935). Data are from their Table 1, pp. 11–14.
Source
Shiller, Robert J. *Irrational Exuberance*, Princeton University Press 2000, Broadway Books 2001, 2nd ed. 2005, 3rd ed. 2015. http://www.econ.yale.edu/~shiller/data.htm
Download .xls file directly from here: http://www.econ.yale.edu/~shiller/data/ie_data.xls
Examples
data(SP500)
SP500_qtr <- xts::to.quarterly(SP500$SP500, OHLC = FALSE)
log_SP500 <- 100*log(SP500_qtr)
SP500_trend <- yth_filter(log_SP500, h = 8, p = 4,
output = c("x", "trend"), family = gaussian)
main <- "Log of SP500 and trend"
plot(SP500_trend, grid.col = "white", legend.loc = "topleft", main = main)
SP500_cycle <- yth_filter(log_SP500["1900/"], h = 8, p = 4,
output = c("cycle", "random"), family = gaussian)
main <- "Log of SP500 cycle and random walk"
plot(SP500_cycle, grid.col = "white", legend.loc = "topright", main = main)
Civilian Unemployment Rate
Description
UNRATENSA
Civilian Unemployment Rate
Usage
data(UNRATENSA)
Format
An xts
object containing monthly observations of the
Civilian Unemployment Rate.
- **Release:**
Employment Situation
- **Seasonal Adjustment:**
Not Seasonally Adjusted
- **Frequency:**
Monthly
- **Units:**
Percent
- **Date Range:**
1948-01-01 to 2025-07-01
Notes
The unemployment rate represents the number of unemployed as a percentage of the labor force. Labor force data are restricted to people 16 years of age and older, who currently reside in one of the 50 states or the District of Columbia, who do not reside in institutions (e.g., penal and mental facilities, homes for the aged), and who are not on active duty in the Armed Forces.
This rate is also defined as the U-3 measure of labor underutilization.
The series comes from the 'Current Population Survey (Household Survey)'.
The source code is: LNU04000000
Source
U.S. Bureau of Labor Statistics https://fred.stlouisfed.org/data/UNRATENSA
Examples
data(UNRATENSA)
tail(UNRATENSA)
plot(UNRATENSA, grid.col = "white", col = "green")
Recession Indicators Series
Description
USREC
NBER based Recession Indicators for the United States from the
period following the peak through the trough.
Usage
data(USREC)
Format
An xts
object containing monthly observations of
NBER-based Recession Indicators.
- **Release:**
Recession Indicators Series (Not a press release)
- **Seasonal Adjustment:**
Not Seasonally Adjusted
- **Frequency:**
Monthly
- **Units:**
Binary indicator (1 = recession, 0 = expansion)
- **Date Range:**
1854-12-01 to 2025-07-01
Notes
This time series is an interpretation of U.S. Business Cycle Expansions and Contractions data provided by The National Bureau of Economic Research (NBER) at http://www.nber.org/cycles/cyclesmain.html.
The series is composed of dummy variables that represent periods of expansion and recession. A value of 1 indicates a recessionary period, while a value of 0 indicates an expansionary period.
The NBER identifies months and quarters of turning points without designating an exact date within the period that turning points occurred. For this time series, the recession begins the first day of the period following a peak and ends on the last day of the period of the trough.
Three methods of interpretation are used for converting peak/trough dates into shaded recession data:
Midpoint method — recession spans midpoints of peak and trough.
Trough method — recession spans from period following the peak through the trough (used for this series and in FRED).
Peak method — recession spans from peak through the period preceding the trough.
Source
Federal Reserve Bank of St. Louis https://fred.stlouisfed.org/data/USREC
Examples
data(USREC)
USREC["2007/2009"]
plot(USREC["1947/"], grid.col = "white", col = "red")
Filtered xts object
Description
yth_filter
returns an xts
object containing
user-defined combinations of the original, trend, cycle, and random walk series.
Usage
yth_filter(x, h = 8, p = 4, output = c("x", "trend", "cycle", "random"), ...)
Arguments
x |
A univariate |
h |
An |
p |
An |
output |
A |
... |
Other arguments passed to |
Details
For time series of quarterly periodicity, Hamilton suggests parameters of
h = 8 and p = 4, or an AR(4)
process, additionally lagged by 8
lookahead periods. Econometricians may explore variations of h. However, p
is designed to correspond with the seasonality of a given periodicity and
should be matched accordingly.
Value
An xts
object defined by the output
parameter.
References
James D. Hamilton. Why You Should Never Use the Hodrick-Prescott Filter. NBER Working Paper No. 23429, Issued in May 2017.
See Also
Examples
data(GDPC1)
gdp_filter <- yth_filter(100*log(GDPC1), h = 8, p = 4)
head(gdp_filter, 15)
#---------------------------------------------------------------------------#
data(PAYEMS)
log_Employment <- 100*log(xts::to.quarterly(PAYEMS["1947/2016-6"], OHLC = FALSE))
employ_trend <- yth_filter(log_Employment, h = 8, p = 4, output = c("x", "trend"))
plot(employ_trend, grid.col = "white", legend.loc = "topleft",
main = "Log of Employment and trend")
#----------------------------------------------------------------------------#
quarterly_data <- 100*log(merge(GDPC1, PCECC96, GPDIC1, EXPGSC1, IMPGSC1, GCEC1, GDPDEF))
cycle <- do.call(merge, lapply(quarterly_data, yth_filter, output = "cycle"))
random <- do.call(merge, lapply(quarterly_data, yth_filter, output = "random"))
cycle.sd <- t(data.frame(lapply(cycle, sd, na.rm = TRUE)))
GDP.cor <- t(data.frame(lapply(cycle, cor, cycle[,1], use = "complete.obs")))
random.sd <- t(data.frame(lapply(random, sd, na.rm = TRUE)))
random.cor <- t(data.frame(lapply(random, cor, random[,1], use = "complete.obs")))
my_table_2 <- round(data.frame(cbind(cycle.sd, GDP.cor, random.sd, random.cor)), 2)
names(my_table_2) <- names(Hamilton_table_2)[1:4]
my_table_2
Fits Hamilton's alternative model
Description
yth_glm
fits a generalized linear model suggested by James D. Hamilton
as a better alternative to the Hodrick-Prescott Filter.
Usage
yth_glm(x, h = 8, p = 4, ...)
Arguments
x |
A univariate |
h |
An |
p |
An |
... |
Additional arguments passed to |
Details
For time series of quarterly periodicity, Hamilton suggests parameters of
h = 8 and p = 4, or an AR(4)
process, additionally lagged by 8
lookahead periods. Econometricians may explore variations of h. However, p is
designed to correspond with the seasonality of a given periodicity and should
be matched accordingly.
Value
yth_glm
returns a generalized linear model object of class
glm
, which inherits from lm
.
References
James D. Hamilton. Why You Should Never Use the Hodrick-Prescott Filter. NBER Working Paper No. 23429, Issued in May 2017.
See Also
Examples
data(GDPC1)
gdp_model <- yth_glm(GDPC1, h = 8, p = 4, family = gaussian)
summary(gdp_model)
plot(gdp_model)