load_gains: Download and Align Gains for a Set of Tickers

Description Usage Arguments Details Value References Examples

Description

Downloads and aligns historical investment gains for specified tickers from Yahoo! Finance, using the quantmod package.

Usage

1
2
3
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)

Arguments

tickers

Character vector with ticker symbols that Yahoo! Finance recognizes.

intercepts

Numeric vector of values to add to daily gains for each ticker.

slopes

Numeric vector of values to multiply daily gains for each ticker by. Slopes are multiplied prior to adding intercepts.

from

Date or character string (e.g. "2015-01-15".

to

Date or character string (e.g. "2016-01-30").

time.scale

Character string controlling time frame for gains. Choices are "daily", "monthly", and "yearly".

preto.days

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.

prefrom.days

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).

earliest

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.

latest

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.

Details

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.

Value

Numeric matrix.

References

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.

Examples

1
2
3
4
5
## Not run: 
# Load gains for Netflix and Amazon over their mutual lifetimes
gains <- load_gains(c("NFLX", "AMZN"))

## End(Not run)

stocks documentation built on May 2, 2019, 9:43 a.m.

Related to load_gains in stocks...