Two Java trading system technical questions

Discussion in 'App Development' started by GloriaBrown, Aug 30, 2013.

  1. dholliday

    dholliday

    Hi vicirek,

    Be very careful about the assumptions on the structure of the data in a data engine.

    When I built my trading platform I spent a lot of time exploring different data structures and architectures. My primary concern was speed and flexibility, processing tick data for a large number of symbols in real-time, not back-testing or processing bar-data (I build bars in real-time from tick data). I am closer to the "multiple arrays" camp, and it is much better for what I value most. That said, the data structure I use is an implementation of an interface with methods like:
    public void add(double dValue)
    public double getPreviousValue(int nPrev)
    Since it is an interface I can implement it any way I like.

    On the other hand the OP did mention Open, High, Low, Close, so they are probably building something different than I built, so you may be right, just put it in a "Bar" data structure.

    Take care,
    -David

    PS I do store historical tick and bar data in CSV files. One file for each symbol/timeframe.
     
    #11     Aug 31, 2013
  2. dholliday

    dholliday

    I believe the get() and set() will be optimized out by the JIT. There is no speed penalty.

    That said, when I am using a class that is equivalent to a C struct, and only use it locally, I just make the variables public. It is really much cleaner IMHO. Though I use only Java now, I was a C++ programmer for many years.

    -David
     
    #12     Aug 31, 2013
  3. vicirek

    vicirek

    If you construct bars from ticks with unknown number of ticks per period then best is to use container like queue (vector) per each symbol (kept in array or another vector). At the end of bar period just get first last min max (ohlc), empty vector and start acquiring ticks for next bar. No need to store ticks for entire day, no need for extra counter for arrays or worry about going past the end of array. Only problem to solve is how to account for empty bars (no trades, no quote updates, or feed issues)

    For in memory storage I prefer to use containers as well holding bar structs (if using bars).

    For disk data storage binary file is probably faster and more compact.
     
    #13     Aug 31, 2013
  4. you are tangling stuff all together.

    1) price attributes (open/close/high/low), create a value object and put all of them inside ( google: java encapsulation example). It's one of the fundamental concept.

    2) backtest looping: get a real database - mysql to store the data, then loop through them via resultset, use a util method to populate the above value object while looping. Unless you have a very specialized performance need for in-memory data structure always use a database, laziness is not an excuse.

    3) if you require a large number of those value objects for calculation, see if the calculation can be done via sql instead.

    google web toolkit (gwt) + smartgwt (widget templates).
     
    #14     Sep 10, 2013
  5. dholliday

    dholliday

    Yes, use separate arrays.
    Don't use a data base to store your data-sets.
    Take care.
     
    #15     Sep 10, 2013
  6. @dholliday - could you tell if you are consistently profitable? - thx.
     
    #16     Sep 10, 2013
  7. dholliday

    dholliday

    No, I lose a little bit on each trade... but I make it up on volume.
     
    #17     Sep 10, 2013
  8. "...but I make it up on volume." -- you mean you are paid for the limit orders?
     
    #18     Sep 10, 2013
  9. dholliday

    dholliday

    Thanks for the investing humor. I laughed.
    Seriously, my trading has never set the world on fire and probably would not impress you or anyone else.
    Take care,
    -D
     
    #19     Sep 10, 2013
  10. Thanks for sharing in any case.
     
    #20     Sep 10, 2013