Looking out for volatility

June 26, 2013

(This article was first published on Trading and travelling and other things » R, and kindly contributed to R-bloggers)

Let’s do an easy experiment. Lets caluclate the 25-day rolling volatility of the S&P 500 from 2007 onwards.

1-Get the data:

2-Run the volatility function from the package TTR (comes along with quantmod):
#n=25 means we want 25 day rolling volatility. N=252 means we are taking a year as 252 days. calc=’close’ indicates that we want to calculate Close to Close volatility. If you look at the help page for the volatility function, there are several different calc=” parameters available.

3-We can now plot this using chartSeries(vol). Notice the huge spike in volatility in 2008.


To leave a comment for the author, please follow the link and comment on their blog: Trading and travelling and other things » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)