Introduction

To assess the performance of the portfolio of assets, we can use the Performance Analytics package again.

Load the packages and get data for gold and emerging market equities, combine the daily closing price using the column bind function (cbind()) and the return function (ROC()).

library('PerformanceAnalytics')
library('quantmod')
# Input data for gold and emerging market etf from Yahoo finance
getSymbols(c('GLD', 'EEM'))
## [1] "GLD" "EEM"
# Combine the returns for the closing price
gld.eem.ret <- cbind(ROC(Cl(GLD)), ROC(Cl(EEM)))
colnames(gld.eem.ret) <- c("GLDR", "EEMR")
head(gld.eem.ret)
##                    GLDR         EEMR
## 2007-01-03           NA           NA
## 2007-01-04 -0.010167073 -0.013905579
## 2007-01-05 -0.024299396 -0.029674175
## 2007-01-08  0.005138866  0.007231336
## 2007-01-09  0.006099070 -0.022589465
## 2007-01-10 -0.004281929 -0.002305813

Now set the portfolio weights and create the portfolio return object

# Set the weights
wgt.50.50 <- c(0.5, 0.5)
# calculate the returns for the 50.50 portfolio with rebalancing
port.50.50.rebal <- Return.portfolio(gld.eem.ret, 
                                     weights = wgt.50.50,
                                     rebalance_on = 'years', 
                                     wealth.index = TRUE,
                                     value = 100)
str(port.50.50.rebal)
## An xts object on 2007-01-03 / 2026-03-06 containing: 
##   Data:    double [4824, 1]
##   Columns: portfolio.wealthindex
##   Index:   Date [4824] (TZ: "UTC")

Now do the same for a portfolio that does not rebalance.

port.50.50.norebal <- Return.portfolio(gld.eem.ret, 
                                       weights = wgt.50.50,
                                       wealth.index = TRUE, 
                                       value = 100)
## Warning in Return.portfolio(gld.eem.ret, weights = wgt.50.50, wealth.index =
## TRUE, : NA's detected: filling NA's with zeros

Now combine the two into a single object.

# combine the rebalance and non-rebalance returns
rebal.wi.1 <- cbind(port.50.50.rebal, port.50.50.norebal)
# Create the column names
colnames(rebal.wi.1) <- c("Rebalance", "Non-Rebalance")
head(rebal.wi.1)
##            Rebalance Non-Rebalance
## 2007-01-03 1.0000000     1.0000000
## 2007-01-04 0.9879637     0.9879637
## 2007-01-05 0.9613067     0.9613067
## 2007-01-08 0.9672478     0.9672478
## 2007-01-09 0.9593228     0.9593228
## 2007-01-10 0.9561458     0.9561458
#

Now plot the two. We use the matplot function to plot from a matrix. It works more or less the same as plot. We compare the two portfolios with rebalancing and no rebalancing.

matplot(index(rebal.wi.1), rebal.wi.1, 
        main = "Wealth Indices",
        ylab = "",
        xlab = "",
        type = 'l', 
        col = c('black', 'blue'))
legend(inset = 0.009, 
       lty = c(1), 'topleft', 
       legend = colnames(rebal.wi.1),
       col = c('black', 'blue'), 
       cex = 0.8)
legend(inset = 0.009, 
       'bottomright', 
       legend = c("Dec 31, 1995 = 1"), 
       cex = 0.8)

Now look at some descriptive statistics to compare the two. ROC will create returns (either arithmetic or geometric), turning the price back into returns for assessment.

Then we use calculations from Performance Analytics to compare the performance of the re-balanced and non-rebalanced portfolios.

rebal.wi.1.ret <- ROC(rebal.wi.1, 
                      type = 'discrete', n = 1, na.pad = FALSE)
head(rebal.wi.1.ret)
##               Rebalance Non-Rebalance
## 2007-01-04 -0.012036326  -0.012036326
## 2007-01-05 -0.026981701  -0.026981701
## 2007-01-08  0.006180232   0.006180232
## 2007-01-09 -0.008193355  -0.008193355
## 2007-01-10 -0.003311732  -0.003311732
## 2007-01-11  0.006513616   0.006513616
# Create the calculations, using the Performance Analytics functions
port.50.50.ret <- Return.annualized(rebal.wi.1.ret, scale = 252)
port.50.50.sd <- apply(rebal.wi.1.ret, 2, FUN = sd) * sqrt(252)
port.50.50.sr <- SharpeRatio.annualized(rebal.wi.1.ret)
port.50.50.sortino <- SortinoRatio(rebal.wi.1.ret)
# Rbind
risk.ret.50.50 <- round(rbind(port.50.50.ret,
                        port.50.50.sd,
                        port.50.50.sr,
                        port.50.50.sortino),3)

row.names(risk.ret.50.50) <- c("Ann'zed Return",
                               "Ann'zed Volatility",
                               "Ann'zed Sharpe Ratio",
                               "Ann'zed Sortino Ratio")
risk.ret.50.50
##                       Rebalance Non-Rebalance
## Ann'zed Return            0.046         0.062
## Ann'zed Volatility        0.169         0.167
## Ann'zed Sharpe Ratio      0.272         0.368
## Ann'zed Sortino Ratio     0.031         0.039