1

I am trying to pull stock price data using tq_get in tidyquant, then want to plot the current price against the 52 week range. Here is an example of what I am looking to create.

enter image description here

Basically just a visual representation of where the stock is currently trading in relation to its 52 week range. Below is the code I have begun to load in the appropriate values for TSLA. First, I am wondering if it is possible to set the "from" and "to" dates so that they constantly update to be exactly one year ago and the current date, respectively? Second, is there a ggplot or another package that might be able to generate a similar plot? I've explored boxplots, but really I need something even more simple than that, as I really only need one axis. Thanks in advance!

X <- tq_get(c("^GSPC","TSLA"),get="stock.prices",from="2019-05-04", to="2020-05-04")
TSLA <- X %>% filter(symbol == "TSLA") %>% tk_xts()
chartSeries(TSLA)
TSLAlow <- min(TSLA$close)
TSLAlow

TSLAhigh <- max(TSLA$close)
TSLAhigh

TSLAclose <- tail(X$close, n=1)
TSLAclose

TSLArange <- tibble(TSLAlow, TSLAhigh, TSLAclose)
Phil
  • 7,287
  • 3
  • 36
  • 66
  • question 1: `tq_get(c("^GSPC","TSLA"),get="stock.prices", from = Sys.Date() - 365, to=Sys.Date())` For question 2, there is not much like this in ggplot2 or in the templates. I know this is available in tools like tableau. But maybe someone can help you with this. – phiver May 05 '20 at 09:55

0 Answers0