Violins of Volatility

March 29, 2011

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

A violin plot is a combination box plot and a kernel density plot: it starts with a box plot, and adds a rotated kernel density plot to each side of the box plot. You can create violin plots with the vioplot function (from the vioplot package) package in R

When looking at the volatility of financial instruments, the financial blogger "Milk Trader" suggests Volatility Violins can be helpful. Using the getSymbols function to download VIX and SPX data from Yahoo, he provides code to compare the volatility of the two indices. As suggested by a commenter, I adapted the code to scale the SPX data to match the annualized VIX:

SPX <- getSymbols("^GSPC", auto.assign=FALSE)[,4]
SPX <- Delt(SPX, k=30)
SPX <- na.locf(SPX, na.rm=TRUE)
SPX <- abs(SPX)*sqrt(365/30)

Created by Pretty R at

and the corresponding volatility violins are below:

Follow the link below for the code to create charts like these for other symbols.

Milk Trader: Volatility Violins



To leave a comment for the author, please follow the link and comment on their blog: Revolutions. 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...

Tags: ,

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)