Learn R Programming

quantmod (version 0.3-4)

periodReturn: Calculate Periodic Returns

Description

Given a set of prices, return a quantmod.return object of returns calculated during specified period.

Usage

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

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

allReturns(x, subset=NULL, type='arithmetic')

Arguments

x
zoo object of state prices
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 style subset string
type
type of returns: arithmetic (discrete) or log (continuous)
...
passed along to to.period

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.

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

References

Bodie,Kane...

See Also

getSymbols to.period

Examples

Run this code
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