[R-SIG-Finance] An easy way to run the quantstrat faber.R demo within an R function?

Andre Mikulec andre_mikulec at hotmail.com
Tue Sep 9 15:13:11 CEST 2014


 Hi,I am trying to run the faber.R demo within a function
Here is the urlhttps://r-forge.r-project.org/scm/viewvc.php/pkg/quantstrat/demo/faber.R?view=markup&root=blotter
Within a function, when the 'faber.R code reaches initPortf() the following error is thrown.
Error in exists(paste("portfolio", name, sep = "."), envir = .blotter,  :   object '.blotter' not found
# what I have done to fix is insert the following code # and tested running   # within a function  # within a lexical function  # within R studio ( within a lexical function )
# just after# require(quantstrat) call# required ( If I am running in a function )if(!is.null(sys.call(sys.parent()))) {  if (!exists('.blotter' , envir=.GlobalEnv ))  { .GlobalEnv$.blotter   <- new.env() }   if (!exists('.strategy', envir=.GlobalEnv ))  { .GlobalEnv$.strategy  <- new.env() } }  # just after# getSymbols( . . . ) call# optional: ( If I am running in a function )# does not affect the program ( but for consistency if nothing else )# note: .getSymbols is not an environmentif(!is.null(sys.call(sys.parent()))) {  .GlobalEnv$.getSymbols <- .getSymbols}
# just after # assign(symbol,x) call# required ( If I am running in a function )if(!is.null(sys.call(sys.parent()))) {  assign(symbol,x, envir = .GlobalEnv)}
# RStudio # surrounding any dev() OR chart.#() calls# dev() # Only one RStudio graphics device is permitted# chart # RStudio margins errorif (!any(search() %in% "tools:rstudio")) { # ...}
# Does any other easier way exist, so I do not have to modify# so much code?
Thanks,Andre MikulecAndre_Mikulec at Hotmail.com
 		 	   		   		 	   		  
	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list