Commodities data
The plotting function pairs() creates a pairwise scatterplot of the components of a multivariate time series with two or more dimensions. It is used on a zoo object rather than an xts object.
A roughly circular shape of a scatterplot indicates a low correlation between the log-returns of two different commodities. Generally speaking, low correlation is good in a portfolio as it implies that the assets are diversified. High correlation, on the other hand, represents a risk that must be properly modelled.
In this exercise, you will look at gold and oil prices over a 25 year period, calculate their daily and monthly log-returns, and plot them. The data gold and oil, containing the daily prices from 1990-2015 of gold and Brent crude oil, respectively, are available in your workspace.
Diese Übung ist Teil des Kurses
Quantitative Risk Management in R
Anleitung zur Übung
- Use
plot()to plot thegoldandoiltime series separately. - Calculate the daily log-returns of each commodity and assign to
goldxandoilx, respectively. - Calculate the monthly log-returns of each commodity and assign to
goldx_mandoilx_m, respectively. - Use
merge()to mergegoldx_mandoilx_m, in that order, intocoms. - Plot
coms, a multivariate series, with vertical bars. - Convert
comsto azooobject withas.zoo()and then applypairs()to create a pairwise scatterplot.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Plot gold and oil prices
___(___)
___(___)
# Calculate daily log-returns
goldx <- ___(___)
oilx <- ___(___)
# Calculate monthly log-returns
goldx_m <- ___(___)
oilx_m <- ___(___)
# Merge goldx_m and oilx_m into coms
coms <- ___(___, ___)
# Plot coms with vertical bars
___(___, ___)
# Make a pairwise scatterplot of coms
___(___)