Here we make no probabilistic assumptions. Our view is that what happened in the past is a guide to what will happen in the future. Tomorrow’s price change will be sampled from the distribution of price changes in our historical data.

First we must value our portfolio using today’s stock prices . Next, we must calculate a vector of percentage changes.

For each of these percentage changes , we compute the difference between the current value of our portfolio and the future value our portfolio to build a sample of changes .

We then sort in order of largest to smallest, positive to negative. If, for example, our confidence level is , our estimate of VaR occurs at the cut-off point in at . of 1000 samples is 990, so we take , where is the time horizon.

## Algorithm

- Value today’s portfolio from
- for each asset:
- Calculate daily returns from historical data
- Apply all to

- Value for
- Sort ascending

## Implementation

## Sampling tomorrow’s portfolio prices

```
try {
for (String sym : strSymbols) {
Stock stock = stockHashMap.get(sym);
int stockDeltas = hashStockDeltas.get(sym);
double currentPrice = stock.getQuote().getPreviousClose().doubleValue();
double[] percentageChanges = PercentageChange.getArray(stock.getHistory());
for(int i = 0; i < percentageChanges.length; i++)
tomorrowPortfolio[i] += (percentageChanges[i] + 1) * currentPrice * stockDeltas;
}
} catch (Exception e) {
e.printStackTrace();
}
```

## Estimating VaR

```
Collections.sort(tomorrowPortfolio);
double index = (1 - Confidence) * size;
double VaR = (currentPortfolio - tomorrowPortfolio.get((int) index)) * TimeHorizon;
return VaR;
```

## Output

```
Historical Simulation
VaR: 3383.974036
```