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 1724 - (view) (download)

1 : braverock 1701 # Parameter demo for MACD
2 : braverock 1595 ###############################################################################
3 :    
4 :     require(foreach,quietly=TRUE)
5 : braverock 1701 require(iterators)
6 : braverock 1595 require(quantstrat)
7 :    
8 :     demo('macd',ask=FALSE)
9 :    
10 :     # example parallel initialization for doParallel. this or doMC, or doRedis are
11 :     # most probably preferable to doSMP
12 :     #require(doParallel)
13 :     #registerDoParallel() # by default number of physical cores -1
14 :    
15 :    
16 :     #please run macd demo before all these...
17 :    
18 :     #retrieve the strategy from the environment, since the 'macd' strategy uses store=TRUE
19 : braverock 1701 strategy.st <- 'macd'
20 : braverock 1595
21 : braverock 1701 ### Set up Parameter Values
22 : braverock 1702 .FastMA = (1:20)
23 :     .SlowMA = (30:80)
24 : braverock 1701 .nsamples = 10 #for random parameter sampling, less important if you're using doParallel or doMC
25 : braverock 1595
26 :    
27 : braverock 1702 ### MA paramset
28 : braverock 1595
29 : braverock 1701 add.distribution(strategy.st,
30 : braverock 1702 paramset.label = 'MA',
31 : braverock 1701 component.type = 'indicator',
32 :     component.label = '_', #this is the label given to the indicator in the strat
33 : braverock 1702 variable = list(n = .FastMA),
34 : braverock 1701 label = 'nFAST'
35 :     )
36 : braverock 1595
37 : braverock 1701 add.distribution(strategy.st,
38 : braverock 1702 paramset.label = 'MA',
39 : braverock 1701 component.type = 'indicator',
40 :     component.label = '_', #this is the label given to the indicator in the strat
41 : braverock 1702 variable = list(n = .SlowMA),
42 : braverock 1701 label = 'nSLOW'
43 :     )
44 : braverock 1595
45 : braverock 1701 add.distribution.constraint(strategy.st,
46 : braverock 1702 paramset.label = 'MA',
47 : braverock 1701 distribution.label.1 = 'nFAST',
48 :     distribution.label.2 = 'nSLOW',
49 :     operator = '<',
50 : braverock 1702 label = 'MA'
51 : braverock 1701 )
52 : braverock 1595
53 :    
54 : braverock 1701 ###
55 : braverock 1595
56 : braverock 1701 results <- apply.paramset(strategy.st,
57 : braverock 1702 paramset.label='MA',
58 : braverock 1701 portfolio.st=portfolio.st,
59 :     account.st=account.st,
60 :     nsamples=.nsamples,
61 :     verbose=TRUE)
62 : braverock 1595
63 : braverock 1701 stats <- results$tradeStats
64 : braverock 1595
65 : braverock 1701 print(stats)

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