The Gateway to Algorithmic and Automated Trading

Technology Workshop: Java - Your High-Frequency Friend

Published in Automated Trader Magazine Issue 02 July 2006

An article in the April issue of AT (“You’re using what?!”) questioned the suitability of Java for high frequency automated trading. Matt Schruben, Principal Consultant, Random Walk Computing and Jim Levey, Director of Marketing, Random Walk Computing provide a different perspective.

Matt Schruben, Principal Consultant, Random Walk Computing

Matt Schruben

Automated trading today is typically associated with complex systems that integrate market data feeds, order management, messaging engines and other financial applications into a cohesive framework to manage global trading in high frequency securities and their derivatives. On the buyside, these systems are often driven by algorithms that can pump orders directly into the market using intelligent routers that connect to exchanges, ECNs and crossing networks. Or, buyside traders can send orders directly to agency desks whose systems are designed to achieve best execution for their clients. On the sellside, much of the order flow is internalised either for proprietary trading or matching engines.

Automated trading is a requisite for institutional organisations contending with a shifting market structure, mounting regulatory pressures and accelerating competition from all corners of the globe. In simple terms, automated trading is characterised by systems that automatically consume market data, compute and transmit orders accurately and in a timely fashion (orders must be sent before the opportunity closes). Automated trading has some inherent constraints, however. The amount of trader interaction can be limited and interruptions to order flow can jeopardise trading opportunities. Yet, the continued "electronification" of securities and the inability of traders to process and respond to accelerating volumes of data in a timely fashion demands even more automation.

"...automated trading is characterised
by systems that automatically consume
market data, compute and transmit orders
accurately and in a timely fashion"

Automated trading systems can vary widely based on the parameters of the business, existing technologies and trading partners. In institutional environments systems are tasked with consuming an exponential increase in market data to perform complex analytics, parsing block orders algorithmically before sending them into the market and finally, storing completed transactions in secure environments for regulatory purposes. As a result, managers must develop highly available solutions that are scalable, flexible, adaptive and easy to modify in order to respond to ever changing market conditions.

In consideration of the above, how does a financial organisation balance the demands of performance, quality, time-to-market and costs when developing new systems for automated trading? The answer is unique to your business. New systems development depends upon correctly aligning advanced technologies with business goals in order to assure a smooth transition to the new environment. Strategic preparation in advance will ensure that management and user expectations are met and a favourable return on investment is achieved. Getting there depends upon many factors not least of which, is the development platform, methodology and selection of programming languages.

As a modern programming language, Java is the language of choice for financial applications, proprietary trading solutions, electronic exchanges and messaging engines. There is a reason why the leading FIX Engines use Java. Its advantages include reduced time to market, comparable performance to other languages, and increased stability when developing modular and adaptable applications, such as today's trading systems.

Java enables the development of highly reliable systems in short time frames because of its facility for programming ease and quality assurance. Plus, because of its core ability to port across platforms, automated trading systems written in Java can be easily deployed to next generation operating systems and hardware.

Java is an object oriented development environment that interprets objects by translating them into bytes that, in turn, are translated into machine code readable by standard operating systems across platforms. While the fact that other object oriented languages (C++) compile directly into machine code would lead you to believe there should be a performance boost. In fact, improper memory management often makes the opposite the case. Virtually all contemporary benchmarks show that Java offers comparable performance to C++, particularly in math-related areas. What's more, the language has several other significant advantages for complex development projects.

Jim Levey, Director of Marketing, Random Walk Computing

Jim Levey

"...the leading FIX
engines use Java"

Managing Memory for Superior Performance

Enhancing performance in automated systems can be achieved through efficient application level memory management. Keeping track of memory usage is very time consuming, complicated and error prone. Java is superior due to its ability to manage memory inefficiencies that can arise from premature de-allocation (corrupted pointers) of memory and/or incomplete de-allocation of memory (memory leaks).

De-allocation problems impede system performance when an application attempts to access an object that is no longer there. There are two sub cases: design bugs and coding bugs. Design bugs are language dependent. Coding bugs, on the other hand, do not depend on the language; instead, they involve simple programmer negligence.

Memory leaks, which unnecessarily drain memory from vital tasks, are caused by objects that are no longer in use. In other languages it is the developer's task to delete garbage and correct corrupt pointers. In Java, these tasks are automatically managed by the system using a utility called garbage collection, which automatically reclaims memory in objects that are no longer available to the program.

Poor memory management is magnified in complex transaction systems and is particularly difficult to manage in systems developed in C++ where teams of developers work in concert. One developer's error can dramatically impede overall systems performance and can be extremely difficult to pinpoint. In fact, in languages like C++ the more you try to avoid memory leaks, the more likely you are to create corrupted pointers, and vice versa.

In C++ the programmer handles all memory management. The burden is on the programmer to ensure code is free of memory defects. As system complexity grows, so does the likelihood of such defects.

In Java, on the other hand, the Java language and JVM runtime together limits the possibility of corrupted pointers and memory leaks. Here's why:

  • Memory is only allocated to objects by creating memory for new objects. (Java even treats array types as objects.)
  • Runtime employs a garbage collector to de-allocate the memory occupied by objects once the collector determines that the objects are no longer accessible. This is safe because the garbage collector does not free the object's memory if it is still needed elsewhere. Therefore, removing the reference to an object never runs the risk of corrupting other references.
  • Unlike C++, in Java it's easy to release an entire family of objects by setting the reference to the root to null; the garbage collector will then reclaim all unreferenced objects. This is a lot simpler than tracking each of the objects' references so that the destructor can be called to release memory after there are no dependencies.

The Java Garbage Collector

Another important consideration is systems architecture. Well designed systems can effectively address memory management issues. Good design considers long lived objects that need to be released from memory. Moreover, design errors stem from the failure to account for all the references to an object in the system. Consequently, a small fault in the algorithm to manage the objects would be magnified.

In summary, Java provides a structure for memory management that helps ensure superior performance. This can reduce the number of programming hours and dramatically shorten delivery time for complex software systems.

Innovation for Competitive Advantage

One of the challenges of applications development is to utilise existing code in environments where proprietary trading solutions incorporate complex rules and business logic. In programming, methods exist that do not need to be rewritten. Object-oriented languages use "polymorphism" to achieve code re-use by allowing objects of different types to respond differently to identical method calls. For example, objects share a common interface with their parent class but may have a very different implementation.

Extending polymorphism to multiple types is different in C++ than Java because in C++ developers must contend with multiple inheritance or templates both of which present additional complexities. If two functions look identical (to the application) which one takes precedence? Rules that decide precedence in C++ can be ambiguous. It's difficult to determine which parent method would be called. This can lead to confusion in code maintenance particularly among a large team working in concert to develop a complex system.

On the other hand, Java provides "interfaces" which provide a programmer with a simple means to treat an object as two unrelated classes. This allows methods to share resources in the application, dramatically simplifying the on-going tasks of code maintenance and system versioning - an enormous cost and time saver in complex development projects.

"Quants are constantly rewriting algorithms to
accommodate new trading strategies"

A practical example of how efficient code re-use can impact the adaptability of an organisation to changing business conditions is to view the relationship between the programming staff and the "quants." Quants are primarily responsible for re-engineering algorithms, the intellectual property which distinguishes their products and services in the marketplace. In large portfolios, a significant number of correlations must be run to assess risk before trading strategies are put in place. "Quants" are constantly rewriting algorithms to accommodate new trading strategies. Risk management solutions that draw data from disparate sources throughout the enterprise require a cohesive framework for compute intensive applications. Systems written in Java can be easily modified with high quality. Adjustments to algorithmic modelling strategies such as VWAP, TWAP, stat arb, implied trading and other innovative models, can be accomplished in short time.

Quality and Reliability You Can Depend On

In one sense, Java is a platform, more so than a language. In the past decade, it has evolved into a broad development environment with robust tools and utilities that allow developers and architects to build new systems that ensure maximum uptime and scalability in multiple environments. Fast, portable and bullet-proof applications written in Java are superior to other languages that are orders of magnitude more complex and error prone.

The delivery of custom trading applications is more about using what makes sense. The Java platform provides state of the art tools for developing, debugging and deploying a high performance system. It offers a means to manage memory that does not solely rely on the programmer. It has simple and effective ways of implementing object-oriented designs that allow for a team of programmers to implement a system that is easily adapted to ever changing business conditions.

In these situations where automated trading systems are the lifeblood of an organisation, Java enables enormous programming efficiencies that result in superior performance, availability and time-to-market.