📜 ⬆️ ⬇️

Development of trading systems for FPGA: Pros, cons and analysis of the architecture of the existing library



Many high-frequency trading platforms often run on equipment with high-performance network adapters. However, the disadvantage of such systems is a relatively high and unpredictable delay - as a result, many traders turned their attention to hardware accelerated hybrid architectures.

Experts of Algo-Logic Systems Inc. Jowhn W. Lockwood, Adwait Gupte and Nishit Mehta published a paper on how FPGAs are used in online trading to reduce data transmission delays. We present to you the highlights of this publication.
')

Why speed is so important in HFT


Modern exchanges broadcast financial information through various data streams. Traders monitor these flows, analyze prices and demand for specific financial instruments (stocks, futures, options, etc.) to understand when and which deal to make - when the decision is made, an order is sent to the stock exchange to buy or sell the required instrument.

With the development of electronic commerce, the so-called high-frequency trading (HFT, High frequency trading) has become increasingly widespread - according to various estimates, already in 2010 on American exchanges more than 70% of transactions were carried out using algorithms.

HFT traders are trying to exploit emerging market inefficiencies. In this way, they not only make money, but also make financial markets more efficient. However, due to the growing number of high-frequency traders who are trying to capitalize on the same inefficiencies, only the first few traders can really capitalize on a certain opportunity. So, they need to get ahead of competitors.

The second important reason is the concept of slippage - in the case of highly liquid financial instruments (for example, stocks) after sending an order, say, to buy at a given price, the transaction may be less profitable, because until the order reaches the exchange, the price will change. Accordingly, the longer the delay from the time the order is generated until the moment it is executed, the greater the slippage can be, and as a result, the trader’s lost profit.

Thirdly, there are trading strategies, for example, the latency arbitrage, which essentially boils down to the fact that a trader should be able to get market information and send orders faster than other players. In this situation, every millisecond won can significantly improve the performance of the strategy.

Varieties of HFT-platforms


Currently, most traders and brokers create their own HFT-systems using popular software and hardware technologies. This allows us to describe algorithms using familiar high-level programming languages ​​(we have written here about which of them are used in the field of finance), and they can be quickly changed if necessary.

However, the pursuit of speed leads to the fact that the unpredictable response time of software systems becomes an obstacle to successful trading. Consider the existing software and hardware approaches to the creation of HFT-systems.

High Frequency Software Platforms

There is a fairly large number of companies offering high-frequency trading software (for Western exchanges, for example, Mantara, Ulink and QuantHouse). When using them, most of the delays come from the operation of the operating system on which the software is running, as well as the network stack. To deal with this, users can use high-performance network cards (for example, from Solarflare or Myricom), which accelerate certain parts of the network stack.

Custom HFT hardware platforms

The relatively high latency of software trading platforms has forced industry to look for alternative approaches to reducing delays using special hardware. As a rule, things like ASIC are not considered in HFT trading, since they lack the flexibility to later reconfigure or work with new protocols. GPU also can not offer significant speed. FPGA (Field-Programmable Gate Arrays) technology has become a suitable tool for gaining flexibility and achieving the required speed.

FPGA can be used to accelerate financial applications in various ways. One of them is called Hybrid Computing and is used, for example, in risk management models, option pricing and portfolio modeling — when applied, the system’s speed can increase by three orders of magnitude.

This approach complements conventional multi-core processors with FPGA co-processors. Typically, communication with the CPU is carried out using high-speed connectors like FrontSide Bus (FSB), PCI Express or QPI. The trade modules themselves are then written in high-level programming languages.

Another way to use programmable logic to accelerate is to use the so-called Smart NIC. Usually, this is a combination of high-speed network interfaces, PCI host interfaces, memory, and FPGA. Here, the FPGA acts as a NIC controller, acting as a bridge between the host computers and the network and allowing the integration of software logic directly along the data path. Thus, the Smart NIC can operate as a trading platform under the control of the host machine’s CPU.



Pros and cons of FPGA for high-speed trading


With the help of modern FPGA you can implement any aspects of HFT-applications. Incoming market data can be entirely processed on FPGAs without the need to send them to and from the processor. The figure below shows a comparison of the FPGA platform with a conventional software platform:



In the latter case, you need a network adapter to receive network traffic. The necessary part of it is then transferred to the processor, which is “interrupted” to process the application. After its completion, data is sent back to the network adapter and transmitted over the network. In this situation, an approach involving interrupts, as well as the presence of unpredictable delays during PCIe transfers and caching, increases network latency and makes it difficult to predict.

In contrast, in the case of FPGAs, incoming network data is “fed” directly to a custom, highly optimized system through the MAC and PHY iron blocks. Moreover, in fact, the necessary information can be extracted even before the package is fully received. Thus, the use of FPGA allows you to achieve a significant reduction in overall latency.



Cons of using FPGA

The use of FPGA has its drawbacks in comparison with traditional approaches to the development of trading systems. The root of the problem is the higher complexity of the development flow under FPGA. Much of the developers of financial systems and traders are not familiar with this technology and they lack the knowledge and expertise to implement hardware-oriented development.

Secondly, the development and testing of new hardware solutions due to a lower level of abstraction is a more complex and lengthy process compared to the usual writing of a trading robot. All of this is illustrated in the figure below:



To avoid this, some FPGA-based HFT platforms have special high-level environments that allow you to create trading systems without the need for hardware description languages ​​(HDL).

How it works: Algo-Logic Library


The low latency library from Algo-Logic is a gateway tool that is compatible with standard FPGA platforms. This tool processes the financial protocols used by exchanges in the United States, Europe and other countries, extracting information from the packets as they pass through the FPGA. Library components are used to build trading applications running at high speeds.

The library components are divided into two categories - infrastructure components (interfaces for the network, external memory and host software) and financial information processing modules (protocols, parsing processes, etc.). The figure below shows a more detailed description of these blocks:



Infrastructure components

All infrastructure components use a standardized interface with a 64-bit machine word. The SRAM controller provides low latency and high-performance storage for small amounts of data.

The register interface module monitors and monitors the status of registers into which software running on the host machine is written and read. It contains registers of various types, including write-only configuration registers, read-status registers, and the like. Configuration and status data is transmitted and received via UDP. Access to the register interface can be obtained through the C ++ API on the host or via the web GUI.

Financial Information Processing Components

The Algo-Logic library has IP blocks designed to handle high-frequency trading application level messages. These messages contain orders and reports on the execution of orders sent between clients, brokers and exchanges. Among these components are:

Financial Protocols Parser - receives data from the TCP / IP processing layer and determines the boundaries of the message. The parser then extracts the individual fields and sets the flag when the values ​​of each field are validated. This allows for a reduction in latency when extracting. Now in this particular library there are parsers for protocols FIX, OUCH, XPRS, AcaDIirect, Native Trading gateway, which are used on various exchanges from NASDAQ to London Stock Exchange.

Consider the work of the parser on the example of the protocol OUCH (NASDAQ). The received message is sent to the parsers, which retrieves the fields and sets the necessary flags. For example, a message type field (“O” or “Enter Order”) and a 14-byte order token are retrieved. The indicator of purchase or sale is “T” (Sell Short), the number of shares is 1002, the exchange ticker of the financial instrument is FFHL. The remaining fields indicate the desired transaction price, as well as information that the order cannot be moved to another market.



Parsing market data and storing price data "on a chip" - financial applications need to know the stock price that is used in orders. To track prices, market data is sent to the card using UDP / IP datagrams. The FPGA then retrieves price updates and stores this data for each share. The prices of all 8,000 stocks traded on US exchanges are placed in the FPGA chip memory.



Conclusion


In an effort to reduce potential delays in trading and processing financial information, brokers, traders, and the exchanges themselves are learning how to work with new technologies that will allow them to build high-performance platforms.
One of these technologies is FPGA, but it is important to remember that this tool is not a silver bullet - in addition to its speed advantages, it also has difficulties in developing and maintaining the system.

Nevertheless, this tool provides good opportunities for increasing the speed of financial applications. And here it is important that the entire infrastructure used by the trader meets the requirements for minimizing delays - for this, for example, ITinvest clients can use direct connection technology and place their equipment in ITinvest racks in the Moscow Exchange colocation zone with a 10 GB / s channel width.

Source: https://habr.com/ru/post/272425/


All Articles