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.
Diese Übung ist Teil des Kurses
Quantitative Risk Management in R
Anleitung zur Übung
- Load the DJ constituents data
"DJ_const"fromqrmdata. - Use
names()to view the names inDJ_constandhead()to display the first few rows. - Extract only the Apple (
"AAPL") and Goldman Sachs ("GS") share prices for 2008-2009 and assign them to objectstocks. - Plot
stocksusingplot.zoo().
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Load DJ constituents data
___(___)
# Apply names() and head() to DJ_const
___(___)
___(___)
# Extract AAPL and GS in 2008-09 and assign to stocks
stocks <- ___
# Plot stocks with plot.zoo()
___(___)