The time series of weights
In the previous exercise, you explored the functionality of the Return.portfolio()
function and created portfolios using two strategies. However, by setting the argument verbose = TRUE
in Return.portfolio()
you can create a list of beginning of period (BOP) and end of period (EOP) weights and values in addition to the portfolio returns, and contributions.
You can access these from the resultant list-object created from Return.portfolio()
. The resultant list contains $returns
, $contributions
, $BOP.Weight
, $EOP.Weight
, $BOP.Value
, and $EOP.Value
.
In this exercise, you will recreate the portfolios you made in the last exercise but extend it by creating a list of calculations using verbose = TRUE
. You will then visualize the end of period weights of Apple.
The object returns
is pre-loaded in your workspace.
This exercise is part of the course
Introduction to Portfolio Analysis in R
Exercise instructions
- Define the vector
eq_weights
for two equally weighted assets. - Create a portfolio of returns by using the buy and hold strategy and setting
verbose = TRUE
. Call thispf_bh
. - Create a portfolio of returns using the monthly rebalancing strategy and setting
verbose = TRUE
. Call thispf_rebal
. - Create a new object called
eop_weight_bh
using the end of period weights ofpf_bh
. - Create a new object called
eop_weight_rebal
using the end of period weights ofpf_rebal
. - Plot the end of period weights of Apple in
eop_weight_bh
usingplot.zoo()
, and the end of period weights of Apple ineop_weight_rebal
usingplot.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 <-
# Create a portfolio using buy and hold
pf_bh <- Return.portfolio(returns, weights = eq_weights, ___ )
# Create a portfolio that rebalances monthly
pf_rebal <- Return.portfolio(returns, weights = eq_weights, rebalance_on = "months", ___ )
# Create eop_weight_bh
# Create eop_weight_rebal
# Plot end of period weights
par(mfrow = c(2, 1), mar=c(2, 4, 2, 2))
plot.zoo(___$AAPL)
plot.zoo(___$AAPL)