Calculate Yearly Gains for One or More Tickers

Description

Calculate yearly gains for one or more ticker symbols. User can enter names of tickers or a list of objects returned from the getSymbols function in the quantmod package.

Usage

1
2
yearly.gains(tickers = NULL, quantmod.list = NULL, from = NULL, to = NULL, 
              decimals = getOption("digits"), partialyear.min = 125)

Arguments

tickers

Character string or vector of character string with ticker symbols that Yahoo! Finance recognizes.

quantmod.list

List of objects returned from getSymbols function in the quantmod package [1].

from

Date or character string in form of date (e.g. '1950-01-03' for January 3, 1950), indicating the starting date for the period of interest. Default is first day of calendar year 5 years prior to the 'to' date.

to

Date or character string in form of date (e.g. '2015-03-09' for March 9, 2015), indicating the ending date for the period of interest. Default is current date.

decimals

Whole number indicating the number of decimal places you would like numbers rounded to.

partialyear.min

Minimum number of trading days for a year to be included in the analysis. Mainly used to control whether partial year at beginning and end of time period is included.

Value

Data frame where each row shows the year, number of trading days, total growth for each ticker, compound annual growth rate (CAGR) for each ticker, and compound daily growth rate (CADR) for each ticker.

Note

This function prints warnings which are typically nothing to worry about.

Author(s)

Dane R. Van Domelen

References

1. Jeffrey A. Ryan (2014). quantmod: Quantitative Financial Modelling Framework. R package version 0.4-2/r613. http://R-Forge.R-project.org/projects/quantmod/.

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

See Also

monthly.gains

Examples

1
2
# Get yearly gains for UPRO and the S&P 500 over the past 5 years
upro.sp500.gains <- yearly.gains(tickers = c("UPRO", "^GSPC"))

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.