Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotting SPX vs. VIX using quantmod in R

Tags:

r

quantmod

I just got introduced to quantmod, and looked at examples here http://www.r-chart.com/2010/06/stock-analysis-using-r.html I tried the following code,

getSymbols(c("^GSPC","^VIX"))
head(as.xts(merge(GSPC,VIX)))
chartSeries(c(GSPC, VIX), subset='last 3 months')

but the graph was completely out-of-scale, so I hope some of the experts on this forum can show me how to plot this correctly.

like image 343
user1155299 Avatar asked Mar 15 '26 11:03

user1155299


1 Answers

Try this:

chart_Series(GSPC)
add_Series(OHLC(VIX)+1000,on=1)

You need to use OHLC to remove the volume from VIX, since it's always zero and seems to hose up the automatic ylim calculation. I also added 1000 to make the levels of the two series to be a bit closer together.

like image 61
Joshua Ulrich Avatar answered Mar 18 '26 01:03

Joshua Ulrich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!