➗

# Calculations for Euler Wallet VaR

For our wallet value at risk page, we wanted to come up with a simple metric that conveys a decentralized lending position's risk of liquidation. Anthias uses Aave's liquidation health formula for our Aave dashboards in order to show the "health" of a position. However, through our eGP6 grant from the Euler community, we created a bespoke health metric for Euler. The Aave liquidation health metric is great, but it does not always accurately display a position's risk of liquidation. When a position's collateral and liability assets are highly correlated, a position with a liquidation health factor close to 1 may still have a low probability of liquidation. Also, two positions with the same liquidation health factor will differ in actual risk of liquidation depending on the variance and covariance of the value of their collateral and liability.

Therefore, we wanted to create a metric that displays a position's risk of liquidation, taking into account the variance of each of the position's underlying assets' price action, as well as the covariance between each of those assets' price actions. The following walkthrough will show how Anthias derives a probability that a position gets liquidated.

We calculate the daily returns on each token and the average return. Note that the returns for DWBTC are multiplied by -1 as liabilities are considered short positions on the asset. For excess returns we take the returns and subtract them from the average return to get the following results.

Next, the covariance matrix will be an nxn matrix based on the number of tokens, 3 in this case.

Each value represents the covariance of the two tokens in the array corresponding to the cell. For cells that represent two of the same token, the value is the variance. The covariance between any token A and token B is calculated as:

$\frac{\sum_{i=1}^{days} A\_excessReturns[i]\times B\_excessReturns[i]}{days}$

where "days" represents the number of days that you have returns calculated for.

As a matrix operation, the covariance matrix is calculated as:

$\frac{excessReturns^TexcessReturns}{days}$

The portfolio's standard deviation of percent change is calculated as:

$\phi = \sqrt{\sum_{i=1}^{n} \sum_{j=1}^{n} covariance[i][j]\times proportion_i\times proportion_j}$

where "n" represents the number of tokens and the proportions are calculated as:

$\frac{\beta_{token}}{\beta}$

where

$\beta = \beta_{collateral} + \beta_{liability}$

represents the total value of the position as the sum of the value of the position's collateral and liability, and $\beta_{token} = numTokens * tokenPrice$

. As a note, the proportions of liability assets and $\beta_{liability}$

are positive as liabilities already having been treated as short when calculating returns.The portfolio's standard deviation of price movement over n days is then calculated as:

$\sigma_n = \beta\times\phi\times\sqrt{n}$

The liquidation buffer is then calculated as:

$\alpha = \beta_{collateralWeighted} - \beta_{liabilityWeighted}$

where

$\beta_{collateralWeighted} = \sum_{i=1}^n \beta_{token[i]}\times collateralFactor[i]$

for all n collateral assets and the and $\beta_{liabilityWeighted} = \sum_{j=1}^m\frac{\beta_{token[j]}}{borrowFactor[j]}$

for all m liability assets.Then, the probability of liquidation over the next n days is the inverse normal of \zeta, where \zeta is a z-score given by:

$\zeta = \frac{\alpha}{\sigma_n}$

Then the portfolio standard deviation for 1 day is the following:

$\sigma_1 = \sqrt{\sum_{i=1}^{n} \sum_{h=1}^{n} covariance[i][j] * proportion_i * proportion_j}$

Here "n" represents the number of tokens and the proportions are based on the tokens held in the portfolio.

For a multi-day standard deviation approximation, we multiply the 1-day standard deviation by the number of days like this:

$\sigma_n = \sigma_1\sqrt{n}$

Finally, based on the standard deviation of the portfolio, and the aggregated collateral and debt positions weighted by the supply and borrow factors of each token, we can derive the value of the wallet's liquidation buffer and use an inverse normal function to get the probability that the portfolio's position drops by that buffer value and reaches liquidation.