How to handle special symbols such as GC=F in quantmod. GC=F is the symbol for gold in yahoo. Example below:
library(quantmod)
getSymbols("^GSPC") # this will return symbol GSPC and stock data
getSymbols("GC=F") # this will not work at all, returns missing values
I don't see any issue. Running the below code will return the data for the last few days. There is a missing value in there for October 4th which is consistent with the data on the yahoo page as seen here . All the missing data points are Sundays. If you want to remove these records, you can use na.exclude
or remove all the weekend days with a function.
library(quantmod)
gold <- getSymbols("GC=F", auto.assign = FALSE, from = "2020-10-01")
gold
GC=F.Open GC=F.High GC=F.Low GC=F.Close GC=F.Volume GC=F.Adjusted
2020-10-01 1884.1 1909.6 1882.5 1908.4 730 1908.4
2020-10-02 1893.9 1913.0 1893.9 1900.2 530 1900.2
2020-10-04 NA NA NA NA NA NA
2020-10-05 1898.9 1915.6 1884.7 1912.5 1360 1912.5
2020-10-06 1906.6 1918.0 1874.4 1901.1 968 1901.1
2020-10-07 1874.1 1889.8 1873.1 1883.6 50 1883.6
2020-10-08 1893.0 1893.0 1882.7 1888.6 348 1888.6
2020-10-09 1909.3 1929.1 1905.1 1919.5 348 1919.5
just removing the empty days with na.exclude
na.exclude(gold)
GC=F.Open GC=F.High GC=F.Low GC=F.Close GC=F.Volume GC=F.Adjusted
2020-10-01 1884.1 1909.6 1882.5 1908.4 730 1908.4
2020-10-02 1893.9 1913.0 1893.9 1900.2 530 1900.2
2020-10-05 1898.9 1915.6 1884.7 1912.5 1360 1912.5
2020-10-06 1906.6 1918.0 1874.4 1901.1 968 1901.1
2020-10-07 1874.1 1889.8 1873.1 1883.6 50 1883.6
2020-10-08 1893.0 1893.0 1882.7 1888.6 348 1888.6
2020-10-09 1909.3 1929.1 1905.1 1919.5 348 1919.5
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.