quantstrat spread parameter sweep problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

quantstrat spread parameter sweep problem

Rob Schmidt
Hello all,

I am stuck on making a parameter sweep of a spread and have attached
the version that gets the farthest before failing.  This has driven me
to extreme measures like reading the documentation and trying to upgrade
my debugging skills.  

The code gets through the basic calculations and makes a chart so the
spread definitions seem ok.  But it fails in applyParameter.  The variable
values are reasonable as far as I can tell until %dopar% in the foreach()
command in parameters.R.  Then the debugger takes the rest of the
command in {} as a big chunk and my modest debug skills fail.  This
sweep code works when I use a single contract rather than a spread.  
Here is the error.  The traceback points to the chunk of code after
%dopar% so I won't repeat that.

Thanks to the authors for this great effort. Thanks for all help.

Best regards,

Rob

> source('~/work/R/quantstrat/spread-sweep05.R')
[1] "2011-03-01 00:00:00 SPY.DIA -100 @ 10.9387968680294"
[1] "2011-03-07 00:00:00 SPY.DIA 100 @ 10.8600842370335"
[1] "2011-03-10 00:00:00 SPY.DIA -100 @ 9.82580786782957"
[1] "2011-03-11 00:00:00 SPY.DIA 100 @ 10.0274530275673"
[1] "2011-03-15 00:00:00 SPY.DIA -100 @ 9.2739827055253"
[1] "2011-04-06 00:00:00 SPY.DIA 100 @ 9.78335984354628"
[1] "2011-04-13 00:00:00 SPY.DIA -100 @ 9.02241069100391"
Realized PL: -63.23097
[1] "Object for parameter distribution initialized..."
[1] "Parameter constraint object initialized..."
[1] "ParamTable generated"
numValues: 5, numResults: 0, stopped: TRUE
got results for task 1
accumulate got an error result
numValues: 5, numResults: 1, stopped: TRUE
returning status FALSE
got results for task 2
numValues: 5, numResults: 2, stopped: TRUE
returning status FALSE
got results for task 3
numValues: 5, numResults: 3, stopped: TRUE
returning status FALSE
got results for task 4
numValues: 5, numResults: 4, stopped: TRUE
returning status FALSE
got results for task 5
numValues: 5, numResults: 5, stopped: TRUE
not calling combine function due to errors
returning status TRUE
Error in { (from spread-sweep05.R#193) : task 1 failed - "argument is of length zero"
> sessionInfo()
R version 2.15.3 (2013-03-01)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8  
 [7] LC_PAPER=C                 LC_NAME=C                
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C      

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods  
[8] base    

other attached packages:
 [1] doMC_1.3.0                 iterators_1.0.6          
 [3] quantstrat_0.7.7           foreach_1.4.0            
 [5] blotter_0.8.14             PerformanceAnalytics_1.1.0
 [7] FinancialInstrument_1.1.7  quantmod_0.4-0            
 [9] Defaults_1.1-1             TTR_0.22-0                
[11] xts_0.9-3                  zoo_1.7-9                
[13] vimcom_0.9-8               setwidth_1.0-3            

loaded via a namespace (and not attached):
[1] codetools_0.2-8 compiler_2.15.3 grid_2.15.3     lattice_0.20-13
[5] tools_2.15.3

spread-sweep05.R
Reply | Threaded
Open this post in threaded view
|

Re: quantstrat spread parameter sweep problem

braverock
On 04/20/2013 09:29 AM, Rob Schmidt wrote:

> I am stuck on making a parameter sweep of a spread and have attached
> the version that gets the farthest before failing.  This has driven me
> to extreme measures like reading the documentation and trying to upgrade
> my debugging skills.
>
> The code gets through the basic calculations and makes a chart so the
> spread definitions seem ok.  But it fails in applyParameter.  The variable
> values are reasonable as far as I can tell until %dopar% in the foreach()
> command in parameters.R.  Then the debugger takes the rest of the
> command in {} as a big chunk and my modest debug skills fail.  This
> sweep code works when I use a single contract rather than a spread.
> Here is the error.  The traceback points to the chunk of code after
> %dopar% so I won't repeat that.

%dopar% is running in parallel.  Obviously you can't get a debugger down
into the child processes (debugging for parallel computing is an even
darker art than R coding).

You may be able to debug into your problem by calling registerDoSEQ()
before running your script, to force foreach into single threaded mode
so that you can debug into the foreach loop.

> Error in { (from spread-sweep05.R#193) : task 1 failed - "argument is of

This is saying the error is on line 193 of your script, but I suspect
that you're going to come back and say that is the applyParameters line.

Now that I've said all that, we've moved all our development attention
on parameter code to apply.paramsets instead of applyParameters.  The
old code wasn't extensible enough, and we've basically abandoned it in
favor of a more flexible apporoach, and a refactored code base.

You can see all the documentation, and you should be able to find the
code in the paramsets.R file in the source.  One of the luxor demos uses
the paramsets code, so you shjould be able to find example code to start
from as well in modifying your parameter specification.

Regards,

Brian

--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: quantstrat spread parameter sweep problem

Rob Schmidt
Hi Brian,

Thank you for your helpful suggestions.  The paramset method is working much better.  For completeness, I'm attaching a minimum parameter sweep example using apply.paramset() based on a simple moving average crossover.  It is a mangle of a small piece of the luxor demo.  It does make a warning about GBPUSD being the name of a currency about which I have no clue.

Best regards,

Rob

spread-sweep08.R