Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/returns.R View source: R/returns.R
Convert prices into returns.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  returns(x, ...)
## Default S3 method:
returns(x, t = NULL, period = NULL, complete.first = TRUE, pad = NULL,
position = NULL, weights = NULL, rebalance.when = NULL,
lag = 1, ...)
## S3 method for class 'zoo'
returns(x, period = NULL, complete.first = TRUE,
pad = NULL, position = NULL,
weights = NULL, rebalance.when = NULL, lag = 1, ...)
## S3 method for class 'p_returns'
print(x, ..., year.rows = TRUE, month.names = NULL,
zero.print = "0", plus = FALSE, digits = 1,
na.print = NULL)
## S3 method for class 'p_returns'
toLatex(object, ...,
year.rows = TRUE, ytd = "YTD", month.names = NULL,
eol = "\\\\", stand.alone = FALSE)
## S3 method for class 'p_returns'
toHTML(x, ...,
year.rows = TRUE, ytd = "YTD", month.names = NULL,
stand.alone = TRUE, table.style = NULL, table.class = NULL,
th.style = NULL, th.class = NULL,
td.style = "textalign:right; padding:0.5em;",
td.class = NULL, tr.style = NULL, tr.class = NULL, browse = FALSE)
.returns(x, pad = NULL, lag)

x 
a 
t 
timestamps. See argument 
period 
Typically All returns are computed as simple returns. They
will only be annualised with option 
complete.first 
logical. For monthly returns, should the first month (if incomplete) be used. 
pad 
either 
position 
numeric; the same length/dimension as

weights 
numeric 
rebalance.when 
numeric 
... 
further arguments 
year.rows 
logical. If 
zero.print 
character. How to print zero values. 
na.print 
character. How to print 
plus 
logical. Add a ‘ 
lag 
The lag for computing returns. A positive integer,
defaults to one; ignored for timeweighted returns
or if 
object 
an object of class 
month.names 
character: names of months. Default is an
abbreviated month name as provided by the
locale. That may cause trouble, notably with

digits 
number of digits in table 
ytd 
header for YTD 
eol 
character 
stand.alone 
logical or character 
table.class 
character 
table.style 
character 
th.class 
character 
th.style 
character 
td.class 
character 
td.style 
character 
tr.class 
character 
tr.style 
character 
browse 
logical: open table in browser? 
returns
is a generic function. It computes
simple returns: current values divided by prior
values minus one. The default method works for
numeric vectors/matrices.
When a timestamp is available, returns can compute returns for specific calendar periods.
returns
may compute returns for a portfolio
specified in weights
. The portfolio is
rebalanced at rebalance.when
; the default is
every period.
rebalance.when
may either be integers or of
the same class as a timestamp
(e.g. Date
).
If called as returns(x)
: a numeric vector or
matrix, possibly of class zoo
.
If called with a period
argument: an object of
class "p_returns"
(period returns), which is a
numeric vector of returns with attributes t
(timestamp) and period
. Main use is to have
methods that prettyprint such period returns;
currently, there are methods for
toLatex
and
toHTML
.
Enrico Schumann
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  x < 101:105
returns(x)
returns(x, pad = NA)
returns(x, pad = NA, lag = 2)
## monthly returns
t < seq(as.Date("20120615"), as.Date("20121231"), by = "1 day")
x < seq_along(t) + 1000
returns(x, t = t, period = "month")
returns(x, t = t, period = "month", complete.first = FALSE)
### formatting
print(returns(x, t = t, period = "month"), plus = TRUE, digits = 0)
## returns per year (annualised returns)
returns(x, t = t, period = "ann") ## less than one year, not annualised
returns(x, t = t, period = "ann!") ## less than one year, *but* annualised
is.ann < function(x)
attr(x, "is.annualised")
is.ann(returns(x, t = t, period = "ann")) ## FALSE
is.ann(returns(x, t = t, period = "ann!")) ## TRUE

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.