load_gains: Download Historical Gains

Description Usage Arguments Value References Examples

View source: R/load_gains.R

Description

Downloads historical gains 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
load_gains(
  tickers,
  intercepts = NULL,
  slopes = NULL,
  from = "1950-01-01",
  to = Sys.Date(),
  time.scale = "daily",
  preto.days = NULL,
  prefrom.days = NULL,
  mutual.lifetimes = TRUE,
  mutual.start = mutual.lifetimes,
  mutual.end = mutual.lifetimes,
  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 gains for preto.days trading days prior to to. For example, to load the most recent 50 daily gains, 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).

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.

drop.anyNA

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

Value

Data frame with gains 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 gains for Netflix and Amazon over their mutual lifetimes
gains <- load_gains(c("NFLX", "AMZN"))

## End(Not run)

vandomed/stocks documentation built on July 22, 2020, 3:25 a.m.