How to Measure Position Risk - An Introduction to the VaR Method

in fmz •  9 months ago 

Controlling risk is a skill that every investor needs to learn. With the rapidly changing and evolving cryptocurrency market, algorithmic traders need to focus on risk management especially. This is because algorithmic trading often executes trades automatically based on historical data and statistical models, which may quickly become inaccurate in fast-moving markets. Therefore, effective risk management strategies are crucial for protecting investors' capital.

Among many risk management tools, Value at Risk (VaR) is a widely used measure of risk. It can help investors predict the maximum loss that might occur under normal market conditions in their portfolio. VaR quantifies risk into a single number, simplifying the expression of risk and allowing investors to understand potential losses intuitively.

The Role of VaR

VaR, or "Value at Risk", is used to quantify the maximum possible loss that can be endured within a certain period of time, according to a certain confidence level. In other words, it tells investors or risk managers: "Under normal market conditions, how much money is within the 'safe' range and will not be lost tomorrow." For example, if the 1-day 99% VaR of a cryptocurrency portfolio is $10,000, it means that in 99% of cases we expect the loss in one day will not exceed $10,000.

Advantages

  1. Easy to understand : For example, the 1-day 95% VaR of a digital currency portfolio is $5000, which means there is a 95% confidence that the loss of the portfolio within one day will not exceed $5000. Quantifying complex risks into an intuitive number makes it easy for non-professionals to understand. Of course, it's inevitably to have some misleading aspects.

  2. Relatively standard : Suppose there are two portfolios A and B, with A's 1-day 95% VaR being $3000 and B's being $6000. This implies that under normal market conditions, A's risk is lower than B's. Even if these two portfolios contain different assets, we can compare their risk levels directly. Correspondingly, we can also judge the level of investment; if both strategies A and B have earned $6000 in the past month but A's average and maximum VaR values are significantly lower than B's, then we could consider strategy A as better, since it achieves higher returns at a lower risk level.

  3. Decision-making tool : Traders might use VaR to decide whether or not to add a new asset to their portfolio. If adding an asset increases the VaR value significantly, then it may suggest that the added asset's risk does not match with the portfolio's acceptable risk level.

Disadvantages

  1. Ignoring tail risk : If a portfolio's 1-day 99% VaR is $10,000, the loss in the extreme 1% scenario could far exceed this value. In the field of digital currency, black swan events are frequent and extreme situations can exceed most people's expectations, because VaR does not consider tail events.

  2. Assumption limitations : The parameter VaR often assumes that asset returns are normally distributed, which is rarely the case in real markets, especially in digital currency markets. For example, suppose a portfolio only contains Bitcoin. We use the parameter VaR and assume that Bitcoin's return is normally distributed. However, in reality, Bitcoin's rate of return may experience large jumps during certain periods and exhibit significant volatility clustering phenomena. If there has been high volatility over the past week, the probability of noticeable volatility in the following period will increase significantly. This can lead to an underestimation of risk by normal distribution models. Some models take this issue into account such as GARCH etc., but we won't discuss them here.

  3. Historical dependence : The VaR model relies on historical data to predict future risks. However, past performance does not always indicate future situations, especially in rapidly changing markets like the digital currency market. For example, if Bitcoin has been very stable over the past year, a historical simulation might predict a very low VaR. However, if there is a sudden regulatory change or market crash, past data will no longer be an effective predictor of future risk.

Methods of Calculating VaR

There are mainly three methods to calculate VaR: Parametric method (Variance-Covariance Method): This assumes that the rate of return follows a certain distribution (usually normal distribution), and we use the mean and standard deviation of the rate of return to calculate VaR. Historical Simulation Method: It makes no assumptions about the distribution of returns, but uses historical data directly to determine potential loss distributions. Monte Carlo Simulation: It uses randomly generated price paths to simulate asset prices and calculates VaR from them.

The Historical Simulation Method utilizes past price changes directly to estimate possible future losses. It does not need any assumptions about profit distribution, making it suitable for assets with unknown or abnormal profit distributions, such as digital currencies.

For example, if we want to calculate 1-day 95% VaR for a Bitcoin spot position, we can do this:

  1. Collect the daily returns of Bitcoin over a certain period (for example, 100 days).
  2. Calculate the portfolio return rate each day, which is the return rate of each asset multiplied by its weight in the portfolio.
  3. Sort these 100 days of portfolio returns from low to high.
  4. Find the data point at the 5% mark (because we are calculating 95% VaR). The point represents the loss rate on the best day out of worst five days in past 100 days.
  5. Multiply the return by total value held, and that's your one-day 95% VaR.

The following is a specific code that has obtained data from the past 1000 days, calculating that the current VaR for holding one BTC spot is 1980 USDT.

import numpy as np
import requests

url = 'https://api.binance.com/api/v3/klines?symbol=%s&interval=%s&limit=1000'%('BTCUSDT','1d')
res = requests.get(url)
data = res.json()

confidence_level = 0.95
closing_prices = [float(day[4]) for day in data]
log_returns = np.diff(np.log(closing_prices))
VaR = np.percentile(log_returns, (1 - confidence_level) * 100)
money_at_risk = VaR * closing_prices[-1] * 1

print(f"VaR at {confidence_level*100}% confidence level is {money_at_risk}")

Calculating VaR Considering Correlation

When calculating the VaR of a portfolio containing multiple assets, we must consider the correlation between these assets. If there is a positive correlation in price changes between assets, then the risk of the portfolio will increase; if it's negatively correlated, then the risk of the portfolio will decrease.

When using historical simulation method to calculate VaR considering correlation, we need to collect not only each individual asset's historical returns, but also consider their joint distribution. In practice, you can use the historical returns of your portfolio for sorting and calculation directly, because these returns already implicitly include inter-asset correlations. In cryptocurrency markets, correlation is especially important with BTC essentially leading market trends. If BTC rises bullishly, other cryptocurrencies are likely to rise as well; if BTC rapidly surges or plummets due to quickly changing market, this could cause significant short-term increases in correlation - something that is particularly common during extreme market events. Therefore, historical simulation method is a useful tool when considering digital currency investment portfolios' VaR calculations. It doesn't require complex statistical models - just effective historical data - and naturally includes inter-asset correlations.

For example: holding 1 long position on BTC and 10 short positions on ETH – following our previous method – we can calculate that 10 ETH short positions have a VaR of 1219 USDT. When combining these two types of assets into one portfolio, here's how you would calculate its combined VaR:

confidence_level = 0.95
btc_closing_prices = np.array([float(day[4]) for day in btc_data])
eth_closing_prices = np.array([float(day[4]) for day in eth_data])
btc_log_returns = np.diff(np.log(btc_closing_prices))
eth_log_returns = np.diff(np.log(eth_closing_prices))

log_returns = (1*btc_log_returns*btc_closing_prices[1:] - 10*eth_log_returns*eth_closing_prices[1:])/(1*btc_closing_prices[1:] + 10*eth_closing_prices[1:])
VaR = np.percentile(log_returns, (1 - confidence_level) * 100)
money_at_risk = VaR * (btc_closing_prices[-1] * 1 + eth_closing_prices[-1]*10)

print(f"VaR at {confidence_level*100}% confidence level is {money_at_risk}")

The result is 970 USDT, which means the risk of this combination is lower than holding the respective assets separately. This is because BTC and ETH markets have a high correlation, and the hedging effect of long-short position combinations serves to reduce risk.

Summary

This article will introduce a highly adaptive risk assessment method, namely the application of Historical Simulation in calculating VaR, as well as how to consider asset correlations to optimize risk prediction. Through specific examples from the digital currency market, it explains how to use historical simulation to assess portfolio risks and discusses methods for calculating VaR when asset correlations are significant. With this method, algorithmic traders can not only estimate their maximum loss in most situations, but also be prepared for extreme market conditions. This allows them to trade more calmly and execute strategies accurately.

From: https://blog.mathquant.com/2023/11/03/how-to-measure-position-risk-an-introduction-to-the-var-method.html

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!