periodReturn {quantmod} | R Documentation |
Given a set of prices, return a quantmod.return
object
of returns calculated during specified period.
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)
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 |
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
Returns object of class quantmod.returns
with ending dates of each
period indexing the returns
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
Jeffrey A. Ryan
Bodie,Kane...
## 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)