load_gains: Download and Align Investment Gains for a Set of Tickers

Description Usage Arguments Details Value Note Author(s) References See Also Examples

Description

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

Usage

1
2
3
4
5
load.gains(tickers, intercepts = NULL, slopes = NULL, ...,
           from = "1950-01-01", to = Sys.Date(),
           time.scale = "daily",
           preto.days = NULL, prefrom.days = NULL,
           earliest.subset = FALSE, latest.subset = FALSE)

Arguments

tickers

Character string or vector of ticker symbols.

intercepts

Numeric vector of values to add to daily gains for each ticker. For example, if you have two tickers and want to simulate a 1% annual expense ratio for only the second fund, you would set intercepts = c(0, convert.rate(-0.01, units.in = 252, units.out = 1)).

slopes

Numeric vector of values to multiply daily gains for each ticker by. For example, if you have two tickers and want to simulate a 2x leveraged version of the second fund, you would set slopes = c(1, 2). The slopes are multiplied prior to adding the intercepts.

...

Arguments to pass to getSymbols or adjustOHLC functions, which are called internally by this function. For example, you can download data from Google Finance rather than Yahoo! Finance by adding the getSymbols argument src = "google".

from

Date or character string in form of date (e.g. "2015-01-01" for Jan. 1, 2015), indicating the starting date for the period of interest.

to

Date or character string in form of date (e.g. "2016-01-01" for Jan. 1, 2016), indicating the ending date for the period of interest.

time.scale

Character string that controls the time frame for gains. Possible values are "daily", "monthly", and "yearly".

preto.days

If specified, function returns gains for preto.days trading days prior to to. To illustrate, if you want 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

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

If TRUE, only the subset of tickers with data going back to from (or the earliest) are included; if FALSE, all tickers are included, and data covering their mutual lifetimes is returned.

latest.subset

If TRUE, only the subset of tickers with data going all the way to to (or the latest) are included; if FALSE, all tickers are included, and data covering their mutual lifetimes is returned.

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

A numeric matrix where each column indicates the daily/monthly/yearly gains for a given ticker over the time period of interest.

Note

NA

Author(s)

Dane R. Van Domelen

References

1. Jeffrey A. Ryan (2016). quantmod: Quantitative Financial Modelling Framework. R package version 0.4-6, https://cran.r-project.org/package=quantmod.

Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.

See Also

load.prices

Examples

1

Example output

Loading required package: rbenchmark
[1] NA

stocks documentation built on May 2, 2019, 5:22 p.m.