Computing Portfolio VaR Across Candidate Weight Combinations
Summary
The document shows how to calculate portfolio-level value at risk for different candidate allocations using component profit-and-loss observations. For each weight vector, scale each component’s P&L by its weight, sum the weighted values by observation, and take the chosen lower-tail quantile of the resulting portfolio P&L distribution. The answer demonstrates this process in R by applying the calculation across a list of weight vectors, and notes that candidate allocations could instead be stored in a matrix.
The example uses generated returns and reports quantiles for allocations concentrated in individual components. It illustrates a simple way to extend the calculation from two components to a larger set, provided each component’s observations are aligned across scenarios. The method only evaluates the supplied weight combinations; it does not itself search the allocation space or explain constraints such as weights summing to one. Its VaR estimate also depends on the input P&L sample and the selected confidence level, so the example is a computational recipe rather than evidence about portfolio risk performance.
Key ideas
- For each scenario, portfolio P&L is the sum of component P&Ls multiplied by their respective weights.
- VaR can be calculated by taking a lower-tail quantile of the portfolio P&L observations.
- The same calculation extends to many components by iterating over candidate weight vectors.
- The approach evaluates specified allocations but does not generate or optimize the weight combinations.
Tags
Full text
# Testing severity of VaR by changing portfolio component weights
# Testing severity of VaR by changing portfolio component weights
Let's assume that I have a portfolio with two components:$$\omega_i = 0.3$$ $$\omega_j = 0.7$$
I also have two P&L vectors, $v_i$ and $v_j$ each containing 1000 P&Ls. I would like to play around with the weights and test out the VaR 95% at portfolio/total level. What would be the easiest and most intuitive approach (either in R or Python) if I wanted to extend this exercise to $n$ components instead of having only two?
Note that to find the portfolio P&L I am simply multiplying each P&L by each component's weight and then summing them together: $$PnL_t = \omega_i \times v_{i,t} + \omega_j \times v_{j,t}$$
## Answer by Kermittfrog (score 2, accepted)
https://quant.stackexchange.com/a/65997
In R, the simplest way to brute force through a predefined number of portfolio combinations would be to simply iterate over them:
```
set.seed(42)
returns <- matrix(rnorm(200),40,5)
weights <- list(c(1,0,0,0,0),
c(0,1,0,0,0),
c(0,0,1,0,0),
c(0,0,0,1,0),
c(0,0,0,0,1))
conf <- 0.99
sapply(weights,function(w){
quantile(
rowSums( sweep( returns, 2, w, "*")),
1-conf)
})
```
which would result in
```
1% 1% 1% 1% 1%
-2.572220 -2.359415 -1.582364 -1.840156 -1.686373
```
Of course, you will need to play around with the various weights, or maybe you store them in a matrix instead of a list and iterate; same result.
Did this help?Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.