Learn R Programming

quantmod (version 0.3-3)

periodReturn: Calculate Periodic Returns

Description

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

Usage

periodReturn(x, by = months, from = NULL, to = NULL)

allReturns(x, from = NULL, to = NULL) dailyReturn(x, from = NULL, to = NULL) weeklyReturn(x, from = NULL, to = NULL) monthlyReturn(x, from = NULL, to = NULL) quarterlyReturn(x, from = NULL, to = NULL) annualReturn(x, from = NULL, to = NULL)

Arguments

x
zoo object of state prices
by
character string indicating time period. Valid entries are weekdays, weeks, months, quarters, years. All are accessible from wrapper functions described below. Defaults to monthly returns (same as monthlyReturn)
from
character string representing dates in ISO 8601 format (e.g. 1992-01-01). Defaults to beginning of dataset
to
character string representing dates in ISO 8601 format (e.g. 1992-01-01). Defaults to end of dataset

Value

  • Returns object of class quantmod.returns with ending dates of each period indexing the returns

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

Examples

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

periodReturn(QQQQ,by=years,from='2003-01-01')  # returns years 2003 to present
periodReturn(QQQQ,by=years,from='2003-01-01',to='2004-01-01')  # returns year 2003

rm(QQQQ)

Run the code above in your browser using DataLab