[Blotter-commits] r693 - pkg/quantstrat/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 22 01:22:53 CEST 2011


Author: cyrforge
Date: 2011-07-22 01:22:53 +0200 (Fri, 22 Jul 2011)
New Revision: 693

Modified:
   pkg/quantstrat/R/parameters.R
Log:
Add comments and clean up.

Modified: pkg/quantstrat/R/parameters.R
===================================================================
--- pkg/quantstrat/R/parameters.R	2011-07-21 23:00:07 UTC (rev 692)
+++ pkg/quantstrat/R/parameters.R	2011-07-21 23:22:53 UTC (rev 693)
@@ -277,8 +277,14 @@
 #' 
 #' Given a parameter distribution object generated by setParameterDistribution function, 
 #' generate parameter sets and test each set on specified strategy. 
-#'  
 #' 
+#' In the returned Object$:
+#' eachRun	contains the details of test run with each parameter set.
+#' paramTable	is parameter samples used, in a table for print.
+#' paramConstrainTable	is the constraints apply to the parameters, in a table for print.
+#' parameterDistribution	is the parameter distribution passed in as argument.
+#' parameterConstrains	 is the constraints apply to the parameters, passed in as argument.
+#' 
 #' @param strategy name of the strategy to apply paramters to.
 #' @param portfolios name of the portfolio to apply to.
 #' @param parameterPool a paramter distribution object that created by setParameterDistribution function, which includes all the parameter legal values and distribution/weights.
@@ -394,8 +400,8 @@
 			
 			iparamTable<-unique(iparamTable)
 			
-			print("nnnnnnnnnnnnnnnnnnnnnnn")
-			print(nrow(iparamTable))
+#			print("nnnnnnnnnnnnnnnnnnnnnnn")
+#			print(nrow(iparamTable))
 			
 			if (nrow(iparamTable)<tsampleSize)
 			{
@@ -425,10 +431,7 @@
 	print(psize)
 	
 	
-	#	
 	
-	
-	#for (i in 1:nrow(paramTable))
 	instruments<-as.list(.instrument)
 	getSymbols<-as.list(.getSymbols)
 	blotter<-as.list(.blotter)
@@ -437,56 +440,36 @@
 	symbols<-names(.getSymbols)
 	
 	testPackListPRL<-foreach (i = 1:psize, .export=c('instruments',symbols,'getSymbols','blotter','tmp_strategy'),.verbose=TRUE) %dopar% 
-			#TODO check %dopar problem updateportf
-			{								
+			
+			{
+#				library(blotter)
+#				require(FinancialInstrument)
+				require(quantstrat)
+				
+				#Pass enviorments needed.
 				.instrument<-as.environment(instruments)
 				.getSymbols<-as.environment(getSymbols)
 				.blotter<-as.environment(blotter)
 				
-				length(instruments$wer)
+				#Unpack symbols to worker. change later.
+				#seems need to go through assign, rather than just .export the names...
 				
-			#Unpack symbols to worker. change later.
-			#seems need to go through assign, rather than just .export the names...
-
-			for (sym in symbols) {
-				assign(sym, eval(as.name(sym)), .GlobalEnv)
-			}
-
-#			
-#			assign('AAPL',AAPL,.GlobalEnv)
-#				length(AAPL)
-#				length(.getSymbols$AAPL)
-#				
+				for (sym in symbols) {
+					assign(sym, eval(as.name(sym)), .GlobalEnv)
+				}
 				
-				
-				library(blotter)
-				require(FinancialInstrument)
-				require(quantstrat)
-				
-				#Pass values to each process, for parallel execution.
-#				currency('USD')
-#				stock(stock.str,currency='USD',multiplier=1)# for .instrument
-#				
-#				getSymbols('IBM',from=initDate)
-				
-				
-				#Create a copy of strategy object.	
+				#Create a copy of strategy object, so not to lock up on the sameone.
 				PLtmp_strategy<-tmp_strategy
 				
-				#Start extract parameter from table.	
+				#Extract parameter from table and construct PLtmp_strategy.
 				for (j in 1:ncol(paramTable)){
 					
 					tmp_arg<-parameterPool[[j]]$distribution[1] #Just get the list form with name
 					#tmp_arg<-list(tmp_argName=paramTable[i,j])
 					tmp_arg[[1]]<-paramTable[i,j]
 					
-					
-					#print(tmp_arg)
-					
 					tmp_index<-parameterPool[[j]]$indexnum
 					
-					
-					
 					switch(parameterPool[[j]]$type,
 							'indicator'={
 								#merge.list uses another package. PLtmp_strategy$indicators[[tmp_index]]$arguments<-merge.list(targ1,tmp_arg)
@@ -569,15 +552,8 @@
 #Initial portfolio for each test		
 				#######################################################################################
 				
-				
-#TODO will move out later, as parameter or put in a obj of TestPack.
-				#initDate='2010-12-31'
-				#initEq=1000000
-				
-				
 				testPack$portfolio.st=paste(portfolios,'t',i,sep='.')
 				testPack$account.st=paste(portfolios,'t',i,sep='.')
-#		
 				
 				rmpstr=paste('portfolio',testPack$portfolio.st,sep=".")
 				rmastr=paste('account',testPack$account.st,sep=".")
@@ -588,10 +564,7 @@
 				
 				print('Initial portf')
 				
-				
-				
-#			try({})
-				
+				#some time even exist, can't remove, why?
 				try(rm(paste("order_book",portfolio.st,sep='.'),pos=.strategy),silent=TRUE)
 				try(rm(paste("account",portfolio.st,sep='.'),paste("portfolio",portfolio.st,sep='.'),pos=.blotter),silent=TRUE)
 				
@@ -633,12 +606,6 @@
 				
 				testPack$stats<-tradeStats(Portfolios=testPack$portfolio.st)
 				
-				#TODO combine the stats outside the foreach loop.
-				#length(werqewr)
-				
-				
-# replaced -- testPackList[[i]]<-testPack
-				#testPackList[[paste(testPack$portfolio.st)]]<-testPack
 				return(testPack)
 				
 			}	# Loop i
@@ -651,7 +618,7 @@
 		
 	}
 	
-#	return(testPackList)
+	
 	testPackListPRLStructure$eachRun<-testPackListPRL
 	testPackListPRLStructure$paramTable<-paramTable
 	testPackListPRLStructure$paramConstrainTable<-data.frame(parameterConstrains)



More information about the Blotter-commits mailing list