Get startedGet started for free

The time series of portfolio returns

In the previous exercise, you created a variable called returns from the daily prices of stocks of Apple and Microsoft. In this exercise, you will create two portfolios using the return series you previously created. The two portfolios will differ in one way, and that is the weighting of the assets.

In the last video, you were introduced to two weighting strategies: the buy and hold strategy, and a monthly rebalancing strategy. In this exercise, you will create a portfolio in which you don’t rebalance, and one where you rebalance monthly. You will then visualize the portfolio returns of both.

You will use the function Return.portfolio() for your calculations. For this function, you will provide three arguments: R, weights, and rebalance_on. R is a time series of returns, weights is a vector containing asset weights, and rebalance_on specifies which calendar-period to rebalance on. If you need help, be sure to check the documentation by clicking on the function!

For this exercise, you will be working with the returns data that are pre-loaded in your workspace.

This exercise is part of the course

Introduction to Portfolio Analysis in R

View Course

Exercise instructions

  • Create a vector of weights for two equally weighted assets called eq_weights. Remember that weights must add to 1.
  • Create a portfolio using the buy and hold strategy using Return.portfolio(). Note, you do not need to specify a rebalance period. Call this pf_bh.
  • Create a portfolio where you rebalance your weights monthly. Use Return.portfolio() with the argument rebalance_on = "months". Call this pf_rebal.
  • Plot the time series of each portfolio using plot.zoo(). par(mfrow = c(2, 1), mar = c(2, 4, 2, 2)) is used to organize the plots you create. Do not alter this code.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create the weights
eq_weights <- c(___, ___)

# Create a portfolio using buy and hold
pf_bh <- Return.portfolio(R = ___, weights = ___)

# Create a portfolio rebalancing monthly 


# Plot the time-series
par(mfrow = c(2, 1), mar = c(2, 4, 2, 2))
plot.zoo(___)
plot.zoo(___)
Edit and Run Code