Learn R Programming

quantmod (version 0.4.25)

periodReturn: Calculate Periodic Returns

Description

Given a set of prices, return periodic returns.

Usage

periodReturn(x,
             period='monthly',
             subset=NULL,
             type='arithmetic',
             leading=TRUE,
             ...)

dailyReturn(x, subset=NULL, type='arithmetic', leading=TRUE, ...) weeklyReturn(x, subset=NULL, type='arithmetic', leading=TRUE, ...) monthlyReturn(x, subset=NULL, type='arithmetic', leading=TRUE, ...) quarterlyReturn(x, subset=NULL, type='arithmetic', leading=TRUE, ...) annualReturn(x, subset=NULL, type='arithmetic', leading=TRUE, ...) yearlyReturn(x, subset=NULL, type='arithmetic', leading=TRUE, ...) allReturns(x, subset=NULL, type='arithmetic', leading=TRUE)

Value

Returns object of the class that was originally passed in, with the possible exception of monthly and quarterly return indicies being changed to class yearmon and yearqtr

where available. This can be overridden with the indexAt

argument passed in the ... to the to.period function.

By default, if subset is NULL, the full dataset will be used.

Arguments

x

object of state prices, or an OHLC type object

period

character string indicating time period. Valid entries are ‘daily’, ‘weekly’, ‘monthly’, ‘quarterly’, ‘yearly’. All are accessible from wrapper functions described below. Defaults to monthly returns (same as monthlyReturn)

subset

an xts/ISO8601 style subset string

type

type of returns: arithmetic (discrete) or log (continuous)

leading

should incomplete leading period returns be returned

...

passed along to to.period

Author

Jeffrey A. Ryan

Details

periodReturn is the underlying function for wrappers:

  • allReturns: calculate all available return periods

  • dailyReturn: calculate daily returns

  • weeklyReturn: calculate weekly returns

  • monthlyReturn: calculate monthly returns

  • quarterlyReturn: calculate quarterly returns

  • annualReturn: calculate annual returns

See Also

getSymbols

Examples

Run this code
if (FALSE) {
getSymbols('QQQQ',src='yahoo')
allReturns(QQQQ)  # returns all periods

periodReturn(QQQQ,period='yearly',subset='2003::')  # returns years 2003 to present
periodReturn(QQQQ,period='yearly',subset='2003')  # returns year 2003

rm(QQQQ)
}

Run the code above in your browser using DataLab