Downloads and aligns historical investment gains for specified tickers from Yahoo! Finance, using the quantmod package.
load_gains(tickers, intercepts = NULL, slopes = NULL, from = "1950-01-01",
to = Sys.Date(), time.scale = "daily", preto.days = NULL,
prefrom.days = NULL, earliest = FALSE, latest = FALSE)
Character vector with ticker symbols that Yahoo! Finance recognizes.
Numeric vector of values to add to daily gains for each ticker.
Numeric vector of values to multiply daily gains for each ticker by. Slopes are multiplied prior to adding intercepts.
Date or character string (e.g. "2015-01-15"
.
Date or character string (e.g. "2016-01-30"
).
Character string controlling time frame for gains. Choices
are "daily"
, "monthly"
, and "yearly"
.
Numeric value. If specified, function returns gains for
preto.days
trading days prior to to
. To illustrate, to load the
most recent 50 daily gains, you would leave to
and time.scale
as the defaults and set preto.days = 50
.
Numeric value. If specified, function returns gains for
prefrom.days
trading days prior to from
. Useful when you want
to test a trading strategy starting on a particular date, but the strategy
requires data leading up to that date (e.g. trailing beta).
Logical value for whether to retain only the subset of
tickers with data going the furthest back. Set to FALSE
if you want
all tickers retained and gains over their mutual lifetimes.
Logical value for whether to retain only the subset of tickers with data going the furthest forward, e.g. dropping funds that were discontinued at some point.
Numeric matrix.
In aligning historical prices, dates on which not all funds have data are simply dropped. Messages are printed indicating which dates are dropped for which tickers.
Ryan, J.A. and Ulrich, J.M. (2017) quantmod: Quantitative Financial Modelling Framework. R package version 0.4-12, https://CRAN.R-project.org/package=quantmod.
# NOT RUN {
# Load gains for Netflix and Amazon over their mutual lifetimes
gains <- load_gains(c("NFLX", "AMZN"))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab