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()
The documentation of
tidyquantstates thatget="stock.price"downloads data from Yahoo Finance, which has daily price data.The options for getting sub-daily information using
quantmodinclude 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.