Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring function returns in a table in R (quant finance)
    primarykey
    data
    text
    <p>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. </p> <p>Let's take an example from the <code>Performance Analytics</code> package:</p> <ul> <li>I have the close-close returns of 3 indices from 2001: SPX, NASDAQ (CCMP) and EuroStoxx (SX5E).</li> <li>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).</li> </ul> <p>To illustrate my question, I will use the <code>table.DownsideRisk</code> function in the <code>Performance Analytics</code> package rather than just calling <code>VaR()</code>.</p> <p>So, I can get these results individually:</p> <pre><code> 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 </code></pre> <p>Or I can place them all in an <code>xts</code> object together and then run <code>table.DownsideRisk</code>:</p> <pre><code> 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 </code></pre> <p>but, let's say I ran the individual example either as an <code>lapply</code> or <code>for</code> loop as part of a broader analytical program - what I would like to do is extract each of the <code>Historical VaR (95%)</code> figures from the output of the <code>table.DownsideRisk</code> function <strong>as the loop / apply function is running on each element</strong> and place those extracted values in a table in the <code>.GlobalEnv()</code> and then sort that table along the lines of (Low to High)</p> <pre><code> Historical VaR (95%) SPX.ccl -.0203 SX5E.ccl -.0249 CCMP.ccl -.0260 </code></pre> <p>I know this will seem rather basic to data frame / table users but any assistance is much appreciated.</p> <p>Cheers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload