SCM

SCM Repository

[blotter] Diff of /pkg/quantstrat/demo/macdParameters.R
ViewVC logotype

Diff of /pkg/quantstrat/demo/macdParameters.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

pkg/quantstrat/demo/parameterTestMACD.R revision 692, Thu Jul 21 23:00:07 2011 UTC pkg/quantstrat/demo/macdParameters.R revision 1370, Thu Jan 17 20:58:10 2013 UTC
# Line 1  Line 1 
1  # TODO: Add comment  # Parameter demo for MACD demo
2  #  #
3  # Author: CCD  # Author: Yu Chen
4  ###############################################################################  ###############################################################################
5    
6  require(foreach)  require(foreach,quietly=TRUE)
7  require(doSMP)  require(quantstrat)
 workers <- startWorkers(2)  
 registerDoSMP(workers)  
8    
9    demo('macd',ask=FALSE)
10    
11    # example parallel initialization for doParallel. this or doMC, or doRedis are
12    # most probably preferable to doSMP
13    #require(doParallel)
14    #registerDoParallel() # by default number of physical cores -1
15    
 source("D:\\Documents\\GoogleCode\\Workspace\\quantstrat\\R\\parameters.R")  
16    
17  #please run macd demo before all these...  #please run macd demo before all these...
18    
19    #retrieve the strategy from the environment, since the 'macd' strategy uses store=TRUE
20    stratMACD<-getStrategy('macd')
21    
22  paramStructure<-getParameterTable(stratMACD)  paramStructure<-getParameterTable(stratMACD)
23    
24  tPD2<-setParameterDistribution()  rm(tPD2)
25  tPD2  
26    
27  # Just provide leagal values and use random sampling.  # Just provide leagal values and use random sampling.
28  tPD2<-setParameterDistribution(tPD2,'indicator',indexnum=1,distribution=list(nFast=(10:30)),label='nFast')  # Make nFast and nSlow over lap from 20 to 30 to test the constrains later.
29  #make them over lap from 20 to 30 to test.  # First call don't need to input tPD2, the funciton will initial one and return it.
30  tPD2<-setParameterDistribution(tPD2,'indicator',indexnum=1,distribution=list(nSlow=(20:40)),label='nSlow')  
31  tPD2<-setParameterDistribution(tPD2,'signal',indexnum=1,distribution=list(relationship=c('gt','gte')),label='sig1.gtgte')  tPD2<-setParameterDistribution(type='indicator',indexnum=1,distribution=list(nFast=(10:30)),label='nFast')
32    
33    # Initial one tPD2 and pass it also works as following two lines:
34    ## tPD2<-setParameterDistribution()
35    ## tPD2<-setParameterDistribution(type='indicator',indexnum=1,distribution=list(nFast=(10:30)),label='nFast')
36    
37    tPD2<-setParameterDistribution(tPD2,type='indicator',indexnum=1,distribution=list(nSlow=(20:40)),label='nSlow')
38    tPD2<-setParameterDistribution(tPD2,type='signal',indexnum=1,distribution=list(relationship=c('gt','gte')),label='sig1.gtgte')
39    
40    # Put constrains to the nFast and nSlow parameters.
41  pConstraint2<-setParameterConstraint(constraintLabel='macdPC',paramList=c('nFast','nSlow'),relationship='lt')  pConstraint2<-setParameterConstraint(constraintLabel='macdPC',paramList=c('nFast','nSlow'),relationship='lt')
42    
43    
# Line 31  Line 46 
46  #system.time(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))
47    
48    
49  laststpar<-system.time(  laststpar.rnd<-system.time(
50                  testPackListPL<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=10,parameterConstrains=pConstraint2)                  testPackListPL<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=20,parameterConstraints=pConstraint2)
51  )  )
52  laststpar  #laststpar.rnd
 #  
 #stopWorkers(workers)  
 #rmSessions(all=TRUE)  
   
   
   
   
53    
54    # Please run either random mode or expand mode, since the latter run will overwrite the objects in .blotter.
55    #laststpar.exp<-system.time(
56    #               testPackListPL<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=20,parameterConstrains=pConstraint2)
57    #)
58    if(verbose >=1) print(laststpar.exp)
59    
60    #examine the stats from this parameter run:
61    if(verbose >=1) print(testPackListPL$statsTable)
62    
63    ##### PLACE THIS BLOCK AHEAD OF DATE INITS IN DEMO SCRIPT ######
64    # if(!exists('in_test') || !isTRUE(in_test)){
65    #     initDate='2005-12-31' # ensure this is demo default
66    #     endDate=Sys.Date()    # ensure this is demo default
67    # }
68    ################################################################
69    
70    ##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
71    # book  = getOrderBook(port)
72    # stats = tradeStats(port)
73    # rets  = PortfReturns(acct)
74    ################################################################

Legend:
Removed from v.692  
changed lines
  Added in v.1370

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge