我正在尝试使用bt.prep()
函数格式化数据。有人可以解释为什么这会失败,并希望如何解决它? Link to github repo
library(quantmod)
#Systematic Investor Toolbox
sit = getURLContent('https://github.com/systematicinvestor/SIT/raw/master/sit.gz', binary=TRUE, followlocation = TRUE, ssl.verifypeer = FALSE)
con = gzcon(rawConnection(sit, 'rb'))
source(con)
close(con)
data <- getSymbols("USD/EUR",src="oanda",env=NULL)
bt.prep(data, align='remove.na')
错误是:
Error in b[[i]] : attempt to select more than one element In addition: Warning message:
In merge.xts(..., all = all, fill = fill, suffixes = suffixes) :
NAs introduced by coercion
答案 0 :(得分:0)
@ Rilcon42,
我认为您需要在调用getSymbols ...
之前创建new.env()
library(quantmod)
library(RCurl)
#Systematic Investor Toolbox
sit = getURLContent('https://github.com/systematicinvestor/SIT/raw/master/sit.gz', binary=TRUE, followlocation = TRUE, ssl.verifypeer = FALSE)
con = gzcon(rawConnection(sit, 'rb'))
source(con)
close(con)
tickers = spl('USD/EUR')
dataRepo <- new.env()
getSymbols(tickers, src = "oanda", env = dataRepo, auto.assign = T)
bt.prep(dataRepo, align='remove.na')
head(dataRepo$USDEUR,6)
结果:
> library(quantmod)
> library(RCurl)
>
> #Systematic Investor Toolbox
> sit = getURLContent('https://github.com/systematicinvestor/SIT/raw/master/sit.gz', binary=TRUE, followlocation = TRUE, ssl.verifypeer = FALSE)
> con = gzcon(rawConnection(sit, 'rb'))
> source(con)
> close(con)
>
> tickers = spl('USD/EUR')
> dataRepo <- new.env()
> getSymbols(tickers, src = "oanda", env = dataRepo, auto.assign = T)
[1] "USDEUR"
> bt.prep(dataRepo, align='remove.na')
>
> head(dataRepo$USDEUR,6)
USD.EUR
2015-01-11 0.8445
2015-01-12 0.8448
2015-01-13 0.8467
2015-01-14 0.8489
2015-01-15 0.8535
2015-01-16 0.8621