Split-sample evaluation
In chapter 2, you used the function window() to subset your returns for graphical purposes. In this exercise, you will use the window() to create two samples: an estimation sample and an evaluation sample. This exercise will illustrate how portfolio weights can differ when changing the estimation window.
To remind you, the function window() has argument of x, start, and end. Where start and end are in the format "YYYY-MM-DD".
The object returns is loaded in your workspace.
Diese Übung ist Teil des Kurses
Introduction to Portfolio Analysis in R
Anleitung zur Übung
- Create the sample
returns_estimby subsettingreturns, where the sample begins on January 1st, 1991, and ends on December 31st, 2003. - Create the sample
returns_evalby subsettingreturns, where the sample begins on the first day of 2004 and ends on the last day of 2015. - Create a vector of maximum weights equal to 10%, with a length as the number of columns there are in
returnscalledmax_weights. - Create a portfolio with the estimation sample called
pf_estim, where the maximum weight (reshigh) is set tomax_weights. - Create a portfolio with the evaluation sample called
pf_eval, where the maximum weight (reshigh) is set tomax_weights. - Create a scatter plot of the evaluation portfolio weights versus the estimation portfolio weights (note that you can use
$pw). If portfolio weights are identical, they should be on the 45-degree line.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Create returns_estim
returns_estim <- window(___, start = "YYYY-MM-DD", end = "YYYY-MM-DD")
# Create returns_eval
# Create vector of max weights
max_weights <- rep(___, ncol(___))
# Create portfolio with estimation sample
pf_estim <- portfolio.optim(___, reshigh = ___)
# Create portfolio with evaluation sample
# Create a scatter plot with evaluation portfolio weights on the vertical axis
plot(___, ___)
abline(a = 0, b = 1, lty = 3)