[Blotter-commits] r962 - pkg/quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Mar 4 21:09:16 CET 2012
Author: braverock
Date: 2012-03-04 21:09:15 +0100 (Sun, 04 Mar 2012)
New Revision: 962
Added:
pkg/quantstrat/demo/bbandParameters.R
pkg/quantstrat/demo/macdParameters.R
Removed:
pkg/quantstrat/demo/parameterTest.R
pkg/quantstrat/demo/parameterTestMACD.R
Modified:
pkg/quantstrat/demo/00Index
Log:
- update parameter tests to not require doSMP, add notes about configuring parallel backend to foreach
- rename parameter tests
- add to 00index
Modified: pkg/quantstrat/demo/00Index
===================================================================
--- pkg/quantstrat/demo/00Index 2012-03-04 19:52:03 UTC (rev 961)
+++ pkg/quantstrat/demo/00Index 2012-03-04 20:09:15 UTC (rev 962)
@@ -5,3 +5,5 @@
maCross classic 'Golden Cross' 50/200 period moving average cross strategy, long only, with long/short extra rules commented out
pair_trade simple two-instrument long-short equity strategy demonstrating custom indicator and extended order sizing functionality
rsi Relative Strength Index (RSI) strategy demonstrating long-only threshold actions
+bbandParameters example of parameter test on bbands demo strategy
+macdParameters example of parameter test on macd demo strategy
Copied: pkg/quantstrat/demo/bbandParameters.R (from rev 910, pkg/quantstrat/demo/parameterTest.R)
===================================================================
--- pkg/quantstrat/demo/bbandParameters.R (rev 0)
+++ pkg/quantstrat/demo/bbandParameters.R 2012-03-04 20:09:15 UTC (rev 962)
@@ -0,0 +1,47 @@
+# Parameter example for BBands demo
+#
+# Author: Yu Chen
+###############################################################################
+
+require(foreach,quietly=TRUE)
+require(quantstrat)
+
+demo('bbands',ask=FALSE)
+#the user should load a parallel backend for foreach before running,
+# or this will run in single threaded mode
+
+#please run bbands demo before all these...
+paramStructure<-getParameterTable(stratBBands)
+
+#tPD<-setParameterDistribution() need no more for initial object.
+
+#Do expand test
+#tPD<-setParameterDistribution(tPD,'indicator',indexnum=1,distribution=list(sd=(1:3)))
+#tPD<-setParameterDistribution(tPD,'signal',indexnum=2,distribution=list(sd=sample(1:10, size=1, replace=FALSE)))
+#tPD<-setParameterDistribution(tPD,'signal',indexnum=3,distribution=list(n=sample(1:10, size=1, replace=FALSE)))
+#
+##update the 3rd slot by using psindex
+#tPD<-setParameterDistribution(tPD,'signal',indexnum=2,distribution=list(n=c(20,30)),psindex=3)
+#testPackList<-applyParameter(strategy=stratBBands,portfolios='bbands',parameterPool=tPD,method='expand')
+
+
+
+
+#tPD
+
+#debug(applyParameter)
+#undebug(applyParameter)
+
+
+# Just provide leagal values and use random sampling.
+tPD<-setParameterDistribution(tPD,'indicator',indexnum=1,distribution=list(sd=(1:3)),weight=c(.25,.25,.5),label='sd')
+tPD<-setParameterDistribution(tPD,'signal',indexnum=2,distribution=list(relationship=c("lt","lte")),label='rel')
+#tPD<-setParameterDistribution(tPD,'signal',indexnum=2,distribution=list(relationship=c("lte")))
+tPD<-setParameterDistribution(tPD,'indicator',indexnum=1,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)
+
+
Copied: pkg/quantstrat/demo/macdParameters.R (from rev 910, pkg/quantstrat/demo/parameterTestMACD.R)
===================================================================
--- pkg/quantstrat/demo/macdParameters.R (rev 0)
+++ pkg/quantstrat/demo/macdParameters.R 2012-03-04 20:09:15 UTC (rev 962)
@@ -0,0 +1,63 @@
+# Parameter demo for MACD demo
+#
+# Author: Yu Chen
+###############################################################################
+
+require(foreach,quietly=TRUE)
+require(quantstrat)
+
+demo('macd',ask=FALSE)
+
+# example parallel initialization for doSMP, doParallel, doMC, or doRedis are
+# most probably preferable to doSMP
+#require(doSMP)
+#workers <- startWorkers(2)
+#registerDoSMP(workers)
+
+#please run macd demo before all these...
+paramStructure<-getParameterTable(stratMACD)
+
+rm(tPD2)
+
+
+# Just provide leagal values and use random sampling.
+# Make nFast and nSlow over lap from 20 to 30 to test the constrains later.
+# First call don't need to input tPD2, the funciton will initial one and return it.
+
+tPD2<-setParameterDistribution(type='indicator',indexnum=1,distribution=list(nFast=(10:30)),label='nFast')
+
+# Initial one tPD2 and pass it also works as following two lines:
+## tPD2<-setParameterDistribution()
+## tPD2<-setParameterDistribution(type='indicator',indexnum=1,distribution=list(nFast=(10:30)),label='nFast')
+
+tPD2<-setParameterDistribution(tPD2,type='indicator',indexnum=1,distribution=list(nSlow=(20:40)),label='nSlow')
+tPD2<-setParameterDistribution(tPD2,type='signal',indexnum=1,distribution=list(relationship=c('gt','gte')),label='sig1.gtgte')
+
+# Put constrains to the nFast and nSlow parameters.
+pConstraint2<-setParameterConstraint(constraintLabel='macdPC',paramList=c('nFast','nSlow'),relationship='lt')
+
+
+
+#testPackList2<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=3,parameterConstrains=pConstraint2)
+#system.time(testPackList2<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=3,parameterConstrains=pConstraint2))
+
+
+laststpar.rnd<-system.time(
+ testPackListPL<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=20,parameterConstraints=pConstraint2)
+)
+laststpar.rnd
+
+# Please run either random mode or expand mode, since the latter run will overwrite the objects in .blotter.
+#laststpar.exp<-system.time(
+# testPackListPL<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=20,parameterConstrains=pConstraint2)
+#)
+#laststpar.exp
+
+#
+#stopWorkers(workers)
+#rmSessions(all=TRUE)
+
+
+
+
+
Deleted: pkg/quantstrat/demo/parameterTest.R
===================================================================
--- pkg/quantstrat/demo/parameterTest.R 2012-03-04 19:52:03 UTC (rev 961)
+++ pkg/quantstrat/demo/parameterTest.R 2012-03-04 20:09:15 UTC (rev 962)
@@ -1,42 +0,0 @@
-# TODO: Add comment
-#
-# Author: Yu Chen
-###############################################################################
-
-require(foreach)
-
-#please run bbands demo before all these...
-paramStructure<-getParameterTable(stratBBands)
-
-#tPD<-setParameterDistribution() need no more for initial object.
-
-#Do expand test
-#tPD<-setParameterDistribution(tPD,'indicator',indexnum=1,distribution=list(sd=(1:3)))
-#tPD<-setParameterDistribution(tPD,'signal',indexnum=2,distribution=list(sd=sample(1:10, size=1, replace=FALSE)))
-#tPD<-setParameterDistribution(tPD,'signal',indexnum=3,distribution=list(n=sample(1:10, size=1, replace=FALSE)))
-#
-##update the 3rd slot by using psindex
-#tPD<-setParameterDistribution(tPD,'signal',indexnum=2,distribution=list(n=c(20,30)),psindex=3)
-#testPackList<-applyParameter(strategy=stratBBands,portfolios='bbands',parameterPool=tPD,method='expand')
-
-
-
-
-#tPD
-
-#debug(applyParameter)
-#undebug(applyParameter)
-
-
-# Just provide leagal values and use random sampling.
-tPD<-setParameterDistribution(tPD,'indicator',indexnum=1,distribution=list(sd=(1:3)),weight=c(.25,.25,.5),label='sd')
-tPD<-setParameterDistribution(tPD,'signal',indexnum=2,distribution=list(relationship=c("lt","lte")),label='rel')
-#tPD<-setParameterDistribution(tPD,'signal',indexnum=2,distribution=list(relationship=c("lte")))
-tPD<-setParameterDistribution(tPD,'indicator',indexnum=1,distribution=list(n=20:30),label='n')
-
-#pConstr<-setParameterConstraint()
-pConstraint<-setParameterConstraint(constraintLabel='PC1',paramList=c('sd','n'),relationship='gt')
-
-testPackList<-applyParameter(strategy=stratBBands,portfolios='default',parameterPool=tPD,method='random',sampleSize=2,parameterConstraints=pConstraint)
-
-
Deleted: pkg/quantstrat/demo/parameterTestMACD.R
===================================================================
--- pkg/quantstrat/demo/parameterTestMACD.R 2012-03-04 19:52:03 UTC (rev 961)
+++ pkg/quantstrat/demo/parameterTestMACD.R 2012-03-04 20:09:15 UTC (rev 962)
@@ -1,57 +0,0 @@
-# TODO: Add comment
-#
-# Author: CCD
-###############################################################################
-
-require(foreach)
-require(doSMP)
-workers <- startWorkers(2)
-registerDoSMP(workers)
-
-#please run macd demo before all these...
-paramStructure<-getParameterTable(stratMACD)
-
-rm(tPD2)
-
-
-# Just provide leagal values and use random sampling.
-# Make nFast and nSlow over lap from 20 to 30 to test the constrains later.
-# First call don't need to input tPD2, the funciton will initial one and return it.
-
-tPD2<-setParameterDistribution(type='indicator',indexnum=1,distribution=list(nFast=(10:30)),label='nFast')
-
-# Initial one tPD2 and pass it also works as following two lines:
-## tPD2<-setParameterDistribution()
-## tPD2<-setParameterDistribution(type='indicator',indexnum=1,distribution=list(nFast=(10:30)),label='nFast')
-
-tPD2<-setParameterDistribution(tPD2,type='indicator',indexnum=1,distribution=list(nSlow=(20:40)),label='nSlow')
-tPD2<-setParameterDistribution(tPD2,type='signal',indexnum=1,distribution=list(relationship=c('gt','gte')),label='sig1.gtgte')
-
-# Put constrains to the nFast and nSlow parameters.
-pConstraint2<-setParameterConstraint(constraintLabel='macdPC',paramList=c('nFast','nSlow'),relationship='lt')
-
-
-
-#testPackList2<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=3,parameterConstrains=pConstraint2)
-#system.time(testPackList2<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=3,parameterConstrains=pConstraint2))
-
-
-laststpar.rnd<-system.time(
- testPackListPL<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=20,parameterConstraints=pConstraint2)
-)
-laststpar.rnd
-
-# Please run either random mode or expand mode, since the latter run will overwrite the objects in .blotter.
-#laststpar.exp<-system.time(
-# testPackListPL<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=20,parameterConstrains=pConstraint2)
-#)
-#laststpar.exp
-
-#
-#stopWorkers(workers)
-#rmSessions(all=TRUE)
-
-
-
-
-
More information about the Blotter-commits
mailing list