[Blotter-commits] r1218 - in pkg/quantstrat: R demo man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Oct 11 22:47:44 CEST 2012


Author: opentrades
Date: 2012-10-11 22:47:44 +0200 (Thu, 11 Oct 2012)
New Revision: 1218

Modified:
   pkg/quantstrat/R/parameters.R
   pkg/quantstrat/demo/bbandParameters.R
   pkg/quantstrat/demo/luxor.3.Parameters.R
   pkg/quantstrat/demo/luxor.4.Timespans.R
   pkg/quantstrat/man/setParameterDistribution.Rd
Log:
- changed parameter names in setParameterDistribution() 
- improved doc somewhat



Modified: pkg/quantstrat/R/parameters.R
===================================================================
--- pkg/quantstrat/R/parameters.R	2012-10-11 19:57:02 UTC (rev 1217)
+++ pkg/quantstrat/R/parameters.R	2012-10-11 20:47:44 UTC (rev 1218)
@@ -261,18 +261,18 @@
 #' @examples 
 #' \dontrun{
 #' #(For complete demo see parameterTestMACD.R)
-#' tPD2<-setParameterDistribution(tPD2,strat,'indicator',component='FastSMA',
-#'      distribution=list(nFast=(10:30)),label='nFast')
-#' tPD2<-setParameterDistribution(tPD2,strat,'indicator',component='SlowSMA',
-#'      distribution=list(nSlow=(20:40)),label='nSlow')
-#' tPD2<-setParameterDistribution(tPD2,strat,'signal',component='go.long',
-#'      distribution=list(relationship=c('gt','gte')),label='sig1.gtgte')
+#' tPD2<-setParameterDistribution(tPD2, strat, component.type='indicator', component.label='FastSMA', 
+#'      distribution=list(nFast=(10:30)), label='nFast')
+#' tPD2<-setParameterDistribution(tPD2, strat, component.type='indicator', component.label='SlowSMA', 
+#'      distribution=list(nSlow=(20:40)), label='nSlow')
+#' tPD2<-setParameterDistribution(tPD2, strat, component.type='signal', component.label='go.long', 
+#'      distribution=list(relationship=c('gt', 'gte')), label='sig1.gtgte')
 #' }
 #' 
 #' @param paramDist The object in which the parameter list is stored; if this parameter is missing, or object does not exist, the function will return a new object.
 #' @param strategy The strategy object
-#' @param type A character string that specifies the type of the parameter, it takes the value in one of 'indicator', 'signal', 'enter', 'exit', 'order', 'chain'.
-#' @param component The label of the strategy component (indicator/signal/rule) that contains the parameter
+#' @param component.type A character string that specifies the type of the strategy component that contains the parameter, it takes the value in one of 'indicator', 'signal', 'enter', 'exit', 'order', 'chain'.
+#' @param component.label The label that uniquely identifies the strategy component that contains the parameter
 #' @param distribution Distribution of the parameter, can be any function that returns a vector of value. See detail. (A numerical example: 1:10 or sample(1:20,6)
 #' @param weight The weight of each value in the distribution, if missing, the default value of all equal weights will be taken.
 #' @param label A string label to apply to the parameter distribution
@@ -280,20 +280,20 @@
 #' @return The returned object is a structure contains the distribution of parameters, if the input argument 'paramDist' is provided, the function update the input paramDist object and return the updated one. When specify the distribution of several parameters, usually the first returned object is passed to the next several call of the function as input argument 'paramDist'. See example. 
 #' @author Yu Chen
 #' @export
-setParameterDistribution<-function(paramDist=NULL, strategy, type, component, distribution=NULL, weight, label, psindex=NULL) #All is needed,  set to illegal values
+setParameterDistribution<-function(paramDist=NULL, strategy, component.type, component.label, distribution=NULL, weight, label, psindex=NULL) #All is needed,  set to illegal values
 {
     missing.msg <- ': missing in call to setParameterDistribution'
 
     if(!hasArg(strategy))
         stop(paste('strategy', missing.msg))
-    if(!hasArg(type))
-        stop(paste('type', missing.msg))
-    if(!hasArg(component))
-        stop(paste('component', missing.msg))
+    if(!hasArg(component.type))
+        stop(paste('component.type', missing.msg))
+    if(!hasArg(component.label))
+        stop(paste('component.label', missing.msg))
     if(!hasArg(distribution))
         stop(paste('distribution', missing.msg))
 
-    if(!type %in% c("indicator","signal","enter","exit","order","chain"))
+    if(!component.type %in% c("indicator","signal","enter","exit","order","chain"))
         stop("Type must be a string in: indicator, signal, enter, exit, order", "chain")
 
     if(!is.list(distribution) || length(distribution) != 1)
@@ -305,16 +305,16 @@
         print('Object for parameter distribution initialized...')
     }
 
-    indexnum <- label2index(strategy, type, component)
+    indexnum <- label2index(strategy, component.type, component.label)
 
     tmp_paramDist<-list()
-    tmp_paramDist$type<-type
+    tmp_paramDist$type<-component.type
     tmp_paramDist$indexnum<-indexnum
     tmp_paramDist$distribution<-distribution
     
     if(missing(label))
     {
-        tmp_paramDist$label<-paste('Param',type,indexnum,names(distribution),sep='.')
+        tmp_paramDist$label<-paste('Param',component.type,indexnum,names(distribution),sep='.')
     }
     else
     {
@@ -330,7 +330,7 @@
 
     #class(tmp_paramDist)<-'parameter_distribution'
 
-    #TODO put an check to see if the type/indexnum exist already.
+    #TODO put an check to see if the component.type/indexnum exist already.
     paramDist[[psindex]]<-tmp_paramDist
 
     return(paramDist)

Modified: pkg/quantstrat/demo/bbandParameters.R
===================================================================
--- pkg/quantstrat/demo/bbandParameters.R	2012-10-11 19:57:02 UTC (rev 1217)
+++ pkg/quantstrat/demo/bbandParameters.R	2012-10-11 20:47:44 UTC (rev 1218)
@@ -42,15 +42,16 @@
 tPD <- NULL
 
 # Just provide legal values and use random sampling.
-tPD<-setParameterDistribution(tPD, strategy=stratBBands, type='indicator', component='BBands', distribution=list(sd=(1:3)), weight=c(.25, .25, .5), label='sd')
-tPD<-setParameterDistribution(tPD, strategy=stratBBands, type='signal', component='Cl.lt.LowerBand', distribution=list(relationship=c("lt", "lte")), label='rel')
+tPD<-setParameterDistribution(tPD, strategy=stratBBands, component.type='indicator', component.label='BBands', distribution=list(sd=(1:3)), weight=c(.25, .25, .5), label='sd')
+tPD<-setParameterDistribution(tPD, strategy=stratBBands, component.type='signal', component.label='Cl.lt.LowerBand', distribution=list(relationship=c("lt", "lte")), label='rel')
 #tPD<-setParameterDistribution(tPD,strategy=stratBBands,'signal',indexnum=2,distribution=list(relationship=c("lte")))
-tPD<-setParameterDistribution(tPD, strategy=stratBBands, type='indicator', component='BBands', distribution=list(n=20:30), label='n')
+tPD<-setParameterDistribution(tPD, strategy=stratBBands, component.type='indicator', component.label='BBands', distribution=list(n=20:30), label='n')
 
 #pConstr<-setParameterConstraint()
 pConstraint<-setParameterConstraint(constraintLabel='PC1',paramList=c('sd','n'),relationship='gt')
 
-testPackList<-applyParameter(strategy=stratBBands,portfolios=portfolio.st,parameterPool=tPD,method='random',sampleSize=2,parameterConstraints=pConstraint)
+#testPackList<-applyParameter(strategy=stratBBands,portfolios=portfolio.st,parameterPool=tPD,method='expand',parameterConstraints=pConstraint)
+testPackList<-applyParameter(strategy=stratBBands,portfolios=portfolio.st,parameterPool=tPD,method='random',sampleSize=8,parameterConstraints=pConstraint)
 
 ###############################################################################
 # R (http://r-project.org/) Quantitative Strategy Model Framework

Modified: pkg/quantstrat/demo/luxor.3.Parameters.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.Parameters.R	2012-10-11 19:57:02 UTC (rev 1217)
+++ pkg/quantstrat/demo/luxor.3.Parameters.R	2012-10-11 20:47:44 UTC (rev 1218)
@@ -43,8 +43,8 @@
 #parameterTable
 #stop()
 
-tPD2<-setParameterDistribution(strategy=s, type = 'indicator', component='nFast', distribution = list(nFast = .fastRange), label = 'nFast')
-tPD2<-setParameterDistribution(tPD2, strategy=s, type = 'indicator', component='nSlow', distribution = list(nSlow = .slowRange), label = 'nSlow')
+tPD2<-setParameterDistribution(strategy=s, component.type='indicator', component.label='nFast', distribution = list(nFast = .fastRange), label = 'nFast')
+tPD2<-setParameterDistribution(tPD2, strategy=s, component.type='indicator', component.label='nSlow', distribution = list(nSlow = .slowRange), label = 'nSlow')
 
 pConstraint2<-setParameterConstraint(constraintLabel='luxorPC',paramList=c('nFast','nSlow'),relationship='lt')
 

Modified: pkg/quantstrat/demo/luxor.4.Timespans.R
===================================================================
--- pkg/quantstrat/demo/luxor.4.Timespans.R	2012-10-11 19:57:02 UTC (rev 1217)
+++ pkg/quantstrat/demo/luxor.4.Timespans.R	2012-10-11 20:47:44 UTC (rev 1218)
@@ -45,7 +45,7 @@
 
 parameterTable<-getParameterTable(s)
 
-tPD2<-setParameterDistribution(strategy=s, type = 'enter', component='EnterLONG', distribution = list(timespan = .timespans), label = 'Timespan')
+tPD2<-setParameterDistribution(strategy=s, component.type='enter', component.label='EnterLONG', distribution = list(timespan = .timespans), label = 'Timespan')
 
 registerDoMC(cores=2)
 

Modified: pkg/quantstrat/man/setParameterDistribution.Rd
===================================================================
--- pkg/quantstrat/man/setParameterDistribution.Rd	2012-10-11 19:57:02 UTC (rev 1217)
+++ pkg/quantstrat/man/setParameterDistribution.Rd	2012-10-11 20:47:44 UTC (rev 1218)
@@ -3,8 +3,8 @@
 \title{Function used to create an object that contains the distribution of parameters to be generated from, before testing parameters of a strategy.}
 \usage{
   setParameterDistribution(paramDist = NULL, strategy,
-    type, component, distribution = NULL, weight, label,
-    psindex = NULL)
+    component.type, component.label, distribution = NULL,
+    weight, label, psindex = NULL)
 }
 \arguments{
   \item{paramDist}{The object in which the parameter list
@@ -13,12 +13,13 @@
 
   \item{strategy}{The strategy object}
 
-  \item{type}{A character string that specifies the type of
-  the parameter, it takes the value in one of 'indicator',
+  \item{component.type}{A character string that specifies
+  the type of the strategy component that contains the
+  parameter, it takes the value in one of 'indicator',
   'signal', 'enter', 'exit', 'order', 'chain'.}
 
-  \item{component}{The label of the strategy component
-  (indicator/signal/rule) that contains the parameter}
+  \item{component.label}{The label that uniquely identifies
+  the strategy component that contains the parameter}
 
   \item{distribution}{Distribution of the parameter, can be
   any function that returns a vector of value. See detail.
@@ -67,12 +68,12 @@
 \examples{
 \dontrun{
 #(For complete demo see parameterTestMACD.R)
-tPD2<-setParameterDistribution(tPD2,strat,'indicator',component='FastSMA',
-     distribution=list(nFast=(10:30)),label='nFast')
-tPD2<-setParameterDistribution(tPD2,strat,'indicator',component='SlowSMA',
-     distribution=list(nSlow=(20:40)),label='nSlow')
-tPD2<-setParameterDistribution(tPD2,strat,'signal',component='go.long',
-     distribution=list(relationship=c('gt','gte')),label='sig1.gtgte')
+tPD2<-setParameterDistribution(tPD2, strat, component.type='indicator', component.label='FastSMA',
+     distribution=list(nFast=(10:30)), label='nFast')
+tPD2<-setParameterDistribution(tPD2, strat, component.type='indicator', component.label='SlowSMA',
+     distribution=list(nSlow=(20:40)), label='nSlow')
+tPD2<-setParameterDistribution(tPD2, strat, component.type='signal', component.label='go.long',
+     distribution=list(relationship=c('gt', 'gte')), label='sig1.gtgte')
 }
 }
 \author{



More information about the Blotter-commits mailing list