[英]How to hand special symbols such as GC=F in quantmod
How to handle special symbols such as GC=F in quantmod.如何在quantmod中处理GC=F等特殊符号。 GC=F is the symbol for gold in yahoo.
GC=F 是雅虎中的黄金符号。 Example below:
下面的例子:
library(quantmod)图书馆(quantmod)
getSymbols("^GSPC") # this will return symbol GSPC and stock data getSymbols("^GSPC") # 这将返回符号 GSPC 和股票数据
getSymbols("GC=F") # this will not work at all, returns missing values getSymbols("GC=F") # 这根本不起作用,返回缺失值
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 .
那里有一个 10 月 4 日的缺失值,这与这里看到的雅虎页面上的数据一致。 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.如果要删除这些记录,可以使用
na.exclude
或使用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
just removing the empty days with na.exclude
只需使用
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.