Best practice for backtesting from external CSV files

I want to write afl code to read values from a CSV file and then use those values as part of a trading system. The file will have columns "date", "symbol", "value1", "value2", "value3". There will be 500 symbols stacked and at least 5 years of values per symbol.

It's likely I will use the same data repeatedly as part of multiple optimizations and backtests, so run-time efficiency is important. Proper date-alignment is also essential of course.

I'm sure there are multiple ways to load the data. One approach is importing the data into the database and referencing foreign(). Another approach is loading the data into static vars. Are there other better approaches?

What is the recommended best-practice for this use-case?

1 Like

@steve, considering you have less than 8 extra values ​​to store per symbol, for efficiency and ease of use I think the database option (importing them as extra symbols and referencing them with Foreign()) in my opinion is the best one to use.

1 Like

@beppe Thank you for the recommendation. I've been away from this community for some time and have forgotten some aspects of AmiBroker system development. May I ask, what is the significance of having fewer than 8 extra values to store per symbol?

Each AB quote/bar has 8 fields, OHLCV, OI, Aux1 & 2 and store your custom data.
@beppe means that up to 8 values you can you these fields without worrying about "bar" alignment with timestamp.
For more values, you would need more than one artificial ticker to align the data.

The best approach is to import data as artificial tickers and access them just as he has wriiten.

1 Like

@nsm51 That makes sense, thank you for clarifying.