SCM

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1096 - (view) (download)

1 : braverock 962 # Parameter demo for MACD demo
2 : cyrforge 663 #
3 : braverock 962 # Author: Yu Chen
4 : cyrforge 663 ###############################################################################
5 :    
6 : braverock 962 require(foreach,quietly=TRUE)
7 :     require(quantstrat)
8 : cyrforge 692
9 : braverock 962 demo('macd',ask=FALSE)
10 :    
11 : braverock 1095 # example parallel initialization for doParallel. this or doMC, or doRedis are
12 : braverock 962 # most probably preferable to doSMP
13 : braverock 1095 #require(doParallel)
14 :     #registerDoParallel() # by default number of physical cores -1
15 : braverock 962
16 : braverock 1095
17 : cyrforge 663 #please run macd demo before all these...
18 : braverock 1095
19 :     #retrieve the strategy from the environment, since the 'macd' strategy uses store=TRUE
20 :     stratMACD<-getStrategy('macd')
21 :    
22 : cyrforge 663 paramStructure<-getParameterTable(stratMACD)
23 :    
24 : cyrforge 729 rm(tPD2)
25 : cyrforge 663
26 : cyrforge 729
27 : cyrforge 663 # Just provide leagal values and use random sampling.
28 : cyrforge 729 # Make nFast and nSlow over lap from 20 to 30 to test the constrains later.
29 :     # First call don't need to input tPD2, the funciton will initial one and return it.
30 : cyrforge 663
31 : cyrforge 729 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 : cyrforge 663 pConstraint2<-setParameterConstraint(constraintLabel='macdPC',paramList=c('nFast','nSlow'),relationship='lt')
42 :    
43 :    
44 :    
45 : cyrforge 687 #testPackList2<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=3,parameterConstrains=pConstraint2)
46 :     #system.time(testPackList2<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=3,parameterConstrains=pConstraint2))
47 :    
48 :    
49 : cyrforge 729 laststpar.rnd<-system.time(
50 : gsee 776 testPackListPL<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=20,parameterConstraints=pConstraint2)
51 : cyrforge 692 )
52 : braverock 1095 #laststpar.rnd
53 : cyrforge 729
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 : braverock 1096 if(verbose >=1) print(laststpar.exp)
59 : cyrforge 729
60 : braverock 1096 #examine the stats from this parameter run:
61 :     if(verbose >=1) print(testPackListPL$statsTable)
62 : cyrforge 687
63 :    
64 :    
65 :    
66 :    

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