Assumed Question
Given quarterly data:
- interpolate weekly data points
- then predict future weekly periods
Examples in R, because I absolutely love R.
Part 1. Interpolate Weekly Data Points
Example quarterly dataset from Fed:
require(tidyverse)
require(lubridate)
require(timeSeries)
require(xts)
require(tsbox)
gdp_data<-
tribble(
~DATE, ~GDPC1,
20180101, 18438.254,
20180401, 18598.135,
20180701, 18732.72,
20181001, 18783.548,
20190101, 18927.281,
20190401, 19021.86,
) %>%
mutate(DATE = ymd(alignQuarterly(ymd(DATE)))) %>%
ts_xts()
Resulting xts object:
> gdp_data
GDPC1
2018-03-30 18438.25
2018-06-29 18598.13
2018-09-29 18732.72
2018-12-31 18783.55
2019-03-30 18927.28
2019-06-29 19021.86
Quarter-end periods to Week-end periods by Spline Interpolation
# create weekly time periods
weekly_dates<-
gdp_data %>%
index() %>%
alignQuarterly() %>%
align(by = "w") %>%
ymd() %>%
as.xts()
# approximate values for each week
interpolated_data<-
weekly_dates %>%
merge(gdp_data) %>%
na.spline() %>%
merge(weekly_dates, join = 'right')
Resulting xts object:
> interpolated_data %>% tail(10)
GDPC1
2019-04-26 18969.86
2019-05-03 18979.35
2019-05-10 18988.07
2019-05-17 18995.95
2019-05-24 19002.92
2019-05-31 19008.91
2019-06-07 19013.87
2019-06-14 19017.70
2019-06-21 19020.36
2019-06-28 19021.77
To review output as graph:
interpolated_data %>% plot()
Part 2. Predict Future Weekly Periods
Example Exponential State-space Model
require(forecast)
projection<-
interpolated_data %>%
ts_ts() %>%
ets('MAN', damped = F) %>%
predict(10)
Resulting ts forecast:
> projection
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2019.506 19023.17 19022.34 19024.00 19021.90 19024.45
2019.525 19024.58 19022.72 19026.44 19021.73 19027.43
2019.544 19025.98 19022.87 19029.10 19021.22 19030.75
2019.563 19027.39 19022.83 19031.95 19020.42 19034.37
2019.582 19028.80 19022.62 19034.97 19019.35 19038.24
2019.602 19030.20 19022.26 19038.15 19018.05 19042.35
2019.621 19031.61 19021.76 19041.46 19016.54 19046.68
2019.640 19033.02 19021.12 19044.91 19014.83 19051.21
2019.659 19034.42 19020.36 19048.48 19012.92 19055.92
2019.678 19035.83 19019.49 19052.17 19010.84 19060.82
To review projection as graph:
require(ggplot2)
projection %>%
autoplot()