Java/Linux advantages for algo trading

Discussion in 'Automated Trading' started by swinging tick, Feb 17, 2022.

  1. Hi folks,
    I notice many algo traders (better ones) write their algos in Java/Kotlin. I wonder if there are advantages of Java over C#, Go or other langs for algo trading? Also, is Linux really better for trading setup than Win?
    My backtesting engine and trading logic are written in scripting language (almost finished now, not running live yet). Im curious as to whether I'm missing on smth by not using Java/Linux setup.

    I would appreciate if somebody could educate me on this.

    @FreeGoldRush @ValeryN , if you guys could also chip in on this discussion, I would be grateful.
     
  2. Databento

    Databento Sponsor

    There are many generic reasons to prefer Linux over Windows for general servers or workstations, which is a debate that has been around for decades and pointless to rehash here. But specifically for trading:

    - Plenty of UNIX utilities with widely shared and public resources on their use cases. To name a few:
    - tcpdump for debugging connectivity issues
    - telnet for testing wire protocols
    - PTP daemons like ptp4l for time synchronization
    - taskset to bind application to specific CPU cores
    - turbostat to check CPU frequency
    - netperf for measuring network performance
    - ssh out of the box with most distros for remote access​
    - Easy to configure for performance, e.g. kernel parameters for lockup thresholds, overriding of BIOS C-state settings, wake-up preemption granularity MCB polling.
    - Frequent releases of kernel support for features like hardware clocks etc.
    - Open kernel source makes it easy to understand performance and patch parts for optimizations.
    - Accessible documentation and guaranteed compatibility with tools, libraries and drivers etc., e.g. for RDMA, userspace networking, commercial messaging frameworks.

    As for the preference for Java, I think it is mostly a social one. Java was dominant around the period of peak growth for electronic trading, so naturally many top latency and performance engineers in the space had Java experience and there are now many public resources (guides, open source projects) which make it easy for you to piece together a trading system in Java.

    Java also had better cross-platform support than C# (.NET-based) before Microsoft put their weight behind Mono. And compared to many languages, it had mature desktop GUI development frameworks. Many firms evolved from a front office environment with Windows desktops to support Bloomberg, Excel spreadsheets and manual traders, and so Java adoption helped maintain a unified code base for both their server applications and desktop GUIs.

    You'll probably find a higher density of people working in electronic trading firms when attending a C++ meetup than a Java meetup in Chicago though.
     
    Last edited: Feb 17, 2022
  3. Snuskpelle

    Snuskpelle

    About ten years ago at least, the JVM was massively better than .NET at garbage collection (as in, taking more to completely overpower a heavily threaded application with GC stalls). I am less confident about nowadays simply because I haven't been writing these kinds of applications lately, and I expect Microsoft to have kept working on their GC. Nonetheless, if you have an application doing e.g. heavy messaging (algotrading and especially backtesting can fall into that category) that's something to investigate before you choose one or the other.
     
    swinging tick likes this.
  4. rb7

    rb7

    I would say, it doesn't matter.
    You should concentrate your energy in making money, not in choosing which language is best.
    The best language would be the one you are the most comfortable with.
    The language you chose will not make any difference on how much money you will make as a retail trader.
    FWIW, my system has been coded in VB and C++ under Windows, just because I knew them when I coded it.
     
    HobbyTrading, d08 and swinging tick like this.
  5. @Databento
    I really appreciate you taking time to write such a detailed answer!
    Some of the Linux stuff you mentioned is above my level of knowledge at the moment, but its very interesting, Im going to save your post and use it as a guide in my learning and system developement.
    Thanks!!!
     
    Databento likes this.
  6. I agree. For me the fastest way of developing/testing algos is by writing them in a scripting language. But for a heavy lifting like optimizing parameters on a huge data set, smth like C/C#/Go/Java is needed. My choice for that has been Dlang so far (speed comparable to C++ but simpler syntax, for those unfamiliar).
    Im relatively new to algo trading, so its good to learn from people who walked this path before me, why they chose one setup or another.
     
  7. DaveV

    DaveV

    The Java and C# languages are almost identical. In fact C# was developed by Microsoft after Oracle, who owns the Java copyright, sued to prevent Microsoft from making changes to the Java language. The libraries that are commonly associated with Java and C# however, are vastly different.

    Linux is a much slimmer O/S than Windows, so on a given CPU, Linux will always run faster and have less than can go wrong. Note however that there are some financial software that is only released for Windows, and may not work correctly with Wine.

    No disrespect, but this is classic nooby talk. You haven't finished version one of your system yet, and already you are getting distracted with thinking about porting it to another language or O/S. Old programmer saying - First make it work, then make it pretty.
     
    persistence, swinging tick and rb7 like this.
  8. ValeryN

    ValeryN

    I’d say go with what you know the best. You probably don’t want to be figuring out intricacies or a new programming language while increasing risk of order duplication or opening wrong positions etc.

    There are some great traders who never used Linux or Java. I went with that combo because I know both well and it’s highly performant. Besides, JVM has the largest libraries eco system. Pretty much anything you can think of was already done and packaged in a library. I find Kotlin in particular much safer than Java and very pleasant to write code in.

    I’d stay away from pure scripting/non compilable languages. They’re great for a small project but things tend to get out of hand faster than you’d expect. Performance and multi treading there tend to be an afterthought and becomes a bottleneck eventually. Don’t go with anything exotic that you won’t be able to find libraries for either.

    If you already have nearly complete project just keep going with what you are using. If eventually your pain points accumulate then consider something else.
     
    Occam, swinging tick and DaveV like this.
  9. Thank you all for the answers!

    Guilty as charged! ))

    @ValeryN , thanks. yes thats exactly what Im struggling with: 20k lines in AHK (scripting lang) for algo and backtesting engine + 2k lines in Dlang for param optimization = lots of pain in ass to rewrite all this in another lang. In AHK, which is multi-threaded, algo takes 40ms per symbol/time frame to analyze and issue verdict on trade, which needs to be done every 1-3 minutes. It sems ok for now. Probably I'll follow yours and DaveV advice and stick with what I have til things fully work, and only then start porting to Java/Linux (or C#/Mono on Linux)
     
    ValeryN likes this.
  10. ET180

    ET180

    C# was developed in 2000, about a decade before Oracle acquired Sun and got Java.

    For the purposes of automated trading, what you really want is a real-time OS or as close as you can get to a real-time OS. No version of Windows is a real-time OS (actually, Windows 10 IoT might be, haven't heard of it before). Some versions of Linux and BSD are.

    https://www.ni.com/en-us/innovation...-is-a-real-time-operating-system--rtos--.html

    Of course, the JVM and the garbage collector in Java introduces some unpredictable latencies, but good programming can mitigate a lot of that.
     
    #10     Feb 17, 2022
    d08 and swinging tick like this.