- ago
I'm writing a strategy which will build a TimeSeries containing the average of all the securities in a dataset within PreExecute (Build B53). Based on my tests and the example in the Coding QuickRef, the TimeSeries built in PreExecute needs to be declared as static so all securities can access it when a Portfolio Backtest is run (multiple securities). I had this strategy working well running backtests against the dataset; however, there were issues when I tried to use the optimizer to tune parameters.

I opted to optimize one parameter in Exhaustive mode which would result in 20 permutations. Every time I run this I get 'Index out of Range' exceptions on the 'Basket' TimeSeries built by PreExecute and the messages appear different with each run of the optimizer.

QUOTE:
Timestamp Source Message Exception
"4/7/2022 11:10:39:515" "WL7" "Specified argument was out of the range of valid values. (Parameter 'Index out of Range: ( , 426) ')" "Specified argument was out of the range of valid values. (Parameter 'Index out of Range: ( , 426) ')"
"4/7/2022 11:10:39:516" "WL7" "Specified argument was out of the range of valid values. (Parameter 'Index out of Range: ( Basket, 426) ')" "Specified argument was out of the range of valid values. (Parameter 'Index out of Range: ( Basket, 426) ')"
"4/7/2022 11:10:39:516" "WL7" "Specified argument was out of the range of valid values. (Parameter 'Index out of Range: ( Basket, 7) ')" "Specified argument was out of the range of valid values. (Parameter 'Index out of Range: ( Basket, 7) ')"
"4/7/2022 11:10:39:788" "WL7" "Specified argument was out of the range of valid values. (Parameter 'Index out of Range: ( Basket, 91) ')" "Specified argument was out of the range of valid values. (Parameter 'Index out of Range: ( Basket, 91) ')"


I think I've isolated the code to be within the Execute method when it attempts to access the TimeSeries built by PreExecute with a description of 'Basket'. Once I comment out the line, I no longer get that exception when running the optimizer.

CODE:
   int bidx = _tsBasket.IndexOf(bars.DateTimes[idx]);    BasketSum += _tsBasket[bidx];   // error line


Question: Do you run parallel backtests with the optimizer in multiple threads?? If so, I'm guessing I'm running into race condition where all parallel tests are trying to manipulate the same static 'Basket' TimeSeries variable at the same time.

Is there a way around this so I can use the optimizer on this strategy.
0
772
Solved
3 Replies

Reply

Bookmark

Sort
- ago
#1
Did you choose the non-Parallel optimizer?
0
Best Answer
- ago
#2
Bingo! I did not. I didn't notice there was such a thing. That appears to fix my problem.

Thanks!!
1
- ago
#3
Glad to see you're up and running again!
0

Reply

Bookmark

Sort