C++ for financial trading systems committee seeks technical input
BEVERLY HILLS, CA (GoshRobin) 2023/12/22 – On Wednesday, December 13th, we held our first meeting of the ISO C++ SG14 Low Latency Financial Trading Systems subcommittee since I was voted chairman on September 13th, 2023. SG14 has three subcommittees, with Embedded Systems, Game Programming and Financial Trading Systems. SG14 holds Zoom meetings the 2nd Wednesday of each month, alternating between subcommittees. Next meeting of C++ Financial Trading Systems is March 13th, 2024.
As subcommittee chairman, my role is to suggest what things could be added to the C++ standard to better support low latency financial systems. As a subcommittee, we’re starting from scratch, with no proposal on the table. Ideas?
Low Latency STL
I reached out to Bjarne Stroustrup for suggestions. Asked what we should do about containers, as the STL isn’t suitable for low latency systems. Ideas that were discussed during the subcommittee meeting were EASTL and ETL. Bjarne suggested creating an STL that uses allocation from a pool.
class Stopwatch
A Money class and a Stopwatch class are ideas I suggested. Regarding a Stopwatch class, I reached out to Howard Hinnant who developed chrono_io. Howard said he’s unsure it is worthy of standardization, because it is so easy for the programmer to do himself, and because there are probably a few different good ways to do it. On the other hand…
#include <thread> #include <chrono> #include <iostream> using namespace std;using namespace chrono_literals; void Foo() { const auto start = chrono::high_resolution_clock::now(); std::this_thread::sleep_for(2000ms); const auto end = chrono::high_resolution_clock::now(); const chrono::duration<double, std::milli> elapsed = end - start; cout << "Duration = " << elapsed << endl; } void Bar() { Stopwatch stopwatch; this_thread::sleep_for(2000ms); cout << "Duration = " << stopwatch << endl; }
I’m thinking that Bar() is nicer than Foo() that does the same thing, that it may make sense to have a standard Stopwatch class despite it being a small thing. What do you think?
class Money
Regarding a Money class, I suggested we create a standard money (fixed decimal) type, that float (IEEE 754 being an approximation) and integer (measuring in pennies) types are not great for banking.
A Money class would be a fixed point big decimal implementation:
int main() { Money<4> money(1000);// 1000.0000 cout << "money 1000 as " << money.GetAmount() << endl; money.AddFractionalPart(9999); // 1000.9999 cout << "money 1000.9999 as " << money.GetAmount() << endl; string s = money.to_string(); cout << "money as " << money.GetAmount() << " or " << s << endl; cout << "money status is" << money.error() << endl; return 0; } /* money 1000 as 10000000 money 1000.9999 as 10009999 money as 10009999 or $1,000.9999 money status is no error */
Unlike floating point double type, Money has no rounding error, is precise like an integer, but with a fixed point decimal place.
class spsc_queue
Another idea for trading systems, a low latency lock-free ring buffer for fast packet io like boost::lockfree::spsc_queue.
class Substring
The std::string class can allocate memory from the heap, making it unsuitable for low latency systems. A solution may be a fixed-length substring:
template <unsigned size> class Substring { char text[size]; unsigned length; public: Substring() : length(0) { text[0] = 0; } ... }; Substring<80> substring("Hello World");
This creates an 80-character array that behaves like std::string, but that will not call the heap or throw an exception.
Meeting Notes
These links were shared and discussed:
- Graphs https://lists.isocpp.org/sg19/att-0312/D1709R4.pdf
- Network Interface https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2762r2.pdf
- Tokyo C++ Meeting https://isocpp.org/files/papers/N4961.pdf
Git Repo
I’ve begun experimenting with implementations at https://gitlab.com/robinrowe/cpp-financial-systems. Check it out…
Future SG14 C++ Low Latency Meetings
- Jan 10, 2024 02:00 PM ET: Games
- Feb 14, 2024 02:00 PM ET: Embedded
- Mar 13, 2024 02:00 PM ET: Cancelled due to Tokyo 3-18-23
- Apr 10, 2024 02:00 PM ET: Finance
- May 8, 2024 02:00 PM ET: Games
- June 12, 2024 02:00 PM ET: Embedded; St.louis 6-24-29
- July 10, 2024 02:00 PM ET: Finance
- Aug 14, 2024 02:00 PM ET: Games
- Sep 11, 2024 02:00 PM ET: CPPCON Sept 15-20 so cancelled
- Oct 9, 2024 02:00 PM ET: Embedded
- Nov 13, 2024 02:00 PM ET: Cancelled Wroclaw F2F
- Dec 10, 2024 02:00 PM ET: Finance
About Robin Rowe
Robin Rowe is the chairman of the ISO SG14 C++ Low Latency Financial Trading Systems subcommittee. Product designer to Lenovo, AT&T DIRECTV, GoPro. Founding director of the AI research lab at the multi-billion dollar engineering firm SAIC. Visual effects and animation software designer for Disney Marvel Spider-Man and Mattel Barbie. DARPA and navy research scientist. Taught C++ software design at the Naval Postgraduate School and the University of Washington.