Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Trying to find volatility in R but my code won't work

$
0
0

I'm using this following code to find the volatility of Tesla:

library(quantmod)
library(ggplot2)

Tesla <-  getSymbols("TSLA", src = "yahoo", from = "2014-10-01", to = "2019-11-25", auto.assign = FALSE)

vol.tesla <- volatility(Tesla[ ,6])


graf_vol_tesla <- ggplot(vol.tesla, aes(x = index(vol.tesla), y = vol.tesla))+ geom_line(color = "violetred4") +
  ggtitle("volatility Tesla") + xlab("Date") + ylab("Volatility") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_x_date(date_labels = "%b %y", date_breaks = "9 months")

graf_vol_tesla

However, it comes this as the output instead of the image. Anybody knows how to fix it? Thanks in advance!

'Don't know how to automatically pick scale for object of type xts/zoo. Defaulting to continuous. Error: Invalid input: date_trans works with objects of class Date only'


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>