Return.backtesting: Calculates weighted returns for a portfolio of assets

Description Usage Arguments Value Author(s) Examples

View source: R/pub01_utilityFuncs.R

Description

These are wraped functions of Return.portfolio and Return.rebalancing in package PerformanceAnalytics, with some bug fixed and more result returned.

Usage

1
2
3
4
Return.backtesting(R, weights = NULL, rebFreq = NA, fee.buy = 0,
  fee.sell = 0, output = c("rtn", "turnover", "wgt_EOP", "wgt_BOP",
  "contribution", "weights", "rebtrade"), geometric = TRUE,
  warning.wgtsum = TRUE)

Arguments

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 endpoints.

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 ?

Value

a list with items:

Author(s)

Ruifei.yin

Examples

 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) 

raphael210/QUtility documentation built on May 26, 2019, 11:05 p.m.