I'm attempting to export stock price data from the R program using the "quantmod" package. It provides me with data at a daily frequency, but I need to change it to a frequency of 10 minutes or 30 minutes. Unfortunately, I have not been successful in doing so. i tried the following code
`library(quantmod)
# symbol
symbol <- "GC=F"
# time range (last 100 days)
start_date <- Sys.Date() - 100
end_date <- Sys.Date()
getSymbols(symbol, from = start_date, to = end_date, interval = "10 mins")
gold_data <- Cl(get(symbol))
plot(gold_data)`
You need a new-ish version (from GitHub) but this should be on CRAN "soon" too.
> GC <- getSymbols("GC=F", periodicity="30 minutes", auto.assign=FALSE)
Warning messages:
1: In doTryCatch(return(expr), name, parentenv, handler) :
Only a maximum of 7 days is allowed for querying intraday datadata from 'yahoo'. Setting `from` to '2023-08-14'.
2: GC=F contains missing values. Some functions will not work if objects contain missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> head(GC)
GC=F.Open GC=F.High GC=F.Low GC=F.Close GC=F.Volume
2023-08-13 20:00:00 1945.6 1945.7 1943.0 1943.4 1270
2023-08-13 20:30:00 1943.3 1943.7 1942.5 1943.0 1254
2023-08-13 21:00:00 1943.0 1944.4 1942.2 1943.0 2751
2023-08-13 21:30:00 1943.0 1945.0 1942.2 1943.5 1545
2023-08-13 22:00:00 1943.4 1943.9 1942.2 1943.3 823
2023-08-13 22:30:00 1943.2 1944.6 1943.0 1943.8 649
Warning message:
object timezone (America/New_York) is different from system timezone (America/Chicago)
NOTE: set 'options(xts_check_TZ = FALSE)'to disable this warning
This note is displayed once per session
>
As you see in the message, only up to 7 days can be retrieved for intra-day data. On the other hand it allows minute data so you can grow some intra-day archives on a rolling-forward basis if you archive the snapshots locally.