How can I calculate the stock volatility in percentage? Do i have to use sd() function without any other calculation ?
Thanks
You're looking for the standard deviation of log returns, appropriately annualized and converted to percentage (i.e. multiplied by 100).
Here is an example of computing annual vol from daily prices:
library(tseries)
data <- get.hist.quote('VOD.L')
price <- data$Close
ret <- log(lag(price)) - log(price)
vol <- sd(ret) * sqrt(250) * 100
Notes:
250
is the (approximate) number of trading days in a year.NA
s in ret
, the last line won't work unless you use sd(ret, na.rm=TRUE)
.
$\endgroup$
Commented
Sep 23, 2018 at 17:24
When volatility is described as a percentage, that means it's being given as a fraction of the mean. So if the standard deviation of the price is 10 and the mean is 100, then the price could be described as 10% volatile.
In R terms, this would mean:
vol_percent = sd(price) / mean(price)
EDIT: This could also have been easily found on the Wikipedia article for volatility.
BNaul's answer is probably not the one you're looking for. If you want to calculate Black-Scholes style volatility, you need to calculate an annualized volatility of log-returns. That means, calculate the log return series $\ln(s_t/s_{t-1})$ for each $t$, take the standard deviation, and then adjust it by the square root of time to obtain the annualized figure. This volatility can be used in pricing models that require Black Scholes vol.
The stock return volatility is not observable, we can only estimate it. I'm assuming that you mean historical volatility, because there's also implied volatility which is estimated from options on stocks.
There are several ways of estimating it. For instance, look at this paper "MEASURING HISTORICAL VOLATILITY". Start with the simplest method, which they call "Close-to-close", it's similar to Classical method in Bloomberg terminal ("CLV"). It's always a good idea to check your results against Bloomberg. If you have access to the terminal, then get the document describing how they do it exactly.