Computing a Portfolio's Value at Risk (VaR) Using Signaloid's UxHw Technology

Quantitative Finance

Quantitative Finance

Value at Risk (VaR) is widely used in the insurance and risk management industries to estimate potential financial losses over a specific time horizon. One of the most widely-used and most robust methods deployed by these industries for calculating VaR is Monte Carlo simulation. Monte Carlo simulation involves simulating a large number of potential scenarios for future asset prices or portfolio values based on assumed statistical distributions of the parameters and correlations between the assets. By analyzing the distribution of simulated future values of assets and portfolios, practitioners can estimate the highest loss that they would expect to incur at a chosen confidence level. Typically, the Monte Carlo simulation in VaR attempts to approximate the solution to a stochastic differential equation. Therefore, the accuracy of Monte Carlo-based VaR is sensitive to the assumptions made about the underlying stochastic model such as the volatility of each asset, the correlations between the assets, and the choice of parameter distributions. Uncertainty in parameters such as the volatility can lead to large variations in the calculated risk; this volatility underscores the importance of validating and stress testing models. Furthermore, although Monte Carlo simulation can capture this uncertainty, the accuracy of the uncertainty produced by Monte Carlo simulation depends on the number of simulation iterations used; limiting the number of simulation iterations to limit the computational costs of Monte Carlo can often lead to drastic underestimations of potential losses. This explainer describes how to simplify and improve on this computational process in terms of the cost of implementing VaR models (e.g., lines of code), the cost of running the VaR models (e.g., execution time), and the accuracy achieved, comparing VaR using Monte Carlo to the significant quality and performance benefits of instead running those VaR computations on top of computing platforms such as the Signaloid Cloud Compute Engine that implement Signaloid's UxHw technology.

Figure 1: Typical loss function, which is the result of a stochastic process simulated until a selected time, T. The plot shows the VaR as the red zone on the left and the values that we are confident sure will remain at time T as the green zone on the right, given a 95% confidence interval.

Why It Matters

In the insurance and risk sectors, VaR serves as a critical tool for capital allocation, regulatory compliance, and strategic decision-making. Insurers use it to assess potential losses from catastrophic events, while financial institutions rely on it to gauge market and credit risks. Despite the difficulties in computing VaR using Monte Carlo simulations, VaR remains a cornerstone of modern risk management, providing insights into potential exposures and guiding risk mitigation strategies.

The Technical Details

The mathematics and process of estimating VaR involves modeling the distribution of potential portfolio outcomes. The key steps are as outlined next.

Define the Portfolio and Inputs: The VaR estimation process first specifies the portfolio's current value, asset weights (here we assume the basic case of one asset), and risk factors such as volatility (σ).

Generate Random Scenarios: The VaR estimation process next simulates a large collection of potential future states using Signaloid's UxHw technology. We run the simulation, assuming that the driving noise follows a certain probability distribution. A common approach is to model asset prices using geometric Brownian motion (GBM).

Let S(t) be the asset price at time t, let μ be the drift term (expected return), let σ be the volatility of the asset, and let Wt be the standard Brownian motion (Wiener process). Then, the stochastic differential equation (SDE) for GBM is:

Let Z be a standard normal random variable. Then, an explicit solution to this SDE at time T is:

Compute Portfolio Values: If more than one asset is in the portfolio, the VaR estimation process performs the above steps for each asset and then computes a weighted sum to compute the portfolio value. That is, let Vt be the portfolio value at time t, let wi be the weight of asset i, and let Si(t) be the simulated price of asset i at time t. Then, the portfolio value is given by

Construct the Loss Distribution: The VaR estimation process calculates the portfolio losses relative to the initial value (V0), given a loss at time t of L.

Determine VaR: Finally, the VaR estimation process computes the VaR as the loss at the chosen confidence level (e.g., 95% or 99%). For example, for portfolio losses Lt and x percent quantile function Qx, at 95%, VaR is the 5th percentile of the loss distribution:

Consider a portfolio with an initial value of $1,000,000, simulated for 10 years under two different scenarios. In the first scenario, we consider μ=7, σ=20, and obtain a VaR of $417,505.32.

Portfolio value (note that the support for the portfolio value distribution spans approximately 0.0E7 to 0.8E7):

Image

Loss distribution (note that the support for the loss distribution spans approximately -0.05E7 to 0.7E7):

Image

In the second scenario, we consider μ=3, σ=10, and obtain a VaR of $236,780.76.

Portfolio value (note that the support for the portfolio value distribution spans approximately 0.5E6 to 3.5E6):

Image

Loss distribution (note that the support for the loss distribution spans approximately -0.5E6 to 2.5E6):

Image
Relevant Code Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <uxhw.h>

#define alpha 0.05 // Confidence level (5%)
#define years 10
#define timeStepsPerYear 252 // Trading days in a year
#define annualMeanReturn 0.07 // Annual mean return (7%)
#define annualVolatility 0.2 // Annual volatility (20%)

int main() 
{
    /*
     *  Initial portfolio value
     */ 
    double initialPortfolioValue = 1000000.0; 
    double dt = 1.0 ;

    /*
     *  Step 1: Simulate portfolio values at time = years
     */
    double portfolioValue   = initialPortfolioValue;
    double randomNormal     = UxHwDoubleGaussDist(0,1);
    double drift            = annualMeanReturn - 0.5 * annualVolatility * annualVolatility; 
    double diffusion        = annualVolatility *  randomNormal * sqrt(years);           

    portfolioValue *= exp(drift * years + diffusion);
    

    /*
     *  Step 2: Compute all possible returns given the final portfolio values
     */ 
    double simulatedReturns = (portfolioValue - initialPortfolioValue);
    printf("Portfolio Value $ %2.f \n", portfolioValue);
    printf("Simulated Returns $ %2.f \n", simulatedReturns);

    /*
     *  Output results
     */ 
    double var = UxHwDoubleQuantile(simulatedReturns,alpha);
    printf("5%% VaR: $%.2f\n", var);

    return 0;
}
The Takeaway

VaR serves as a critical tool in the insurance and risk sectors. One shortcoming, however, is the large computational cost involved in simulating a prohibitively large number of scenarios to get an accurate distribution of the simulated returns. This technology explainer showed how to take advantage of Signaloid's UxHw technology to reduce both engineering time of implementing VaR models as well as execution time and runtime costs. When running on the Signaloid Cloud Compute Engine, the example showed how to compute the VaR of an asset in mere microseconds using a single one-shot execution and with an implementation of the VaR model requiring fewer than fifty lines of code.

Gallery
Schedule a Demo Call
Request Whitepaper
Schedule a Demo Call
Request Whitepaper
Schedule a Demo Call
Request Whitepaper