load_prices: Download and Align Historical Prices for a Set of Tickers

Description Usage Arguments Details Value References Examples

View source: R/load_prices.R

Description

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

Usage

1
2
3
4
load_prices(tickers, intercepts = NULL, slopes = NULL,
  from = "1950-01-01", to = Sys.Date(), time.scale = "daily",
  preto.days = NULL, prefrom.days = NULL, initial = 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).

initial

Numeric value specifying what value to scale initial prices to.

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 prices for Netflix and Amazon over their mutual lifetimes
prices <- load_prices(c("NFLX", "AMZN"))

## End(Not run)

vandomed/stocks documentation built on Sept. 2, 2018, 10:10 a.m.