periodReturn {quantmod}R Documentation

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

Details

periodReturn is the underlying function for wrappers:

Value

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

Note

The final row of returned object will have the current period return to last date, i.e. this week/month/quarter/year return to date.

By default, if from and/or to is missing, they will be set to the dataset beginning and end, respectively. One or both may be set, and will subset the data, inclusively, after all calculations have been made. The values must be character strings representing dates in ISO 8601 format. (e.g. 1992-01-01).

Additional methods to handle ts and data.frame objects will enable automatic conversion to the suitable zoo object as returned by a call to getSymbols

Author(s)

Jeffrey A. Ryan

References

Bodie,Kane...

See Also

getSymbols

Examples

## Not run: 
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)
## End(Not run)

[Package quantmod version 0.2-5 Index]