Guy Yollin's QuantStrat I lecture issue

最后都变了- 提交于 2019-11-30 07:43:45
Jan Humme

The sheets by Guy Yollin are excellent learning material, but unfortunately they are somewhat outdated (2011). Many changes have been made to blotter, quantstrat and other packages over the last 2 years, and much of the code in Guy's sheets will no longer run as such.

As far as the quantstrat package is concerned, you may want to take a look at the sheets from the R/Finance 2013 conference in Chicago; you can get a copy at http://www.rinfinance.com/agenda/2013/workshop/Humme+Peterson.pdf.

UPDATE: Guy Yollin has updated his slides to the latest quantstrat as of August 2013, they are available here http://www.r-programming.org/papers

The blotter and quantstrat packages store things in the .GlobalEnv (which is one reason they're not on CRAN.) When you run rm(list=ls(all=TRUE)), you are removing things, that those packages expect to be able to find in your workspace. In order for everything to work, you have to put a couple environments back in your globalenv(). After running these two lines of code, I think your code will work.

.blotter <- new.env()
.strategy <- new.env()

In the past, FinancialInstrument used to create a .instrument environment in the .GlobalEnv (and later expect it to exist). A couple years ago, I changed it so that .instrument is now stored in the FinancialInstrument namespace. Since that change came after Guy's slides, the code is not compatible. Slides 14-15 should be changed to

currency("USD")
getInstrument("USD")
stock("SPY", "USD")
getInstrument("SPY")

Or to more closely follow his original code,

get("USD", envir=FinancialInstrument:::.instrument)
get("SPY", envir=FinancialInstrument:::.instrument)

By storing package level objects in the package's namespace, the user is free to remove everything from the globalenv() without breaking any of the package's code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!