Quantum-Inspired Algorithm has been used to optimize combinatorial problems in place of Universal Quantum Computation. We design and implemented two Quantum-Inspired Trading Strategies for currency arbitrage, Simulated Bifurcation Machine (SBM), and Simulated Quantum Annealing (SQA). Both are implemented with High-Level Synthesis (HLS) and validated on Xilinx Accelerated Algorithmic Trading (AAT) framework. This is a fully-featured open-source reference design for trading applications.
The test toolkit provides SBM/SQA data generation and decoding, which can be used to generate PCAP test files and decode OrderEntry results.
https://github.com/bol-edu/xilinx-acc-2021_submission/tree/main/test_toolkit
Development Environment and Sources:
- Operation System of Ubuntu 20.04.2 LTS
- Xilinx Vitis Software Platform 2021.1
- Xilinx Accelerated Algorithmic Trading (AAT) reference design Q2 (UG1067 v1.1, July 2 2021)
- SBM/SQA design sources in submitted sbm/sqa directory
Build flow of AAT Q2 and SBM/SQA design sources:
Replace the origional AAT Q2 files in /Accelerated_Algorithmic_Trading/hw/pricingEngine
with the files in submitted sbm/sqa directory.
Merge AAT & SBM sources:
$ cd ../Accelerated_Algorithmic_Trading/hw/
$ mv ./pricingEngine ./pricingEngine.bak
$ cp -rf ../xilinx-acc-2021_submission/sbm/src/hw/pricingEngine ./
Merge AAT & SQA sources:
$ cd ../Accelerated_Algorithmic_Trading/hw/
$ mv ./pricingEngine ./pricingEngine.bak
$ cp -rf ../xilinx-acc-2021_submission/sqa/src/hw/pricingEngine ./
Build settings in ~/.bashrc
:
source /opt/Xilinx/Vitis/2021.1/settings64.sh
source /opt/xilinx/xrt/setup.sh
export PLATFORM_REPO_PATHS='/opt/xilinx/platforms'
export LM_LICENSE_FILE="~/Xilinx.lic"
export XILINX_PLATFORM='xilinx_u50_gen3x16_xdma_201920_3'
export DEVICE=${PLATFORM_REPO_PATHS}/${XILINX_PLATFORM}/${XILINX_PLATFORM}.xpfm
export DM_MODE=DMA
Build Hardware & Software:
$ cd ../Accelerated_Algorithmic_Trading/build
$ make clean
$ sh ./buildall.sh
Build Software:
$ cd ../Accelerated_Algorithmic_Trading/sw/applications/aat/aat_shell_exe
$ make all
You also can use prebuild SBM/SQA xclbin files in submitted prebuild_xclbin directory and skip "Build Hardware & Software" step. But you still need to run "Build Software" to generate aat_shell_exe
from source.
Preparation:
- A local host installed with a Xilinx Avelon U50 accelrator.
- A remote host installed with a Broadcom BCM957711A 10Gb x 2 SFP port card and PCAP test files.
- A QSFPx1-to-SFPx4 connection cable.
- An AAT Q2
demo_setup.cfg
and SFP network setting files in submitted configuration directory. - The SBM/SQA test toolkit (
pcap_gen.py
anddecode_order.py
) tested under Python 3.8.5 are submitted in test_tookit directory.- Generate SBM/SQA PCAP test files by
pcap_gen.py
. - Decode OrderEntry results by
decode_order.py
which prints all found currency arbitrage. - The dependencies of
pcap_gen.py
anddecode_order.py
are installed whith commandpip3 install scapy pandas
.
- Generate SBM/SQA PCAP test files by
We refer the network configuration used by the Xilinx verification team.
Interactions between local host and remote host:
The AAT Q2 provides prebuilt xclbin (/sample/aat.u50_xdma.xclbin) and PCAP test sample (/sample/cme_input_arb.pcap) for AAT development environment validation. To test the build of AAT & SBM or AAT & SQA should refer the following supplementary.
Supplementary of test instructions:
- The AAT Q2 used prebuilt xcblin
/Accelerated_Algorithmic_Trading/build/sample/aat.u50_xdma.xclbin
should be replaced to the new built xcblin from AAT & SBM or AAT & SQA mapped to/Accelerated_Algorithmic_Trading/build/aat.xclbin
. - The AAT Q2 default configuration
/Accelerated_Algorithmic_Trading/build/support/demo_setup.cfg
should be replaced with submittedconfiguration/demo_setup.cfg
. - Our own SPF port names are
enp3s0f0
andenp3s0f1
. You should replaceenp3s0f0
andenp3s0f1
with your own SPF port names withinsettingNetwork_sf0.sh
andsettingNetwork_sf1.sh
. - The
> orderentries.bin
(write to./orderentries.bin
) added to Linux Netcat command terminal#1 saves OrderEntry results of SBM/SQA. The./orderentries.bin
is written completely while TCPreplay command finishs to send PCAP test files. The saved./orderentries.bin
is used for decoding OrderEntry results. - The port name
enp3s0f1
used in Linux TCPreplay command terminal#2 should be replaced with your own SPF port name, which is corresponded to the port to send PCAP test files. - The AAT Q2 PCAP test sample
/Accelerated_Algorithmic_Trading/build/sample/cme_input_arb.pcap
used in Linux TCPreplay command terminal#2 should be replaced to SBM/SQA PCAP test files.
Run AAT shell terminal#0 on U50 local host.
$ sudo reboot (if needed to clean U50 setting)
$ cd ../Accelerated_Algorithmic_Trading/build
$ vim support/demo_setup.cfg (if needed to change demo_setup.cfg setting)
./aat_shell_exe
download ./sample/aat.u50_xdma.xclbin
run support/demo_setup.cfg
datamover threadstart
udpip0 getstatus
Run Linux Netcat command terminal#1 on remote host and get OrderEntry results from local host.
$ cd ../network_setting/
$ sudo sh ./settingNetwork_sf0.sh
$ sudo sh ./execFrom_sf0.sh ping -w 5 192.168.20.200 (optional test)
$ sudo sh ./execFrom_sf0.sh nc -n -l 192.168.20.100 12345 -v > orderentries.bin
If Linux Netcat command terminal#1 has not shown connected IP & Port message from local host, run OrderEntry reconnection and get its status on U50 local host terminal#0.
orderentry reconnect
orderentry getstatus
On U50 local host terminal#0, connection established should be shown "true" and connection status should be shown "SUCCESS” from OrderEntry status table.
Run Linux TCPreplay command terminal#2 to send PCAP test files from reomte host.
$ cd ../network_setting/
$ sudo sh ./settingNetwork_sf1.sh
$ sudo sh ./execFrom_sf1.sh ping -w 5 192.168.50.101 (optional test)
$ sudo sh ./execFrom_sf1.sh tcpreplay --intf1=enp3s0f1 --pps=2 --stats=1 ../Accelerated_Algorithmic_Trading/build/sample/cme_input_arb.pcap
Before we can apply SBM/SQA to find optimal arbitrage opportunities, we need to transform the problem into a quadratic unconstrained binary optimization (QUBO) form. The methodology is introduced in
https://github.com/bol-edu/xilinx-acc-2021_submission/tree/main/qubo_formulation
Simulated bifurcation is a Quantum-Inspired heuristic algorithm that approximates the solutions to Ising-model problem formulations. The algorithm can yield high-quality solutions under fewer time steps than the traditional simulated annealing method. Furthermore, the matrix-vector multiplications in the equations can be simplified and parallelized easily, opening the possibility for high frequency trading. In this project, SBM solves a currency arbitrage problem of 5 currencies and 9 exchange pairs in under 7 microseconds, demonstrating its speed and modularity. SBM is integrated into the pricingEngine
of the AAT framework, which processes the market data and decides the orders to place.
https://github.com/bol-edu/xilinx-acc-2021_submission/tree/main/sbm
Simulated Quantum Annealing is a Quantum-Inspired heuristic algorithm that approximates the solutions to Ising-model problem formulations. The algorithm can yield high-quality solutions under fewer time steps than the traditional simulated annealing method. We optimize the algorithm for FPGA implementation, which exploits more parallelism. In this project, SQA solves a currency arbitrage problem of 5 currencies and 9 exchange pairs to demonstrate its speed and modularity. SQA is integrated into the pricingEngine
of the AAT framework, which processes the market data and decides the orders to place.
This work applies some optimization techniques to boost the FPGA performance. For detail, please refer to
https://github.com/bol-edu/xilinx-acc-2021_submission/tree/main/sqa
Quantum-Inspired Trading Strategies:
- Leverage HLS to develop trading strategies with readability and maintainability
- Customizable Quantum-Inspired trading strategies
- Parallel computing on FPGA hardware
- Built on trading industry-standard of CME and FIX
Accelerated Algorithmic Trading (AAT) Framework:
- Full implementation in HLS
- Designed for software engineers
- Source code provided
- Integrated with Vitis™
- Runs out of the box on Xilinx Alveo™
- Supported on Alveo™ U250, U50
- Supports XDMA and host memory bridge-based
Quantum-Inspired trading strategies can be executed on CPUs/GPUs but incur additional latency particularly from the PCIe bus. FPGA based trading strategies can significantly lower latency, but typically need expertised hardware design team and long system integration cycles. Xilinx AAT reference design can provide all the infrastructure required to create a Quantum-Inspired trading application on the FPGA using Xilinx Vitis™ unified platform, and standard Xilinx shells. The design is written in HLS, and all the source code is provided. The design is modular, allowing easily replacing trading strategy IP blocks in the reference design with needed strategy.
AAT Shell Enhancement for Hardware Debugging:
- Status/Debugging registers for SBM/SQA modules
- Add timestamp and time pause functions in both shell mode and run script mode
https://github.com/bol-edu/xilinx-acc-2021_submission/tree/main/aat_shell_enhancement
SBM experimental results:
https://github.com/bol-edu/xilinx-acc-2021_submission/tree/main/sbm#experimental-results
SQA experimental results:
https://github.com/bol-edu/xilinx-acc-2021_submission/tree/main/sqa#experimental-results
Contributors: