Title: | Forecasting Long-Term Growth of the U.S. Stock Market and Business Cycles |
---|---|
Description: | A long-term forecast model called "Jubilee-Tectonic model" is implemented to forecast future returns of the U.S. stock market, Treasury yield, and gold price. The five-factor model forecasts the 10-year and 20-year future equity returns with high R-squared above 80 percent. It is based on linear growth and mean reversion characteristics in the U.S. stock market. This model also enhances the CAPE model by introducing the hypothesis that there are fault lines in the historical CAPE, which can be calibrated and corrected through statistical learning. In addition, it contains a module for business cycles, optimal interest rate, and recession forecasts. |
Authors: | Stephen H-T. Lihn [aut, cre] |
Maintainer: | Stephen H-T. Lihn <[email protected]> |
License: | Artistic-2.0 |
Version: | 0.3.3 |
Built: | 2025-02-15 02:38:44 UTC |
Source: | https://github.com/cran/jubilee |
The jubilee package provides the core class and functions to forecast long-term growth of the U.S. stock market. It also contains a module for business cycles, optimal interest rate, and recession forecasts. A tutorial is provided to demonstrate how to use this package and explain the relation between the mathematical notations and the functions and data columns in this package.
Stephen H-T. Lihn
Stephen H.T. Lihn, "Jubilee Tectonic Model: Forecasting Long-Term Growth and Mean Reversion in the U.S. Stock Market." Available at SSRN: https://ssrn.com/abstract=3156574 or via DOI: http://dx.doi.org/10.2139/ssrn.3156574
Stephen H.T. Lihn, "Business Cycles, Optimal Interest Rate, and Recession Forecast From Yield Curve, Unemployment, GDP, and Payrolls." Available at SSRN: https://ssrn.com/abstract=3422278
Utility to convert from daily Date (R's Date object) to fraction.
daily2fraction(d)
daily2fraction(d)
d |
array of Date object, or string in ISO |
numeric, year in fraction convention
Stephen H. Lihn
daily2fraction(as.Date("2017-01-15")) # 2017.038 daily2fraction(as.Date("2017-02-14")) # 2017.122 daily2fraction(as.Date("2017-07-15")) # 2017.538
daily2fraction(as.Date("2017-01-15")) # 2017.038 daily2fraction(as.Date("2017-02-14")) # 2017.122 daily2fraction(as.Date("2017-07-15")) # 2017.538
Utility to convert from fraction to daily Date (R's Date object).
fraction2daily(fraction)
fraction2daily(fraction)
fraction |
numeric, representing year in fraction convention. |
array of Date object
Stephen H. Lihn
fraction2daily(2017.038) # 2017-01-15 fraction2daily(2017.125) # 2017-02-15
fraction2daily(2017.038) # 2017-01-15 fraction2daily(2017.125) # 2017-02-15
Construct an jubilee object which holds raw and derived data, channel regression results, and other derived analytical quantities. This object is the main object to perform various forecasts and analyses.
jubilee(dtb, lookback.channel = 45, fwd.rtn.duration = 20, force = TRUE)
jubilee(dtb, lookback.channel = 45, fwd.rtn.duration = 20, force = TRUE)
dtb |
data.table from the |
lookback.channel |
numeric, look-back channel in years to calculate mean-reversion. Default is 45. |
fwd.rtn.duration |
numeric, forward return duration in years. Default is 20. |
force |
logical, if FALSE, allowed to retrieve previous object stored in option. Default is |
an object of the jubilee class
Stephen H. Lihn
## Not run: repo <- jubilee.repo(online=FALSE) ju <- jubilee(repo@ie, 45, 20) ## End(Not run)
## Not run: repo <- jubilee.repo(online=FALSE) ju <- jubilee(repo@ie, 45, 20) ## End(Not run)
This S4 class stores raw and derived data, channel regression settings and results.
call
the match.call slot.
lookback.channel
numeric, the look-back channel in years.
fwd.rtn.duration
numeric, the forward return duration in years.
reg.dtb
data.table, contains the regression data.
dtb
data.table, contains the consolidated market data.
rate.spread.mean
numeric, the mean of the yield spread,
used to calculate rate.spread.norm
column.
create.time
POSIXct
, records the creation time of this object.
This utility is used to adjust the time series by the provided fault lines.
jubilee.adj_fault_line(fraction, ts, fl, months = 1)
jubilee.adj_fault_line(fraction, ts, fl, months = 1)
fraction |
numeric, representing year in fraction convention. |
ts |
numeric, time series to be adjusted, typically it is |
fl |
the fault line matrix. See |
months |
interval in months to ramp up the fault line. Default is 1. |
numeric, ts adjusted by fault lines
Stephen H. Lihn
## Not run: repo <- jubilee.repo(online=FALSE) dj <- jubilee(repo@ie, 45, 10)@reg.dtb dj$log.cape10.adj <- jubilee.adj_fault_line(dj$fraction, dj$log.cape10, "r_nom_f10_5ftr_4fl") ## End(Not run)
## Not run: repo <- jubilee.repo(online=FALSE) dj <- jubilee(repo@ie, 45, 10)@reg.dtb dj$log.cape10.adj <- jubilee.adj_fault_line(dj$fraction, dj$log.cape10, "r_nom_f10_5ftr_4fl") ## End(Not run)
This CAPE calculator replicates the methodology of Shiller, so that one can calculate n-year CAPE, e.g. n=20. This utility has been calibrated by original 10-year CAPE data from Shiller.
jubilee.calc_cape(dtb, period, tol.frac = 1/6)
jubilee.calc_cape(dtb, period, tol.frac = 1/6)
dtb |
data.table |
period |
numeric, the backward-looking regression period |
tol.frac |
numeric, tolerance of missing data in the beginning of the time series, expressed as fraction. Default is 1/6, that is, two months. |
numeric, the same length as dtb$fraction
.
Stephen H. Lihn
## Not run: dtb <- jubilee.repo(online=FALSE)@ie cape10 <- jubilee.calc_cape(dtb, 10) cape20 <- jubilee.calc_cape(dtb, 20) ## End(Not run)
## Not run: dtb <- jubilee.repo(online=FALSE)@ie cape10 <- jubilee.calc_cape(dtb, 10) cape20 <- jubilee.calc_cape(dtb, 20) ## End(Not run)
Calculate the OLS regression for log total return index
jubilee.eqty_ols(dtb, end.frac, lookback.channel, tol.frac = 1/6)
jubilee.eqty_ols(dtb, end.frac, lookback.channel, tol.frac = 1/6)
dtb |
data.table that contains |
end.frac |
numeric, the ending fraction of regression. |
lookback.channel |
numeric, the backward-looking regression period |
tol.frac |
numeric, tolerance of missing data in the beginning, expressed as fraction. Default is 1/6, that is, two months. |
two-element array c(a,R)
if end.frac
is length-one;
data.table with end.frac
as fraction column if end.frac
is an array.
Stephen H. Lihn
## Not run: dtb <- jubilee.repo(online=FALSE)@ie jubilee.eqty_ols(dtb, 1970, 50) # c(11.8671626, 0.1008371) ## End(Not run)
## Not run: dtb <- jubilee.repo(online=FALSE)@ie jubilee.eqty_ols(dtb, 1970, 50) # c(11.8671626, 0.1008371) ## End(Not run)
These two internal utilities are intended to be used to calculate the annualized forward and backward log-return on the given time series. It is really calculating the speed of change, aka log-return, expecting the input to be in logrithmic scale. The forward return is typically the response variable in a forecast. The backward return is often used as explanatory variable in a regression.
jubilee.forward_rtn(fraction, ts, fwd.rtn.duration, tol.frac = 1/12) jubilee.backward_rtn(fraction, ts, bwd.rtn.duration, tol.frac = 1/12)
jubilee.forward_rtn(fraction, ts, fwd.rtn.duration, tol.frac = 1/12) jubilee.backward_rtn(fraction, ts, bwd.rtn.duration, tol.frac = 1/12)
fraction |
numeric, the ending fraction of regression |
ts |
numeric, the time series data, typically in log-scale |
fwd.rtn.duration |
numeric, the forward-looking regression period |
tol.frac |
numeric, tolerance of missing data in the beginning of backward return, or the ending of the forward return, expressed as fraction. Default is 1/12, that is, one month. |
bwd.rtn.duration |
numeric, the backward-looking regression period |
numeric, the same length as fraction
Stephen H. Lihn
## Not run: dtb <- jubilee.repo(online=FALSE)@ie dtb$fwd.logr.10 <- jubilee.forward_rtn(dtb$fraction, dtb$log.tri, 10) dtb$bwd.logr.10 <- jubilee.backward_rtn(dtb$fraction, dtb$log.tri, 10) head(subset(dtb, fraction >= 1990),1)$fwd.logr.10 # 1/1990+10y: 0.16745 tail(subset(dtb, fraction <= 2000+1/12),1)$bwd.logr.10 # the same as above ## End(Not run)
## Not run: dtb <- jubilee.repo(online=FALSE)@ie dtb$fwd.logr.10 <- jubilee.forward_rtn(dtb$fraction, dtb$log.tri, 10) dtb$bwd.logr.10 <- jubilee.backward_rtn(dtb$fraction, dtb$log.tri, 10) head(subset(dtb, fraction >= 1990),1)$fwd.logr.10 # 1/1990+10y: 0.16745 tail(subset(dtb, fraction <= 2000+1/12),1)$bwd.logr.10 # the same as above ## End(Not run)
This utility downloads time series from FRED. Many time series that this package uses are available on FRED. Therefore, this utility is used to provide daily or monthly updates by concatenating live data to the internal static data.
jubilee.fred_data(symbol, col_out = "Close", retry = 3)
jubilee.fred_data(symbol, col_out = "Close", retry = 3)
symbol |
character, the name of the time series |
col_out |
character, the name of the output closing price column. Default is "Close" |
retry |
numeric, number of retries on the URL. Default is 3. |
The xts
object for the time series
## Not run: jubilee.fred_data("VIXCLS") # VIX ## End(Not run)
## Not run: jubilee.fred_data("VIXCLS") # VIX ## End(Not run)
This utility returns the path to internal file
jubilee.locate_file(local_file, stop = TRUE)
jubilee.locate_file(local_file, stop = TRUE)
local_file |
character, the file name of an internal file. |
stop |
logical, whether to stop if file can't be located. Default is |
The path to the file, or else, an empty string
Stephen H. Lihn
jubilee.locate_file("UNRATE.csv")
jubilee.locate_file("UNRATE.csv")
This utility calculates the cost function of the macro model according to the squared error sum with penaty parameter. This utility can be used to experiment more sophisticated optimization schemes.
jubilee.macro_cost(dtb, rs, penalty = c(1, 1, 1), new.tb3ms = NA, new.gs10 = NA)
jubilee.macro_cost(dtb, rs, penalty = c(1, 1, 1), new.tb3ms = NA, new.gs10 = NA)
dtb |
data table, usually this is the reg.dtb of the jubilee object |
rs |
the list returned from |
penalty |
numeric, the penalty vector for the 6 models.
Default is |
new.tb3ms |
numeric, vector of new |
new.gs10 |
numeric, vector of new |
The data table containing the "macro.cost" column
Stephen H. Lihn
This utility contains the macro regression models, covering GUPTY: three types of GDP, UNRATE (unemployment rate), Payroll, and Treasury yield curve. TCU (total capacity utilization) is also covered in the model but less recommended. Given the in-sample time periods, it will perform model regressions and return a list storing relavant information about the result. The purpose of this method is to automate the regression and facilitate programatic cross validation.
jubilee.macro_fit(dtb, N, K, unrate.frac.start, gdp.frac.start, frac.end, cv.frac.end)
jubilee.macro_fit(dtb, N, K, unrate.frac.start, gdp.frac.start, frac.end, cv.frac.end)
dtb |
data table, usually this is the reg.dtb of the jubilee object |
N |
numeric, number of years for GDP log-return calculation in GDP models |
K |
numeric, number of years for GDP log-return calculation in Payroll and TCU models |
unrate.frac.start |
numeric, starting fraction of unrate regression time period |
gdp.frac.start |
numeric, starting fraction of gdp regression time period |
frac.end |
numeric, ending fraction of regression time period. This is also the starting fraction of cross-validation. |
cv.frac.end |
numeric, ending fraction of cross-validation time period. Cross validation can be disabled by setting it to NA. |
The list of data elements and their attributes.
Stephen H. Lihn
Stephen H.T. Lihn, "Business Cycles, Optimal Interest Rate, and Recession Forecast From Yield Curve, Unemployment, GDP, and Payrolls." Available at SSRN: https://ssrn.com/abstract=3422278
## Not run: repo <- jubilee.repo() ju <- jubilee(repo@ie, 45, 20) N <- 4 K <- 1.5 rs <- jubilee.macro_fit([email protected], N, K, 1950, 1960, 2010, 2019) ## End(Not run)
## Not run: repo <- jubilee.repo() ju <- jubilee(repo@ie, 45, 20) N <- 4 K <- 1.5 rs <- jubilee.macro_fit(ju@reg.dtb, N, K, 1950, 1960, 2010, 2019) ## End(Not run)
This utility performs the prediction from the linear models of UNRATE and GDP. The purpose of this method is to automate the prediction and to allow users experimenting optimization on the natural rate of interest.
jubilee.macro_predict(dtb, rs, new.tb3ms = NA, new.gs10 = NA)
jubilee.macro_predict(dtb, rs, new.tb3ms = NA, new.gs10 = NA)
dtb |
data table, usually this is |
rs |
the list returned from |
new.tb3ms |
numeric, vector of new |
new.gs10 |
numeric, vector of new |
The data table containing the predictions and all the required input columns
Stephen H. Lihn
sapply
using multi-coreThis utility calculates sapply
using multi-core capability.
It is a simple wrapper on simplify2array
and parallel::mclapply
.
It is particularly convenient on Linux and Mac when parallelism saves significant amount of computing time.
jubilee.mcsapply(x, FUN, ...)
jubilee.mcsapply(x, FUN, ...)
x |
numeric |
FUN |
the function to be applied to each element of x |
... |
optional arguments to |
numeric
Stephen H. Lihn
a <- seq(1,100) jubilee.mcsapply(a, function(x) x^2) # use multi-core!
a <- seq(1,100) jubilee.mcsapply(a, function(x) x^2) # use multi-core!
Calculate the OLS regression for a given time series and fraction
jubilee.ols(fraction, ts, lookback.channel, tol.frac = 1/6)
jubilee.ols(fraction, ts, lookback.channel, tol.frac = 1/6)
fraction |
numeric, the ending fraction of regression |
ts |
numeric, the time series data |
lookback.channel |
numeric, the backward-looking regression period |
tol.frac |
numeric, tolerance of missing data in the beginning, expressed as fraction. Default is 1/6, that is, two months. |
data.table with columns of fraction, lm.a, lm.y, lm.r
Stephen H. Lihn
See Section 2.3 of Stephen H.T. Lihn, "Jubilee Tectonic Model: Forecasting Long-Term Growth and Mean Reversion in the U.S. Stock Market." Available at http://dx.doi.org/10.2139/ssrn.3156574
## Not run: dtb <- jubilee.repo(online=FALSE)@ie df <- jubilee.ols(dtb$fraction, dtb$log.tri, 50) subset(df, fraction > 1970 & fraction < 1970.05) # fraction lm.a lm.r lm.y # 1970.042 11.86401 0.1007617 0.02103105 ## End(Not run)
## Not run: dtb <- jubilee.repo(online=FALSE)@ie df <- jubilee.ols(dtb$fraction, dtb$log.tri, 50) subset(df, fraction > 1970 & fraction < 1970.05) # fraction lm.a lm.r lm.y # 1970.042 11.86401 0.1007617 0.02103105 ## End(Not run)
This utility calculates the optimal TB3MS using the analytic solution.
jubilee.optimal_tb3ms(dtb, rs, penalty = c(1, 1, 1))
jubilee.optimal_tb3ms(dtb, rs, penalty = c(1, 1, 1))
dtb |
data table, usually this is |
rs |
the list returned from |
penalty |
numeric, the penalty vector for the models.
Default is |
The data table containing the "optimal.tb3ms" column
Stephen H. Lihn
Make prediction based on the linear regression of the forward return. Refer to the tutorial for more detail.
jubilee.predict(object, lm, data) jubilee.predict_real(object, lm, data)
jubilee.predict(object, lm, data) jubilee.predict_real(object, lm, data)
object |
object of jubilee class |
lm |
the linear model |
data |
data used to predict (similar to |
data.table containing the prediction
Stephen H. Lihn
See Section 7 of Stephen H.T. Lihn, "Jubilee Tectonic Model: Forecasting Long-Term Growth and Mean Reversion in the U.S. Stock Market." Available at http://dx.doi.org/10.2139/ssrn.3156574
This utility reads the internal static file, optionally amends with FRED online data, and returns the values of a given symbol.
jubilee.read_fred_file(fraction, local_file, symbol, online = FALSE, daily_symbol = NULL, period = "M")
jubilee.read_fred_file(fraction, local_file, symbol, online = FALSE, daily_symbol = NULL, period = "M")
fraction |
numeric, the fraction to return the value.
The utility will lookup within a month to find value.
For debug purpose, set it to |
local_file |
character, the file name of an internal file.
For debug purpose, set it to |
symbol |
character, the FRED symbol. |
online |
logical, whether to fetch online data from FRED. Default is |
daily_symbol |
character, the FRED symbol to read daily data that supplements
the monthly data. Default is |
period |
charater, length-1 string indicating the data period of the symbol.
M is monthly, Q is quarterly. Default is |
The values of the symbol, numeric with the same length as fraction
.
Stephen H. Lihn
## Not run: repo <- jubilee.repo(online=FALSE) a <- jubilee.read_fred_file(repo@ie$fraction, "BAA.csv", "BAA") tail(a) ## End(Not run)
## Not run: repo <- jubilee.repo(online=FALSE) a <- jubilee.read_fred_file(repo@ie$fraction, "BAA.csv", "BAA") tail(a) ## End(Not run)
jubilee.repo
classConstruct a jubilee.repo
class by combining data from that of Robert Shiller
since 1871, historical stock market data from 1802 to 1987 by William Schwert,
3-month Treasury bill rate, gold price, and several other economic time series from FRED.
Optionally, this function can fetch more recent data from the website of Robert Shiller and
Federal Reserve FRED website if the R session has connection to the internet.
jubilee.repo(online = TRUE, force = TRUE)
jubilee.repo(online = TRUE, force = TRUE)
online |
logical, indicating whether to fetch data from online resource or not. Default is |
force |
logical, if FALSE, allowed to retrieve previous object stored in option.
The FALSE setting overrides the online=TRUE setting. Default is |
An object of jubilee.repo
class
Stephen H. Lihn
## Not run: repo <- jubilee.repo(online=FALSE) dtb <- repo@ie tail(dtb,1) ## End(Not run)
## Not run: repo <- jubilee.repo(online=FALSE) dtb <- repo@ie tail(dtb,1) ## End(Not run)
This S4 class stores the raw data for the jubilee package
call
The match.call slot
ie
data.table, contains the combined data from ie.raw
, ws
, and inflation
.
yield.inversion
numeric, the fractions of yield curve inversion
raw.ie
data.table, contains the data from ie_data.xls
of Robert Shiller
ws
data.table, contains the historical market return data from William Schwert
inflation
data.table, contains the historical inflation data from Minneapolis FED
comm.int
data.table, contains the historical commercial interest rate
tb3ms
data.table, contains the historical 3-month Treasury bill rate
gold
data.table, contains the historical monthly gold prices
gold2
data.table, contains the historical annual gold prices
create.time
POSIXct
, records the creation time of this object.
This utility stores the data configuration for the jubilee's data repository. This is used internally to provide proper abstraction to the data sources, such as file name, URL, FRED symbol, column name, decimal format, etc.
jubilee.repo.config()
jubilee.repo.config()
The list of data elements and their attributes.
Stephen H. Lihn
c <- jubilee.repo.config() c$ie$url
c <- jubilee.repo.config() c$ie$url
This method defines a collection of standard fault line data sets that have been analyzed and optimized in the research. It is intended for end users to produce standard regressions, forecasts, and charts quickly.
jubilee.std_fault_line(name)
jubilee.std_fault_line(name)
name |
character, the name of the collection. If "list" is supplied, the list of names will be returned. If a numeric array is supplied, it will be converted to a matrix format. |
numeric, pairs of fault lines, each is c(year, delta)
Stephen H. Lihn
jubilee.std_fault_line("r_nom_f10_5ftr_4fl") jubilee.std_fault_line("r_nom_f20_5ftr_2fl") jubilee.std_fault_line("r_nom_f20_5ftr_2fl_ramp5y")
jubilee.std_fault_line("r_nom_f10_5ftr_4fl") jubilee.std_fault_line("r_nom_f20_5ftr_2fl") jubilee.std_fault_line("r_nom_f20_5ftr_2fl_ramp5y")
List of dates for yield curve inversion, generally compliant to the dating
of business cycles after WWII in the U.S.. This data is also stored in the
yield.inversion
slot in the jubilee.repo
object.
jubilee.yield_inversion()
jubilee.yield_inversion()
numeric, in the unit of fraction.
Stephen H. Lihn
jubilee.yield_inversion()
jubilee.yield_inversion()
tri.wave
classConstruct an tri.wave
object to simulate the triangular wave model.
tri.wave()
tri.wave()
an object of tri.wave
class
Stephen H. Lihn
w <- tri.wave()
w <- tri.wave()
This S4 class defines the parameters in the triangular wave model.
call
the match.call slot.
a.t
numeric, the look-back channel in years
a0
numeric, the look-back channel in years
s1
numeric, the forward return duration in years
s2
numeric, the start fraction of in-sample training period
y.mean
numeric, the end fraction of in-sample training period
y.amp
numeric, the end fraction of in-sample training period
y.t
numeric, the end fraction of in-sample training period
y.p
numeric, the end fraction of in-sample training period
See Section 4 of Stephen H.T. Lihn, "Jubilee Tectonic Model: Forecasting Long-Term Growth and Mean Reversion in the U.S. Stock Market." Available at http://dx.doi.org/10.2139/ssrn.3156574
Methods of triangular wave model
triangle(t, p) tri.wave.s(object, t) tri.wave.a(object, t) tri.wave.y(object, t) tri.wave.x(object, t) tri.wave.logr.y(object, t, p) tri.wave.logr(object, t, p) tri.wave.logr.semi(object, t) tri.wave.logr.quarter(object, t)
triangle(t, p) tri.wave.s(object, t) tri.wave.a(object, t) tri.wave.y(object, t) tri.wave.x(object, t) tri.wave.logr.y(object, t, p) tri.wave.logr(object, t, p) tri.wave.logr.semi(object, t) tri.wave.logr.quarter(object, t)
t |
the time vector in fraction |
p |
the period of the triangle wave |
object |
the object of |
numeric
Stephen H. Lihn
See Section 4 of Stephen H.T. Lihn, "Jubilee Tectonic Model: Forecasting Long-Term Growth and Mean Reversion in the U.S. Stock Market." Available at http://dx.doi.org/10.2139/ssrn.3156574
w <- tri.wave() t <- seq(1900, 2000, by=1) tri.wave.y(w, t)
w <- tri.wave() t <- seq(1900, 2000, by=1) tri.wave.y(w, t)