For the purposes of this question, I would like to construct a data frame or similar to be able to "stack rank" and sort various metrics that are generated from functions.
Let's take an example from the Performance Analytics
package:
- I have the close-close returns of 3 indices from 2001: SPX, NASDAQ (CCMP) and EuroStoxx (SX5E).
- I'd like to get the 95% 1day VaR for each of these, place them into a table and then sort them from high to low (or low to high etc).
To illustrate my question, I will use the table.DownsideRisk
function in the Performance Analytics
package rather than just calling VaR()
.
So, I can get these results individually:
SPX.cc
Semi Deviation 0.0095
Gain Deviation 0.0096
Loss Deviation 0.0102
Downside Deviation (MAR=210%) 0.0142
Downside Deviation (Rf=0%) 0.0094
Downside Deviation (0%) 0.0094
Maximum Drawdown 0.5678
Historical VaR (95%) -0.0203
Historical ES (95%) -0.0317
Modified VaR (95%) -0.0193
Modified ES (95%) -0.0273
Or I can place them all in an xts
object together and then run table.DownsideRisk
:
SPX.cc CCMP.cc SX5E.cc
Semi Deviation 0.0095 0.0114 0.0111
Gain Deviation 0.0096 0.0117 0.0114
Loss Deviation 0.0102 0.0116 0.0113
Downside Deviation (MAR=210%) 0.0142 0.0161 0.0161
Downside Deviation (Rf=0%) 0.0094 0.0113 0.0112
Downside Deviation (0%) 0.0094 0.0113 0.0112
Maximum Drawdown 0.5678 0.6103 0.6219
Historical VaR (95%) -0.0203 -0.0260 -0.0249
Historical ES (95%) -0.0317 -0.0370 -0.0372
Modified VaR (95%) -0.0193 -0.0231 -0.0237
Modified ES (95%) -0.0273 -0.0293 -0.0330
but, let's say I ran the individual example either as an lapply
or for
loop as part of a broader analytical program - what I would like to do is extract each of the Historical VaR (95%)
figures from the output of the table.DownsideRisk
function as the loop / apply function is running on each element and place those extracted values in a table in the .GlobalEnv()
and then sort that table along the lines of (Low to High)
Historical VaR (95%)
SPX.ccl -.0203
SX5E.ccl -.0249
CCMP.ccl -.0260
I know this will seem rather basic to data frame / table users but any assistance is much appreciated.
Cheers.