Error: Index was out of range. Must be non-negative and less than the size of the collection.
Author: wbzhang
Creation Date: 5/10/2011 11:15 AM
profile picture

wbzhang

#1
I am using wealth-lab dev 6.1.27.

I have below problem during backtesting:
Error processing symbol YUM Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

If I change BuyAtMarket(bar+1) to BuyAtMarket(bar), this error disappears. However, I indeed need to buy at bar+1. I think the system will need to generate an "Alert" if the "bar+1" beyond the scope of my dataset, but should not be an error.

However, this does not happen to all dataset. But I debugged a lot, this seems a system bug still. Any suggestions?
profile picture

Eugene

#2
The "system bug" is in your code. This will help you find it:

Errors | Strategy > Index was out of range
profile picture

kendalab

#3
I'm having this same problem "Index was out of range. Must be non-negative and less than the size of the collection" when running a script against Option symbol data. It only happens with a few option symbols, but still it happens. I assumed, based on your message, the error was mine so I commented out all of my custom code and still received the error. Next, I created a "new strategy from rules", selecting buy at market and when RSI is oversold level and ran it against a dataset of option symbols. One of the symbols creates a Debug and Error Message Log (popup). The symbol has zero current day volume, but does have open contracts. Two other symbols in the same dataset have the same zero current day volume and open contracts, but aren't generating the error. Option symbol QQQ, Oct strike dates, strike price 104 is the one currently kicking the error. That's the only one at the moment giving the error, but I seem to get more errors on other symbols in the mornings. Any ideas?
profile picture

Eugene

#4
There's a handful of reasons to this error, and all are nicely summarized by the link in my reply above:

1. accessing the data at an invalid bar number.
2. accessing the data that does not exist (e.g. empty symbol data, symbol stopped trading)
3. accessing a Position that does not yet exist
4. if it happens with only some symbols on some bar scale, the drawing object for that symbol (.DRW file) could have gotten corrupt
5. erroneous ASCII data

Bearing in mind that option symbols may have a history too short to build your indicator(s), the two most likely culrprits are above on top of excluded causes. Corrupt drawing objects is something to consider only if you did draw some lines on their charts manually.
profile picture

kendalab

#5
If there is so little data that back testing doesn't make sense, I wouldn't mind the generated error, but when I get an error, columns go missing from the "By Symbol" tab. Is there possibly a way to test for or trap "bad options" so the columns don't disappear? I suppose it is also possible erroneous results are generated from too little data in the option symbol. Hmmm.
profile picture

Eugene

#6
Highlight the DataSet name in the Data Manager, click "Symbol Details", notice the number of bars. Do some symbols have it less than the indicator period?
profile picture

kendalab

#7
Thanks, I had forgotten about the Symbol Details. Yes, two have less than the 20 bars available for the RSI indicator, but those two are not in the Debug and Error Message Log when I run the script this morning. Six other symbols are and they have from 40 bars up to 214 bars.
profile picture

Eugene

#8
Anyway, try re-running the backtest having excluded symbols with little data from the DataSet.

If that doesn't eliminate the error, please provide the following information:

1. WLP version
2. Complete Strategy code.
3. Wealth-Lab tool in use (Strategy Window or S. Monitor)
4. Symbol(s) and Data provider
5. Single symbol or Multi-symbol mode, Position Sizing, and Data Loading settings
6. Options (F12) from the "Backtest Settings" group
profile picture

Panache

#9
Another potential source of this error is that although the first bar is indexed at 0, Wealth-Lab will not let you buy until the second bar, ie. bar = 1. Attempting to buy at bar = 0 throws the Index out of range error.

CODE:
Please log in to see this code.
profile picture

Eugene

#10
That's right. It doesn't make any sense to buy at bar 0 because the basis price is yet to be determined.
profile picture

kendalab

#11
I don't mean to be dense, but when you say "having excluded symbols with little data from the DataSet.", do you mean the symbols in the error log or the symbols that have less than the "20" bars for the RSI period parameter or is there a way to determine a reasonable number of bars?

Speaking of dense, I'm starting to see why running this against option data may not be the brightest move. lol

Too bad "Symbol Details" doesn't let me select and delete after sorting by bars.
profile picture

Eugene

#12
QUOTE:
Too bad "Symbol Details" doesn't let me select and delete after sorting by bars.

The Data Tool extension lets one delete inactive or empty symbols, and more.

QUOTE:
do you mean the symbols in the error log or the symbols that have less than the "20" bars for the RSI period parameter or is there a way to determine a reasonable number of bars?

Sorry for not being clear. Firstly, try removing those that have less than 20 bars. Then, I'd 2) run the strategy on individual symbols, 3) exclude those that trigger the error message etc.
profile picture

kendalab

#13
Thanks for the Data Tool info. With it I was able to remove symbols that had 20 and fewer bars, which seems to have resolved any errors being reported to the log when the script runs. Thanks for all the help.
profile picture

Eugene

#14
Glad to have helped.
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).