This provides a safe way to do portfolio return calculations. It ensures the returns and weights are explicitly mapped. It is thus a simple wrapper to PerformanceAnalytics::Return.portfolio making it safer. See the following gist for a discussion on why this safety feature is essential:

Safe_Return.portfolio(R, weights, lag_weights = TRUE, ...)



xts of returns.


xts weights.


This function makes weights effective on the day it is given. The Return.Portfolio function defaults to having weights become effective only the following day after its specification. E.g. from the vignette: Rebalancing periods can be thought of as taking effect immediately after the close of the bar. So, a March 31 rebalancing date will actually be in effect for April 1.


parameter inputs from PerformanceAnalytics::Return.portfolio.


#> Warning: package 'PerformanceAnalytics' was built under R version 3.6.1
#> Loading required package: xts
#> Loading required package: zoo
#> Warning: package 'zoo' was built under R version 3.6.1
#> #> Attaching package: 'zoo'
#> The following objects are masked from 'package:base': #> #> as.Date, as.Date.numeric
#> #> Attaching package: 'PerformanceAnalytics'
#> The following object is masked from 'package:graphics': #> #> legend
data(edhec) data(weights) # rebalance at the beginning of the year to various weights through time x <- Safe_Return.portfolio(edhec[,1:11], weights=weights, lag_weights = TRUE, verbose=TRUE)