load_prices: Download Historical Prices

Description Usage Arguments Value References Examples

View source: R/load_prices.R

Description

Downloads historical prices for specified tickers from Yahoo! Finance, with various options. Relies heavily on the quantmod package.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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,
  mutual.lifetimes = TRUE,
  mutual.start = mutual.lifetimes,
  mutual.end = mutual.lifetimes,
  anchor = FALSE,
  drop.anyNA = FALSE
)

Arguments

tickers

Character vector of ticker symbols that Yahoo! Finance recognizes, or "^CASH" for cash.

intercepts

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

slopes

Numeric vector of values to multiply daily gains for each fund 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. "2018-12-31".

time.scale

Character string. Choices are "daily", "monthly", and "yearly".

preto.days

Numeric value. If specified, function returns prices for preto.days trading days prior to to. For example, to load the most recent 50 closing prices, leave to and time.scale as the defaults and set preto.days = 50.

prefrom.days

Numeric value. If specified, function returns prices 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.

mutual.lifetimes

Logical value for whether to start on the first day and end on the last day of the funds' mutual lifetimes (within from and to).

mutual.start

Logical value for whether to start on the first day of the funds' mutual lifetimes.

mutual.end

Logical value for whether to end on the last day of the funds' mutual lifetimes.

anchor

Logical value for whether to anchor the starting price for each fund to the price of the longest-running fund on that day. Useful for visualizing funds' entire histories while also fairly comparing them over their mutual lifetimes. Only used if mutual.start = FALSE.

drop.anyNA

Logical value for whether to drop dates on which prices are missing for any of the funds.

Value

Data frame with closing prices for each fund.

References

Jeffrey A. Ryan and Joshua M. Ulrich (2019). quantmod: Quantitative Financial Modelling Framework. R package version 0.4-15. 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 July 22, 2020, 3:25 a.m.