[R-SIG-Finance] quantstrat help - simple combine error using windows and walk.forward
Brian G. Peterson
brian at braverock.com
Tue Sep 30 17:33:05 CEST 2014
The core problem here is related to custom functions in the .GlobalEnv
and using certain parallel backends in walk.forward.
We're working on evaluating a patch provided by Jonathan Owen, and hope
to have a fix in svn on R-Forge soon.
Regards,
Brian
On 09/30/2014 10:25 AM, Derek Wong wrote:
> Mark,
>
> Thank you for the reply. I really appreciate you taking the time to look at
> it. However in my previous email/post and my current code I do not see a
> line that shows
>
> portfolio1.st <- 'pair1'account.st <- 'pairs'
>
> they should be two separate lines. Either way I have run the entire code
> and will show the area I am focusing on. Which is the end using the
> walk.forward() function, as everything else in the code runs perfectly for
> me using R 3.1.1 in windows or ubuntu.
>
> Code I am focusing on:
>
> # Objective Function
> my.obj.func <- function(x)
> {
> # pick one of the following objective functions (uncomment)
>
> #return(max(x$tradeStats$Max.Drawdown) == x$tradeStats$Max.Drawdown)
>
> return(max(x$tradeStats$Net.Trading.PL) == x$tradeStats$Net.Trading.PL)
>
> }
>
> #WFA
> require(doParallel)
> cl <- makePSOCKcluster(2)
> registerDoParallel(cl)
>
> result <- walk.forward(pairStrat,
> paramset.label = "BBOPT",
> portfolio.st = portfolio1.st,
> account.st = account.st,
> period = "months",
> k.training = 6,
> k.testing = 3,
> obj.func = my.obj.func,
> obj.args = list(x=quote(result$apply.paramset)),
> audit.prefix = "wfa",
> anchored = FALSE,
> verbose = TRUE)
>
>
> Output below:
>> # Objective Function
>> my.obj.func <- function(x)
> + {
> + # pick one of the following objective functions (uncomment)
> +
> + #return(max(x$tradeStats$Max.Drawdown) == x$tradeStats$Max.Drawdown)
> +
> + return(max(x$tradeStats$Net.Trading.PL) == x$tradeStats$Net.Trading.PL)
> +
> + }
>>
>> #WFA
>> require(doParallel)
>> cl <- makePSOCKcluster(2)
>> registerDoParallel(cl)
>>
>> result <- walk.forward(pairStrat,
> + paramset.label = "BBOPT",
> + portfolio.st = portfolio1.st,
> + account.st = account.st,
> + period = "months",
> + k.training = 6,
> + k.testing = 3,
> + obj.func = my.obj.func,
> + obj.args = list(x=quote(result$apply.paramset)),
> + audit.prefix = "wfa",
> + anchored = FALSE,
> + verbose = TRUE)
> [1] "=== training BBOPT on 2009-01-02/2009-06-30"
> automatically exporting the following variables from the local environment:
> account, account.st, calc, env.instrument, mktdata, orderbook,
> paramset.label, portfolio, portfolio.st, strategy, user.args, user.func
> explicitly exporting variables(s): clone.portfolio, clone.orderbook,
> install.param.combo
> numValues: 180, numResults: 0, stopped: TRUE
> got results for task 1
> numValues: 180, numResults: 1, stopped: TRUE
> returning status FALSE
> got results for task 2
> <SNIP>
> got results for task 180
> numValues: 180, numResults: 180, stopped: TRUE
> first call to combine function
> evaluating call object to combine results:
> fun(result.1, result.2, result.3, result.4, result.5, result.6,
> <SNIP>
> result.177, result.178, result.179, result.180)
> error calling combine function:
> <simpleError in fun(result.1, result.2, result.3, result.4, result.5,
> result.6, result.7, result.8, result.9, result.10, result.11,
> result.12, result.13, result.14, result.15, result.16, result.17,
> result.18, result.19, result.20, result.21, result.22,
> <SNIP>
> result.171, result.172, result.173, result.174, result.175, result.176,
> result.177, result.178, result.179, result.180): attempt to select less
> than one element>
> Error in walk.forward(pairStrat, paramset.label = "BBOPT", portfolio.st =
> portfolio1.st, :
> obj.func() returned empty result
> In addition: Warning messages:
> 1: In e$fun(obj, substitute(ex), parent.frame(), e$data) :
> already exporting variable(s): env.instrument
> 2: In max(x$tradeStats$Net.Trading.PL) :
> no non-missing arguments to max; returning -Inf
>
>
>
> Thanks again
>
> Derek
>
> On Tue, Sep 30, 2014 at 8:20 AM, Mark Knecht <markknecht at gmail.com> wrote:
>
>> On Tue, Sep 30, 2014 at 12:34 AM, Derek Wong <treydog999 at gmail.com> wrote:
>>> Hello,
>>>
>>> I have been able to reproduce this error in Ubuntu based system as well
>> not
>>> just on windows. I was wondering if anyone had any insights or ways to to
>>> solve this or create a work around. If there is any additional
>> information
>>> you require let me know. Please I would really appreciate help on this.
>> It
>>> is totally out of my depth and I am hoping that this fine community can
>>> help.
>>>
>>
>> Derek,
>> I have no time to do any debugging of this but the first error on my
>> Gentoo system running RStudio and R-3.1.1 is actually this line:
>>
>> portfolio1.st <- 'pair1'account.st <- 'pairs'
>>
>> which does look like bad code to me.
>>
>> One 'problem' with a number of demos that are out there is that the demo
>> author may be using the development version of a specific package which
>> then results in end user types (like me) having problems.
>>
>> I suggest you run this code line-by-line and then post back a few lines
>> preceding the breakdown. Maybe someone can give better input than
>> I can. Also, please edit/snip your responses to add focus to the exact
>> issue.
>>
>> Good luck,
>> Mark
>>
>>> On Wed, Sep 24, 2014 at 9:36 PM, Derek Wong <treydog999 at gmail.com>
>> wrote:
>>>
>>>> Hello,
>>>>
>>>> I am having a lot of trouble with using walk.forward.in windows. i get
>>>> the following error. This may be related to bug #5814. If someone could
>>>> please help me i would really appreciate it. The reproducible code
>> below is
>>>> based on the pair_trade example. Thanks.
>>>>
>>>> error calling combine function:
>>>> <simpleError in fun(result.1, result.2, result.3, result.4, result.5,
>>>> result.6, result.7, result.8, result.9, result.10, result.11,
>> <SNIP>
>>>> result.172, result.173, result.174, result.175, result.176,
>> result.177,
>>>> result.178, result.179, result.180): attempt to select less than one
>>>> element>
>>>> Error in walk.forward(pairStrat, paramset.label = "BBOPT", portfolio.st
>> =
>>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>
--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock
More information about the R-SIG-Finance
mailing list