Sorry, that's probably quite a bunch of silly questions, but I just got lost a bit and need to dot all the i's and cross some t's :).

Let's say we have a series of returns (like this one we may get in R):

A <- AAPL[,6]["2007"]

Then, if I want to know how much could I lose with the probability 95%, I need to calculate VaR for this 5% quantile, OK? Again, in R first I need to calculate the quantile: quantile(A, 0.05), am I right? The result in this particular series would be 11.485. Which means that with the 95% probability I won't go lower than 11.485, is that right? Thus, my VaR would be then mean(A) - 11.485 = 5.8 or 33.56%, wouldn't it?

In other words, calculating a quantile for a given probability in this particular case gives us a lower boundary corresponding to a series in question, doesn't it? And that's how quantiles are measured, it's not a percentage, but boundaries which with a certain probability limit values of a series?

Now, to the second part :)

While reading the article on Wolfram Alpha, I've noticed that among other things, when asked on a certain stock, WA among other information, also tries to give some predictions. Which are actually quantiles, aren't they? E.g., with the 95% probability they say that the stock in question in one month time won't go lower than 92.67 - and this price, 92.67 would be the 5% quantile for that particular stock during that particular period, right?

If so, now to the most interesting bit: as you may see, they also draw some hypothetical colored graphs there, using log normal random walks, as they say below. But with log normal random walks values one will get may be very different, is that so? Thus, they probably calculate quite a lot of such walks, like hundreds or thousands, and then bootstrap them? If so, then how is that done with R? What is the usual algorithm? Needful libraries? Where should I look to learn more?

Not that I'm interested in predicting stocks, of course :), but I just very much like the idea of trying to predict a distribution...

Thank you.


1 Answer 1


Not too sure about the second part of your questions but as far as VaR, R has some pretty neat functions. First I took you subset A and converted it to discrete returns since using actual prices for VaR may be a bit harder to interpret.

# Load PerformanceAnalytics for VaR & Calculating Returns

# Calculate Returns
a <- CalculateReturns(A, method=c("discrete"))

# Calculate VaR at 95% confidence
VaR(a, p=0.95)

This results in a VaR: -0.03399548. Put simply, One can expected to lose approximately 3.40% on any given day.

Here is a subset of the the function's description.

VaR is an industry standard for measuring downside risk. For a return series, VaR is defined as the high quantile (e.g. ~a 95 quantile) of the negative value of the returns. This quantile needs to be estimated...

Take a look at the daily returns and the VaR level:

abline(h=VaR(a,p=0.95), col='red')

You see that not many returns fall below the red line which satisfies the 95% confidence

  • $\begingroup$ No worries, glad it is helpful. If you think my answer satisfies your question, you can accept it. @JohnDoe $\endgroup$
    – Rime
    Commented Feb 21, 2015 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.