Is there an easier way to end an optimization programatically?
Author: Panache
Creation Date: 10/27/2018 5:48 PM
profile picture

Panache

#1
I think I have all the error checking I need to make sure my strategies run correctly. However, I sometimes make mistakes setting the correct values when I optimize them. Therefore, I would also like to run an error checking routine on the strategy parameter values in the optimization. The puzzle piece I am missing is a simple way to cancel the optimization if there is an error.

This works:
CODE:
Please log in to see this code.


However, it requires me to remember to add a
CODE:
Please log in to see this code.
line for each strategy parameter. Is there a simpler way to programatically end an optimization?
profile picture

superticker

#2
QUOTE:
Is there a simpler way to programmatically end an optimization?
Sounds like a trick question. :)

The way it's typically done in procedures is to add a negative return code in the final executable statement.
CODE:
Please log in to see this code.

But this -1 return code will then be passed back to the optimizer. And I'm not sure the WL API for the optimizer defines what to do with a negative return code. I suppose you could hack the optimizer code and have it test the return code and return control back to Wealth-Lab if it's negative or even throw an error. Perhaps the WL API for the optimizer should define this as the default behavior.

The other approach would to the intentionally throw an error, but this should only be done for exception handling. Are you trying to handle an exception? If so, which WL exception are you looking to throw? What's the nature of this error? (Why are you generating exceptions in the first place while optimizing? Are you debugging an optimizer?)

The fancy way to do this would be to write your own exception handler (class) that calls your dialog box, then use the throw statement to call that handler. The quick and dirty way to do it would be to intentionally divide by zero as "Proof of concept". I don't like the last way.
profile picture

Panache

#3
Thanks superticker.

What I was missing from my simple solution was existence of the list Parameters, which appears to contain the information for each Strategy Parameter. Therefore, this works regardless of the number and names of the Strategy Parameters
CODE:
Please log in to see this code.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).