periodReturn: Calculate Periodic Returns

periodReturnR Documentation

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)

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

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

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.

Note

Attempts are made to re-convert the resultant series to its original class, if supported by the xts package. At present, objects inheriting from the ‘ts’ class are returned as xts objects. This is to make the results more visually appealling and informative. All xts objects can be converted to class ts with as.ts if that is desirable.

The first and final row of returned object will have the period return to last date, i.e. this week/month/quarter/year return to date even if the start/end is not the start/end of the period. Leading period calculations can be suppressed by setting leading=FALSE.

Author(s)

Jeffrey A. Ryan

See Also

getSymbols

Examples

## Not run: 
getSymbols('QQQ',src='yahoo')
allReturns(QQQ)  # returns all periods

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

rm(QQQ)

## End(Not run)

quantmod documentation built on May 29, 2024, 8:03 a.m.