R - FinancialInstrument 包在使用股票时更改符号名称

R - FinancialInstrument Package Changing Symbol Names when using stock

我目前正在使用 quantstrat/blotter 制定策略。我使用的价格数据使用数字作为证券标识符,因此这些数字是列名称以及我在 stock() 等函数中用于符号名称的名称,以便导入金融工具。然而,如下面的可重现代码所示,使用我的数据集的一小部分,每当对这些数字标识符使用 stock() 时,FinancialInstrument 包都会以一种奇怪的方式修改它们,即附加 "X" 并删除前导数字。基于此,与 FinancialInstrument 包一起使用的符号名称是否有任何限制?

structure(c(9.17000007629395, 9.17000007629395, 9.17000007629395, 
9.17000007629395, 9.17000007629395, 9.17000007629395, 41.0999984741211, 
40.7599983215332, 40.4599990844727, 40.1500015258789, 40.5299987792969, 
40.5299987792969, 41.9900016784668, 41.7449989318848, 42.0299987792969, 
41.7200012207031, 42.25, 41.7000007629395, 29.3199996948242, 
29.3199996948242, 29.3199996948242, 29.3199996948242, 29.3199996948242, 
29.3199996948242), class = c("xts", "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC", index = structure(c(1403481600, 
1403568000, 1403654400, 1403740800, 1403827200, 1404086400), tzone = "UTC", tclass = "Date"), .Dim = c(6L, 
4L), .Dimnames = list(NULL, c("10078", "10104", "10107", "10108"
)))

colnames(x)
# "10078" "10104" "10107" "10108"

for(i in colnames(x)){
  stock(i,currency="USD",multiplier=1)
}

ls_stocks()
# "X0078" "X0104" "X0107" "X0108"

乐器名称需要以字母或点开头。 instrument 函数使用 make.names 来确保这一点。如果能够通过数字找到您的乐器很重要,那么您可以将其添加为标识符。

stock("X1234", currency("USD"), identifiers=list(num=1234))
getInstrument("1234")
#primary_id :"X1234"
#currency   :"USD"
#multiplier :1
#tick_size  :0.01
#identifiers:List of 1
# ..$ num:1234
#type       :"stock"

另一种添加标识符的方法

add.identifier("X1234", id2=42)