eolymp
bolt
Try our new interface for solving problems

VaR

In economics and finance, value at risk (VaR) is a measure of how the market value of an asset or of a portfolio of assets is likely to decrease over a certain time period (usually over 1 day or 10 days) under usual conditions. It is typically used by security houses or investment banks to measure the market risk of their asset portfolios (market value at risk), but is actually a very general concept that has broad application. From Wikipedia, the free encyclopedia.

VaR has three parameters.

  • The time horizon (period) to be analyzed (i. e. the period of time over which one plans to hold the assets in the portfolio - the "holding period"). The typical holding period is 1 day, although 10 days are used, for example, to compute capital requirements under the European Capital Adequacy Directive (CAD). For some problems, even a holding period of 1 year is appropriate.

  • The confidence level at which the estimate is made. Popular confidence levels are usually 99% and 95%.

  • The unit of the currency which will be used to denominate the value at risk (VaR).

In the purposes of this problem we will use the fixed confidence level value of 95% and Berland dollar as a currency unit.

The VaR is the maximum amount at risk to be lost from an investment (under 'normal' market conditions) over a given holding period, at a particular confidence level. As such, it is the converse of shortfall probability, in that it represents the amount to be lost with a given probability, rather than the probability of a given amount to be lost.

Consider an example of trading portfolio. Its market value in Berland dollars today is known, but its market value tomorrow is not known. The investment bank holding that portfolio might report that its portfolio has a 1-day VaR of $4** million at the **95%** confidence level. This implies that (provided usual conditions will prevail over the **1** day) the bank can expect that, with a probability of **95%**, the value of its portfolio will decrease by at most **$4 million during 1 day, or, in other words, that, with a probability of 5%, the value of its portfolio will decrease by $4 million or more during 1 day.

The key thing to note is that the target confidence level (95% in the above example) is the given parameter here; the output from the calculation ($4 million in the above example) is the maximum amount at risk (the value at risk ) for that confidence level.

In the following, return means percentage change in value.

A variety of models exist for estimating VaR. Each model has its own set of assumptions, but the most common assumption is that historical market data is our best estimator for future changes. The important assumption of "variance-covariance" model (VCV ) is that risk factor returns are always (jointly) normally distributed and that the change in portfolio value is linearly dependent on all risk factor returns. There are also "historical simulation" and "Monte Carlo simulation" models, but here we will touch only the VCV model.

In the following, we will take the simple case, where the only risk factor for the portfolio is the value of the assets themselves. The following two assumptions enable to translate the VaR estimation problem into a linear algebraic problem:

  1. the portfolio is composed of the assets whose deltas are linear, more exactly: the change in the value of the portfolio is linearly dependent on (i.e. is a linear combination of) all the changes in the values of the assets, so that also the portfolio return is linearly dependent on all the asset returns;

  2. the asset returns are jointly normally distributed.

The implication of (1) and (2) is that the portfolio return is normally distributed because it always holds that a linear combination of jointly normally distributed variables is itself normally distributed.

We will use the following notation:

  • there are N assets;

  • μ[i] = expected value of the return on asset i;

  • μ[P] = expected value of the return on the portfolio;

  • σ[i] = standard deviation of the return on asset i;

  • σ[P] = standard deviation of the the return on the portfolio;

  • Vi = initial value of asset i (in currency units);

  • VP = initial value of the portfolio (in currency units);

  • wi = Vi / VP

  • w = vector of all wi (wT means transposed)

  • Σ = covariance matrix, i. e. matrix of covariances between all N assets, i. e. an N * N matrix.

The covariance between two real-valued random variables X and Y, with expected values E(X) = μ and E(Y) = υ is defined as: cov(X, Y) = E((X - μ)(Y - υ)), where E is the expected value operator. The calculation goes as follows.

prb8502.gif

The normality assumption allows us to z-scale the calculated portfolio standard deviation to the appropriate confidence level. So for the 95% confidence level VaR we get:

VaR = -VP (μ[P] - 1.644854 σ[P])

You will be given historical data of the assets prices and the quantity of each asset in the portfolio. You should calculate the value at risk for that portfolio.

Input

The first line contains integers T and N (1T10 000, 1N10). Second line contains N integers denoting the quantity of each asset in the portfolio. These integers are positive and not exceed 1000.

Each of the next T + 1 lines contains N positive numbers pricei[t] written with 2 digits after the decimal point (0tT, 1iN). The first of those lines contains today's market prices (day 0) for one unit of the corresponding asset. Next line corresponds to the previous working day (day 1), and so on. Today's prices should be used to calculate the initial value of assets. The return of asset i on day t equals to (pricei[t-1] - pricei[t]) / pricei[t].

Prices are positive and do not exceed 100 000.00.

Output

Print one number, the VaR for the given data. Your answer must be accurate up to 10-2.

Time limit 1 second
Memory limit 128 MiB
Input example #1
5 2
200 10
31.11 489.75
31.04 488.04
31.10 497.28
31.15 504.28
31.22 505.00
30.69 501.02
Output example #1
150.887934
Source 2007 Петрозаводск, Saratov for Karelia with love, Январь 28, Задача I