Live data from Hacker News

C++ patterns for low-latency applications including high-frequency trading

arxiv.org

91–100 of 240 posts

Re: C++ patterns for low-latency applications including high-frequency trading

#91
post #39

Earlier quoted context omitted.

Not if we disallow it. We have laws in place to try and prevent a lot of natural actions of markets.

Instant biggest black market of all time, corruption skyrockets, only the richest people get fair deals on investments.

They'll get better than fair deals. They will almost exclusively own all the available pricing information.

Re: C++ patterns for low-latency applications including high-frequency trading

#92
post #17
post #7

Earlier quoted context omitted.

Non-bitcoin transactions are just a couple of entries in various databases. Mining bitcoin is intense number crunching. HFT makes the financial markets a tiny bit more accurate by resolving inconsistencies (for example three pairs of currencies can get out of whack with one another) and obvious mispricings (for various definitions of "obvious")

That's a nice fairy tale that they probably tell their kids when asked, but what the profitable firms are doing at the cutting edge is inducing responses in the other guys' robots, in a phase that the antagonist controls, then trading against what they know is about to happen. It is literally market manipulation. A way to kill off this entire field of endeavor is to charge a tax on cancelled orders.

Exchanges put limits on cancellation rates as measured by a multiple of filled orders.

You have to allow strategies that can induce other strategies as by definition those also increase liquidity. It’s a difficult problem to explain to anyone except the very few people who can understand the extremely complicated feedback loops that result from bots fighting bots, however the regulators actually have access to counterparty tagged exchange event data and what is found when this is analyzed is that the net cost for liquidity that is extracted by market makers and short term traders from longer term participants is continuously decreasing not increasing. The system is becoming more and more efficient and not less. This is good for markets and the economy. There are also less people working in financial markets per capita than ever before, granted those who are might include a higher percentage of highly skilled and specialized and educated individuals than previously, which some might argue might be better used in some other industry, but that is rightfully not what the market wants.

There is absolutely no logical reason to “kill off this entire field” those sentiments are purely envy based reactions from those who don’t understand what is happening.

Re: C++ patterns for low-latency applications including high-frequency trading

#93
post #17

Earlier quoted context omitted.

That's a nice fairy tale that they probably tell their kids when asked, but what the profitable firms are doing at the cutting edge is inducing responses in the other guys' robots, in a phase that the antagonist controls, then trading against what they know is about to happen. It is literally market manipulation. A way to kill off this entire field of endeavor is to charge a tax on cancelled orders.

Yep and what's worse is many hft firms aren't in the market-making business at all but actually REMOVE liquidity.

This comment is how to tell me you completely misunderstood CLOB market structure without telling me.

Re: C++ patterns for low-latency applications including high-frequency trading

#94

> The noted efficiency in compile-time dispatch is due to decisions about function calls being made during the compilation phase. By bypassing the decision-making overhead present in runtime dispatch, programs can execute more swiftly, thus boosting performance. The other benefit with compile-time dispatch is that when the compiler can statically determine which function is being called, it may be able to inline the…

> That eliminates all of the function call overhead and may also enable further optimizations (dead code elimination, constant propagation, etc.).

AFAIK, the speedup is almost never function call overhead. As you mention at the tail end, it's all about the compiler optimizations being able to see past the dynamic branch. Good JITs support polymorphic inlining. My (somewhat dated) experience for C++ is that PGO is the solve for this, but it's not widely used. Instead people tend to avoid dynamic dispatch altogether in performance sensitive code.

I think the more general moral of the story is to avoid all kinds of unnecessary dynamic branching in hot sections of code in any language unless you have strong/confidence your compiler/JIT is seeing through it.

Re: C++ patterns for low-latency applications including high-frequency trading

#95
post #17

Earlier quoted context omitted.

That's a nice fairy tale that they probably tell their kids when asked, but what the profitable firms are doing at the cutting edge is inducing responses in the other guys' robots, in a phase that the antagonist controls, then trading against what they know is about to happen. It is literally market manipulation. A way to kill off this entire field of endeavor is to charge a tax on cancelled orders.

If one outlawed / disincentivized hostile the bot behavior you described, there would still be the opportunity to do the good and profitable things I described.

These commenters have no clue what they are talking about. You don’t need to worry about hostile behaviors in the way they claim. These HN individuals are not domain educated and are spouting highly uninformed nonsense. Silly ideas like market orders take liquidity and limit orders provide it show an extremely rudimentary familiarity with only basic terminology of the field and with no understanding of the extremely dynamic and complex nature of modern capital markets. For instance they don’t realize that most longer term managers execute as much as 80% of their orders as passive limit orders, yet they are the ones that are actually liquidity demanders not suppliers.

Re: C++ patterns for low-latency applications including high-frequency trading

#96

Earlier quoted context omitted.

foo(const bar&) is ideal if you precisely wish to bar ownership. If (and in many kinds of projects, invariably it's more like when) you later decide to share ownership, or if nullptr is an option, then it's no good. foo(std::shared_ptr ) is copy-constructed as part of your function call (bumping the refcount) unless copy elision is both available and allowed. It's only ideal if you almost always pass newly instantiat…

foo(const bar&) is ideal if you precisely wish to bar ownership. What? invariably it's more like when) you later decide to share ownership, shared_ptr shouldn't even be necessary for keeping track of single threaded scope based ownership. As for shared_ptrs being very rare, uh, no. We use them by the truckload. To each their own! You might want to look into that, you shouldn't need to count references in single threa…

> What?

The context you're missing is in your post's GP. That poster holds a std::shared_ptr (for whatever perfectly valid reason) and wishes to pass it to foo(). However, he declares it as foo(const bar &) because the callee does not need to share in the ownership of the shared_ptr. That means it gets called as foo(*p.get()).

> scope based ownership

That's the incorrect assumption that you came to. Obviously if bar is only used for stack-based scope variables, no shared_ptr is needed.

Re: C++ patterns for low-latency applications including high-frequency trading

#97
post #74

Earlier quoted context omitted.

All the java libs that you use can never do an allocation -- ever!. So you don't really get that much benefit to the java ecosystem (other than IDE's). You have to audit the code you use to make sure allocations never happen during the critical path. Fifteen years ago, the USN's DDX software program learned this the hard way when they needed a hard real time requirement in the milliseconds.

In my experience: Allocation is OK, but garbage collection is bad.

I think back then GC defaulted running potentially at allocation.

shared_ptr is a much better solution for garbage collection. One I wish that java had implemented.

Re: C++ patterns for low-latency applications including high-frequency trading

#98
post #12

Earlier quoted context omitted.

OTOH, it might be a net negative in latency if you're icache limited. Depends on the access pattern among other things, of course.

Yup, you always have to measure. Though my impression is that compilers tend to be fairly conservative about inlining so that don't risk the inlining being a pessimization.

My experience has been that it's rather heuristic based. It's a clear win when you can immediately see far enough in advance to know that it'll also decrease the amount of generated code. You can spot trivial cases where this is true at the point of inlining. However, if you stopped there, you'd leave a ton of optimizations on the table. Further optimization (e.g. DCE) will often drastically reduce code size from the inlining, but it's hard to predict in relationship to a specific inlining decision.

So, statistics and heuristics.

Re: C++ patterns for low-latency applications including high-frequency trading

#99
post #54

Is there any good reason for high-frequency trading to exist? People often complain about bitcoin wasting energy, but oddly this gets a free pass despite this being a definite net negative to society as far as I can tell.

A net negative to society, but a positive for the wealthiest.

> A net negative to society, but a positive for the wealthiest.

No.

When your passive index fund manager rebalances every month because “NVDA is now overweighted in VTI, QQQ” the manager does not care about the bid/ask spread.

When VTI is $1.6 trillion, even a $0.01 difference in price translates to a loss $60 million for the passive 401k, IRA, investors.

HFT reduces the bid/ask spread, and “gives this $60 million back” to the passive investors for every $0.01 price difference, every month. Note that VTI mid price at time of writing is $272.49.

Post reply on HN