Description Usage Arguments Value Author(s) Examples
View source: R/pub01_utilityFuncs.R
These are wraped functions of Return.portfolio
and Return.rebalancing
in package PerformanceAnalytics
, with some bug fixed and more result returned.
1 2 3 4 |
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
weights |
a time series or a vector containing asset weights. Note that the sum of weights is not required to be 1. If the sum is smaller to 1,the remnant weight is set to 'cash',and the portfolio is treated as an unfull-position portfolio;if the sum is larger than 1, the extra weight is set as liability, and the portfolio is treated as a leveraged portfolio. See detail in examples. |
rebFreq |
Default "na", alternatively "day", "weeks", "month", "quarter", and "year". to specify calendar-period rebalancing supported by |
fee.buy |
a single-row matrix or a vector containing buying fee of each assets. It also could be a numeric scalar, which means all the assets have the same fee. |
fee.sell |
a single-row matrix or a vector containing selling fee of each assets. It also could be a numeric scalar, which means all the assets have the same fee. |
output |
a vector of character string, with default of c("rtn","turnover","wgt_EOP","wgt_BOP","contribution","weights","rebtrade") |
geometric |
a logical. generate geometric (TRUE) or simple (FALSE) returns, default TRUE |
warning.wgtsum |
a logical. wheather put out a warning when sum of the weights is not equal to 1 ? |
a list with items:
rtn: a time series of the portfolio return.
turnover: a time series of turnover.
wgt_EOP: End of Period (BOP) Weight for each asset, with dims of c(nrow(R), ncol(weights)+1)
.
wgt_BOP: Beginning of Period (BOP) Weight for each asset, with dims of c(nrow(R), ncol(weights)+1)
.
contritution: The per period contribution to portfolio return of each asset, with dims of c(nrow(R), ncol(weights)+1)
weights: weights
rebtrade: a time series of the rebalancing trading of each asset, with dims of c(nrow(weights), ncol(weights)+1)
, a positive element means buying,and vice versa.
Ruifei.yin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | R <- zoo(matrix(rnorm(12,0,0.1),4,3),Sys.Date()+1:4)
colnames(R) <- letters[1:3]
w1 <- (c(0.2,0.3,0.5))
w2 <- (c(0.2,0.3,0.1))
w3 <- (c(0.2,0.3,-0.5))
w4 <- (c(1,0.5,0.5))
Return.backtesting(R,w1) # full position portfolio
Return.backtesting(R,w2) # unfull position portfolio
Return.backtesting(R,w3) # long-short portfolio
Return.backtesting(R,w4) # leveraged portfolio
# examples from \code{\link[PerformanceAnalytics]{Return.portfolio}}
require(PerformanceAnalytics)
data(edhec)
re <- Return.backtesting(edhec["1997",1:5], rebFreq="quarters")
# with a weights object
data(weights) # rebalance at the beginning of the year to various weights through time
chart.StackedBar(weights)
x <- Return.backtesting(edhec["2000::",1:11], weights=weights)
chart.CumReturns(x$returns)
chart.StackedBar(x$BOP.Weight)
chart.StackedBar(x$BOP.Value)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.