如何在quantmod中处理
GC=F
等特殊符号。 GC=F
是雅虎即月黄金期货合约的符号。下面的例子:
library(quantmod)
getSymbols("^GSPC") # this will return symbol GSPC and stock data
getSymbols("GC=F") # this will not work at all, returns missing values
我没有看到任何问题。运行以下代码将返回最近几天的数据。 10 月 4 日有一个缺失值,这与 yahoo 页面上的数据一致,如here所示。所有缺失的数据点都是周日。如果你想删除这些记录,你可以使用
na.exclude
或使用函数删除所有周末。
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
只需用
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