SCM

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1724 - (download) (annotate)
Mon Dec 14 12:54:08 2015 UTC (3 years, 2 months ago) by bodanker
File size: 1953 byte(s)
Do not set initDate argument in demos

Do not set initDate for initPortf, initAcct, or initOrders in any of the
demos. Specifying the initDate argument incorrectly can cause errors
that are difficult for users to diagnose, so we shouldn't provide demos
that suggest users need to set initDate manually.

Rename initDate to startDate in all demos in order to avoid confusion
with initDate argument to initPortf, initAcct, and initOrders.
# Parameter demo for MACD
###############################################################################

require(foreach,quietly=TRUE)
require(iterators)
require(quantstrat)

demo('macd',ask=FALSE)

# example parallel initialization for doParallel. this or doMC, or doRedis are 
# most probably preferable to doSMP
#require(doParallel)
#registerDoParallel() # by default number of physical cores -1


#please run macd demo before all these...

#retrieve the strategy from the environment, since the 'macd' strategy uses store=TRUE
strategy.st <- 'macd'

### Set up Parameter Values
.FastMA = (1:20)
.SlowMA = (30:80)
.nsamples = 10 #for random parameter sampling, less important if you're using doParallel or doMC


### MA paramset

add.distribution(strategy.st,
                 paramset.label = 'MA',
                 component.type = 'indicator',
                 component.label = '_', #this is the label given to the indicator in the strat
                 variable = list(n = .FastMA),
                 label = 'nFAST'
)

add.distribution(strategy.st,
                 paramset.label = 'MA',
                 component.type = 'indicator',
                 component.label = '_', #this is the label given to the indicator in the strat
                 variable = list(n = .SlowMA),
                 label = 'nSLOW'
)

add.distribution.constraint(strategy.st,
                            paramset.label = 'MA',
                            distribution.label.1 = 'nFAST',
                            distribution.label.2 = 'nSLOW',
                            operator = '<',
                            label = 'MA'
)


###

results <- apply.paramset(strategy.st, 
                          paramset.label='MA', 
                          portfolio.st=portfolio.st, 
                          account.st=account.st, 
                          nsamples=.nsamples, 
                          verbose=TRUE)

stats <- results$tradeStats

print(stats)

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge