Value at Risk (VaR) for Algorithmic Trading Risk Management
Estimating the risk of loss to an algorithmic trading strategy, or portfolio of strategies, is of extreme importance for long-term capital growth. Many techniques for risk management have been developed for use in institutional settings. One technique in particular, known as Value at Risk or VaR, will be the topic of this article.
We will be applying the concept of VaR to a single strategy or a set of strategies in order to help us quantify risk in our trading portfolio. The definition of VaR is as follows:
VaR provides an estimate, under a given degree of confidence, of the size of a loss from a portfolio over a given time period.
In this instance “portfolio” can refer to a single strategy, a group of strategies, a trader’s book, a prop desk, a hedge fund or an entire investment bank. The “given degree of confidence” will be a value of, say, 95% or 99%. The “given time period” will be chosen to reflect one that would lead to a minimal market impact if a portfolio were to be liquidated.
For example, a VaR equal to 500,000 USD at 95% confidence level for a time period of a day would simply state that there is a 95% probability of losing no more than 500,000 USD in the following day. Mathematically this is stated as:
P(L≤−5.0×10^5)=0.05 Or, more generally, for loss L exceeding a value VaR with a confidence level c we have:
P(L≤−VaR)=1−c The “standard” calculation of VaR makes the following assumptions:
VaR is pervasive in the financial industry, hence you should be familiar with the benefits and drawbacks of the technique. Some of the advantages of VaR are as follows:
However, VaR is not without its disadvantages:
VaR should not be used in isolation. It should always be used with a suite of risk management techniques, such as diversification, optimal portfolio allocation and prudent use of leverage.
As of yet we have not discussed the actual calculation of VaR, either in the general case or a concrete trading example. There are three techniques that will be of interest to us. The first is the variance-covariance method (using normality assumptions), the second is a Monte Carlo method (based on an underlying, potentially non-normal, distribution) and the third is known as historical bootstrapping, which makes use of historical returns information for assets under consideration.
In this article we will concentrate on the Variance-Covariance Method and in later articles will consider the Monte Carlo and Historical Bootstrap methods.
Consider a portfolio of P dollars, with a confidence level c. We are considering daily returns, with asset (or strategy) historical standard deviation σ and mean μ. Then the daily VaR, under the variance-covariance method for a single asset (or strategy) is calculated as:
P−(P(α(1−c)+1)) Where α is the inverse of the cumulative distribution function of a normal distribution with mean μ and standard deviation σ.
We can use the SciPy and pandas libraries from Python in order to calculate these values. If we set P=106 and c=0.99, we can use the SciPy ppf method to generate the values for the inverse cumulative distribution function to a normal distribution with μ and σ obtained from some real financial data, in this case the historical daily returns of CitiGroup (we could easily substitute the returns of an algorithmic strategy in here):
# var.py import datetime import numpy as np import pandas.io.data as web from scipy.stats import norm def var_cov_var(P, c, mu, sigma): """ Variance-Covariance calculation of daily Value-at-Risk using confidence level c, with mean of returns mu and standard deviation of returns sigma, on a portfolio of value P. """ alpha = norm.ppf(1-c, mu, sigma) return P - P*(alpha + 1) if __name__ == "__main__": start = datetime.datetime(2010, 1, 1) end = datetime.datetime(2014, 1, 1) citi = web.DataReader("C", 'yahoo', start, end) citi["rets"] = citi["Adj Close"].pct_change() P = 1e6 # 1,000,000 USD c = 0.99 # 99% confidence interval mu = np.mean(citi["rets"]) sigma = np.std(citi["rets"]) var = var_cov_var(P, c, mu, sigma) print "Value-at-Risk: $%0.2f" % var
The calculated value of VaR is given by:
Value-at-Risk: $56510.29 VaR is an extremely useful and pervasive technique in all areas of financial management, but it is not without its flaws. We have yet to discuss the actual value of what could be lost in a portfolio, rather just that it may exceed a certain amount some of the time.
In follow-up articles we will not only discuss alternative calculations for VaR, but also outline the concept of Expected Shortfall (also known as Conditional Value at Risk), which provides an answer to how much is likely to be lost.