i have certain values whose calculations are complex but do not change during each pass of the optimization (in other words, i'm optimizing for other values, not these).
is there a way to not have to recalc those blocks of code on each pass of a backtest?
three ideas i had were:
1. put that code in an indicator, write the values to a file and somehow put that data (from the file) into a data stream and treat it like another price series (so the bars line up)
2. i have (but rarely use) the C# version of MC - could i pull that file into an array and make available to the parts of the code that are being optimized?
3. it would be ideal if MC could add a new "code block" similar to "once" but had the effect that it would run the code inside of that block on every bar in the chart but only on the first pass of an optimization - then those values would remain static (on a per bar basis) and available to the rest of the code as the backtest runs thousands of times.
anyone have any ideas?
only calc on first pass of optimization
Re: only calc on first pass of optimization
Barstatus 0 is prior to first tic of bar
But during a backtest that is run 10,000 times, won't it be recalcd every time?
I'm trying to find a method that only runs once, not 10,000 times
But during a backtest that is run 10,000 times, won't it be recalcd every time?
I'm trying to find a method that only runs once, not 10,000 times
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: only calc on first pass of optimization
Where did you get this idea?Barstatus 0 is prior to first tic of bar
::
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: only calc on first pass of optimization
You can add a counter...
Code: Select all
var:
counter(0);
if counter = 0 then
begin
counter = 1;
// put your code here
end;
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: only calc on first pass of optimization
I don't think this is possible since each optimization run acts like a separate signal (that just has different inputs). Perhaps you can put the calculated values in a global variable, but since optimisation is multi-threaded you'd still would have to calculate the code more than once.it would be ideal if MC could add a new "code block" similar to "once" but had the effect that it would run the code inside of that block on every bar in the chart but only on the first pass of an optimization - then those values would remain static (on a per bar basis) and available to the rest of the code as the backtest runs thousands of times.
So your best bet would probably to load these values from a file at the beginning of each optimization run. Such a thing could be done by ELCollection or ADE, but I'm not sure how much you'd gain with this -- reading the data from the file can take more time than calculating the values once at the beginning of every calculation (depending on your computer hardware and code complexity, of course).