我一直在看Guy的quantstrat演讲(链接如下),在反复尝试重新执行代码后,我得到了一些初始错误,这些错误阻止了演讲中的大多数后续代码正常工作。
以下是代码(从讲座复制,只做了很小的重新安排):
rm(list=ls(all=TRUE)) #added this to delete memory
library(quantstrat)
library(blotter) #added this hoping it would rectify the errors
library(FinancialInstrument) #added this hoping it would rectify the errors
# initialize portfolio, accounts and orders
qs.strategy <- "qsFaber"
initPortf(qs.strategy, 'SPY', initDate = '1997-12-31')
initAcct(qs.strategy, portfolios = qs.strategy, initDate = '1997-12-31', initEq= 1e6)下面是我得到的错误:
1)
> initPortf(qs.strategy, 'SPY', initDate = '1997-12-31')
Error in exists(paste("portfolio", name, sep = "."), envir = .blotter, :
object '.blotter' not found2)
> initAcct(qs.strategy, portfolios = qs.strategy, initDate = '1997-12-31', initEq= 1e6)
Error in exists(paste("account", name, sep = "."), envir = .blotter, inherits = TRUE) :
object '.blotter' not found我不得不直接下载blotter,因为我使用的是Windows64位,但尽管抄袭了讲座中的代码,我不确定为什么我会收到这些错误。我的搜索工作表明,FinancialInstruments的一部分演变为FinancialInstrument包,但即使在清除内存并加载blotter之后,我仍然收到相同的错误。
任何帮助都将不胜感激。
链接到讲座:http://www.r-programming.org/files/quantstrat-I.pdf
发布于 2013-06-15 23:52:51
Guy Yollin的工作表是很好的学习材料,但不幸的是它们有点过时(2011)。在过去的两年中,对blotter、quantstrat和其他软件包进行了很多更改,Guy的工作表中的大部分代码将不再以这种方式运行。
就quantstrat软件包而言,您可能想看看在芝加哥举行的R/Finance 2013会议的表格;您可以在http://www.rinfinance.com/agenda/2013/workshop/Humme+Peterson.pdf上获得一份副本。
更新:盖伊·约林已经将他的幻灯片更新到了2013年8月的最新quantstrat,这些幻灯片可以在这里http://www.r-programming.org/papers获得
发布于 2013-06-16 03:31:48
blotter和quantstrat包在.GlobalEnv中存储内容(这是它们不在CRAN上的原因之一)。当您运行rm(list=ls(all=TRUE))时,您正在删除那些包希望能够在您的工作区中找到的东西。为了让一切正常工作,您必须在globalenv()中放回两个环境。运行完这两行代码后,我认为您的代码将会正常工作。
.blotter <- new.env()
.strategy <- new.env()在过去,FinancialInstrument用来在.GlobalEnv中创建.instrument环境(后来期望它存在)。几年前,我对其进行了更改,现在.instrument存储在FinancialInstrument名称空间中。由于更改是在Guy的幻灯片之后进行的,因此代码不兼容。幻灯片14-15应改为
currency("USD")
getInstrument("USD")
stock("SPY", "USD")
getInstrument("SPY")或者更紧跟他的原始代码,
get("USD", envir=FinancialInstrument:::.instrument)
get("SPY", envir=FinancialInstrument:::.instrument)通过将包级对象存储在包的名称空间中,用户可以自由地从globalenv()中删除所有内容,而不会破坏包的任何代码。
https://stackoverflow.com/questions/17120496
复制相似问题