[Blotter-commits] r711 - pkg/quantstrat/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Aug 6 16:57:47 CEST 2011
Author: braverock
Date: 2011-08-06 16:57:46 +0200 (Sat, 06 Aug 2011)
New Revision: 711
Modified:
pkg/quantstrat/R/initialize.R
Log:
- more detail to the shell of initialization functionality
Modified: pkg/quantstrat/R/initialize.R
===================================================================
--- pkg/quantstrat/R/initialize.R 2011-08-06 14:45:03 UTC (rev 710)
+++ pkg/quantstrat/R/initialize.R 2011-08-06 14:57:46 UTC (rev 711)
@@ -4,7 +4,38 @@
#
###############################################################################
+initStrategy <- function(strategy=NULL, portfolio=NULL, symbols=NULL, getSymbols=TRUE, initPortf=TRUE, initAcct=TRUE, initOrders=TRUE, unique=TRUE) {
+ # basic idea is to do all the common set-up stuff
+ # create portfolio, account, orderbook
+
+ # additionally, we should put an initialization slot in the strategy and have
+ # an add.init function (like add.indicator, etc) that could have
+ # arbitrary user-defined initialization functions added to the initialization steps
+
+}
+add.init <- function(strategy, name, arguments, parameters=NULL, label=NULL, ..., enabled=TRUE, indexnum=NULL, store=FALSE) {
+ if(!is.strategy(strategy)) stop("You must pass in a strategy object to manipulate")
+ tmp_init<-list()
+ tmp_init$name<-name
+ if(is.null(label)) label = paste(name,"ind",sep='.')
+ tmp_init$label<-label
+ tmp_init$enabled=enabled
+ if (!is.list(arguments)) stop("arguments must be passed as a named list")
+ tmp_init$arguments<-arguments
+ if(!is.null(parameters)) tmp_init$parameters = parameters
+ if(length(list(...))) tmp_init<-c(tmp_init,list(...))
+
+ if(!hasArg(indexnum) | (hasArg(indexnum) & is.null(indexnum))) indexnum = length(strategy$inits)+1
+ tmp_init$call<-match.call()
+ class(tmp_init)<-'strat_init'
+
+ strategy$inits[[indexnum]]<-tmp_init
+
+ if (store) assign(strategy$name,strategy,envir=as.environment(.strategy))
+ else return(strategy)
+}
+
###############################################################################
# R (http://r-project.org/) Quantitative Strategy Model Framework
#
More information about the Blotter-commits
mailing list