我收到错误消息:
do.call出错(粘贴(" getSymbols。",symbol.source,sep =""),列表(符号= current.symbols,: 对象'来自'找不到
当我从Georgakopoulos的R进行数量交易时运行以下代码:
library(quantstrat)
library(xts)
library(TTR)
library(FinancialInstrument)
library(quantmod)
library(blotter)
library(PerformanceAnalytics)
library(foreach)
# CHAPTER 7
# Backtesting with Quantstrat
#################
# Initial setup #
#################
# Suppresses warnings
options("getSymbols.warning4.0" = FALSE)
# Do some house cleaning
rm(list = ls(.blotter), envir = .blotter)
# Set the currency and the timezone
currency('USD')
Sys.setenv(TZ = "UTC")
# Define symbols of interest
symbols <- c("XLB", #SPDR Materials sector
"XLE", #SPDR Energy sector
"XLF", #SPDR Financial sector
"XLP", #SPDR Consumer staples sector
"XLI", #SPDR Industrial sector
"XLU", #SPDR Utilities sector
"XLV", #SPDR Healthcare sector
"XLK", #SPDR Tech sector
"XLY", #SPDR Consumer discretionary sector
"RWR", #SPDR Dow Jones REIT ETF
"EWJ", #iShares Japan
"EWG", #iShares Germany
"EWU", #iShares UK
"EWC", #iShares Canada
"EWY", #iShares South Korea
"EWA", #iShares Australia
"EWH", #iShares Hong Kong
"EWS", #iShares Singapore
"IYZ", #iShares U.S. Telecom
"EZU", #iShares MSCI EMU ETF
"IYR", #iShares U.S. Real Estate
"EWT", #iShares Taiwan
"EWZ", #iShares Brazil
"EFA", #iShares EAFE
"IGE", #iShares North American Natural Resources
"EPP", #iShares Pacific Ex Japan
"LQD", #iShares Investment Grade Corporate Bonds
"SHY", #iShares 1-3 year TBonds
"IEF", #iShares 3-7 year TBonds
"TLT" #iShares 20+ year Bonds)
# SPDR ETFs first, iShares ETFs afterwards
if(!"XLB" %in% ls()) {
# If data is not present, get it from yahoo
suppressMessages(getSymbols(symbols, from = from, to = to, src = "yahoo", adjust = TRUE))}
我在两台不同的机器上运行它。这个确切的代码用于处理一个。现在他们都不能在不产生这个错误的情况下运行。谢谢。
答案 0 :(得分:2)
您必须在代码中定义from
和to
变量。在我的情况下,以下运行非常顺利:
if(!"XLB" %in% ls()) {
# If data is not present, get it from yahoo
suppressMessages(getSymbols(symbols, from = "1900-01-01",
to = "2017-03-21", src = "yahoo",
adjust = TRUE))
}
输出
[1] "XLB" "XLE" "XLF" "XLP" "XLI" "XLU" "XLV" "XLK" "XLY" "RWR" "EWJ" "EWG"
[13] "EWU" "EWC" "EWY" "EWA" "EWH" "EWS" "IYZ" "EZU" "IYR" "EWT" "EWZ" "EFA"
[25] "IGE" "EPP" "LQD" "SHY" "IEF" "TLT"