I think there are two possible ways: 1. day open, close, high, low, volume separately into array, then I have 5 arrays to work with my calculation 2. Put all of these into one array or linklist to do the calculation.

I think the 1. would be more easy to handle all backtest calculations, do you agree?

Background information: I would develop my system with Java and run in either Windows 7 64 bits/ Ubuntu 64 bits. I will eventually connect the live trading version to Interactive Broker Java socket API.


2 Answers 2


Go with the multiple arrays. This would give you a column-oriented store, which is far more cache-efficient when handling time-series data. Specifically, you are describing an "in-memory" database table that can be queried.

You'll also want to think about how to do your look-ups. Will you have a hash table that maps symbols to OHLC tables? Will you partition the tables by date? Think about what kind of queries you're going to run, and then structure your data to make this search easiest.

  • $\begingroup$ I second your latter paragraph. In some cases storing the data in segregated arrays will be computationally more intensive than storing data of identical time stamp in a struct or class. I coded up my own binary data store and query engine and it ended up to be a lot faster than kdb for standard queries. The data store manages blobs by time stamp rather than segregating out by columns. Obviously my own custom solution only supports what I need and a fraction of what kdb offers. It all comes down what queries need to be supported. $\endgroup$
    – Matt Wolf
    Commented Sep 1, 2013 at 15:39

Considering it is backtesting and ultra-performance is not very relevant**, I would suggest following good OOP principles:

  • create a BarData class which holds the fields you need (date, o, h, l, c, v etc.)
  • store the BarDatas in an ArrayList<BarData>

You can then store several time series in a Map<String, List<BarData>> or a guava MultiMap<String, BarData>.

That should make your life easier.

ps: I don't know the IB API - if they have built-in types that look like my BarData then you sould as well use them directly.

**And note the the difference of performance between arrays and ArrayLists is not that big for most use cases.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.