Learn R Programming

quantstrat (version 0.8.2)

applyParameter: Generate parameter sets for a specific strategy, test the strategy on each set of parameters, output result package.

Description

The function do several things in one call, to test different parameters on a strategy. It generates parameter sets based on specified distribution (a defined parameter distribution object generated by setParameterDistribution function) and constraints (A defined parameter constraint object generated by setParameterConstraint function), apply the generated parameter sets to the specified strategy and return the results package, put the generated portfolio objects and account objects in .blotter environment.

Usage

applyParameter(strategy, portfolios, parameterPool, parameterConstraints, method, sampleSize, verbose = FALSE, ...)

Arguments

strategy
The strategy to test paramters to.
portfolios
The character name of the portfolios to apply to.
parameterPool
The object that created by setParameterDistribution function, which includes all the parameter legal values and distribution/weights.
parameterConstraints
The object created by setParameterConstraint function that specifies the constraints between each parameters,
method
Takes string 'expand' or 'random', specify how to generate samples of parameters. 'expand' will do all possible combinations of the parameter sets,
sampleSize
Used when method=='random', specify how many parameter sets to generate and run test of.
verbose
if verbose TRUE or 1+, will print a lot of debug info, default FALSE
...
any other passthru parameters

Value

In the returned result pack as a list of object:
statsTable
is the summary table show stats from all the runs
eachRun
contains the details of test run with each parameter set, including portfolio name, account name, strategy used, parameters used, stats of the single run, object in .blotter but as a list named blotterl
paramTable
is parameter samples used, in a table for print
paramConstrainTable
is the constraints apply to the parameters, in a table for print
parameterDistribution
is the parameter distribution passed in as argument
parameterConstraints
is the constraints apply to the parameters, passed in as argument

Support for parallel execution

The function supports parallel execution, user only need to initial the parallel package and wrap up afterwards. The function will automaticly use the number of registered parallel sessions to run testing, See example.

Details

Other than the returned result pack, the function puts the generated portfolio and account objects in the .blotter environment. The names of those objects will be extension of the names created by initial strategy/portfolios are created. For example, in macd.R demo, account.macd and portfolio.macd are created in .blotter environment. After calling the applyParameter function and did the parameter test, series of similar objects are created with names account.macd.p.1, account.macd.p.2 ... and portfolio.macd.p.1, portfolio.macd.p.2 ...

See Also

setParameterDistribution, setParameterConstraint

Examples

Run this code
## Not run: 
# require(foreach)
# require(doSMP)
# workers <- startWorkers(2)
# registerDoSMP(workers)
# 
# #PUT ALL CODE RELATED TO QUANTSTRAT HERE
#      #Example to call the function:  (For complete demo see parameterTestMACD.R)
#      x<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,
#                   method='random',sampleSize=20,parameterConstraints=pConstraint2)
#      #or
#      x<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,
#                   method='expand',parameterConstraints=pConstraint2)
# 
# stopWorkers(workers)
# rmSessions(all=TRUE)
# ## End(Not run)

Run the code above in your browser using DataLab