1. Learn
  2. /
  3. Courses
  4. /
  5. Quantitative Risk Management in R

Exercise

Exploring risk-factor time series: individual equities

For some risk management applications, it is sufficient to model equity risk by looking at indexes. If you want a more detailed model of the risk in a portfolio of equities, you can drill down to the level of individual share prices.

In the previous chapter, you used DJ["2008/2009"] to extract the Dow Jones data from certain rows of an xts object by specifying a date range index. To also extract data from particular columns, you can add a column identifier, like a string name or numeric index, in the brackets following a comma. To select multiple columns, include these column identifiers in a vector. This [rows, columns] format is consistent with indexing most other two dimensional objects in R.

data[index, colname]
data[index, c(col1index, col2index)]

The qrmdata package also includes data for certain constituents, or the stocks or companies part of a larger index. The Dow Jones constituents data are contained in "DJ_const". In this exercise, you will view the names of all its stocks, select the Apple and Goldman Sachs share prices, and plot them using the command plot.zoo() to display multiple time series.

Instructions

100 XP
  • Load the DJ constituents data "DJ_const" from qrmdata.
  • Use names() to view the names in DJ_const and head() to display the first few rows.
  • Extract only the Apple ("AAPL") and Goldman Sachs ("GS") share prices for 2008-2009 and assign them to object stocks.
  • Plot stocks using plot.zoo().