Is there a way to not rerun some methods during optimization?
Author: Panache
Creation Date: 10/24/2018 11:31 PM
profile picture

Panache

#1
Before my Strategies get ready to trade, they do a number of things which need not be repeated during each optimization run, ie. checking to make sure the correct data set is being used, which, since it involves reading files, is relatively slow.

What I would like to do is to have this only run once per optimization to decrease the time it takes to optimize the Strategy. Is this possible?

I thought this might work:
CODE:
Please log in to see this code.
but it appears that the optimizer executes the Strategy once before the optimization begins, because firstRun is true on the first optimization run (and all the others).

I realize this may only be reducing the run time by a second or less, but even saving 1 second per run over 10,000+ runs during an optimization is a big deal.
profile picture

Eugene

#2
Two ways come to mind:

1. The initial combination of the Strategy parameter values is always known e.g. "Test = 0" ("Test1 = 0", "Test2 = 0.25" etc.) There can be only one such run (on the first symbol of a DataSet). When this pattern matches, your code knows that this is the real first run.

2. You could use Wealth-Lab's GOP (global memory): save some state with SetGlobal and later make checks with GetGlobal.
profile picture

Panache

#3
Good ideas Eugene.

QUOTE:
1. The initial combination of the Strategy parameter values is always known e.g. "Test = 0" ("Test1 = 0", "Test2 = 0.25" etc.) There can be only one such run (on the first symbol of a DataSet). When this pattern matches, your code knows that this is the real first run.
This sounds like the best solution for me. Here is my sample code to implement this:
CODE:
Please log in to see this code.


QUOTE:
2. You could use Wealth-Lab's GOP (global memory): save some state with SetGlobal and later make checks with GetGlobal.
If I understand the QuickRef for this correctly, the downside of using this approach is that I would have to close Wealth-Lab Pro before I could optimize a different Strategy. This would make things more difficult for me, since my pre-processing would be different if even if I optimized the same Strategy again, using a different time period, for example.
profile picture

Eugene

#4
Agreed that #1 is the most straightforward option. StrategyParameter.Start is the way to go.

Just to clear up on this:
QUOTE:
the downside of using this approach is that I would have to close Wealth-Lab Pro before I could optimize a different Strategy

You could clear a Strategy's unit global memory with RemoveGlobal and the whole vault with ClearGlobals without having to close WLP/D.
profile picture

Panache

#5
QUOTE:
Agreed that #1 is the most straightforward option. StrategyParameter.Start is the way to go.


Is there any way to check whether a strategy is being optimized? This code works great for optimizations, but if I want to generate alerts (and have my strategy parameters set to anything other than their start values), it is not going to execute the pre-trading code. Therefore, I'm looking for something to add to my if statement to run the pre-trading code when the strategy is not being optimized.
profile picture

Eugene

#6
QUOTE:
Is there any way to check whether a strategy is being optimized?

See the IsPricePane property's example code in the QuickRef. Since chart panes are N/A in optimizations, the Strategy Monitor case also applies to optimizations.
profile picture

Panache

#7
Thanks Eugene.

In case someone looks at this thread in the future, the if statement should be changed to:
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).