0

I would like to look at stock price data in R at a period smaller than daily. 1minute, 5minute, or 30minute would be ideal. I have tried working with the tq_transmute command but I cannot seem to get this working.

library(quantmod)
library(tidyquant)
library(tidyverse)
library(ggplot2)

# using tidyverse to import a ticker
spy <- tq_get("spy")
spysegment <- tq_get("spy", get ="stock.prices", from ='2022-10-13', to = '2022-10-19')
str(spysegment)
view(spysegment)
# get 30minute data not daily
spy30m <- tq_get(c("spy"), get="stock.prices") %>%
  tq_transmute(select=close(),
               mutate_fun=to.period,
               period="minutes", n=30,
               col_rename = "minute_return") %>%
  ggplot(aes(date, minute_return)) +
  geom_line()
lvbx9
  • 39
  • 1
  • 8
  • have you read the documentation of [`tq_get`](https://business-science.github.io/tidyquant/reference/tq_get.html)? – Mark Jul 19 '23 at 09:44
  • ""stock.prices": Get the open, high, low, close, volume and adjusted stock prices for a stock symbol from Yahoo Finance" – Mark Jul 19 '23 at 09:45
  • Yahoo data is daily. If you want sub-day financial data, you should use a different data source – Mark Jul 19 '23 at 09:46

1 Answers1

0

The documentation of tidyquant states that get="stock.price" downloads data from Yahoo Finance, which has daily price data.

The options for getting sub-daily information using quantmod include using the Tingo API, the Alpha Vantage API, or Bloomberg. Full examples of how to use these to get sub daily stock price data can be found in the documentation.

Mark
  • 7,785
  • 2
  • 14
  • 34