Description Usage Arguments Details Value Support for parallel execution Author(s) See Also Examples
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.
1 2 | applyParameter(strategy, portfolios, parameterPool, parameterConstraints,
method, sampleSize, verbose = FALSE, ...)
|
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 |
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 ...
In the returned result pack as a list of object:
is the summary table show stats from all the runs
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
is parameter samples used, in a table for print
is the constraints apply to the parameters, in a table for print
is the parameter distribution passed in as argument
is the constraints apply to the parameters, passed in as argument
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.
Yu Chen
setParameterDistribution
,
setParameterConstraint
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.