How can I calculate the stock volatility in percentage?
Do i have to use sd() function without any other calculation ?
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
- The above code should really be using prices adjusted for corporate actions (dividends, splits etc).
250is the (approximate) number of trading days in a year.