Computers and clever maths enable traders to buy and sell in the blink of an eye. But does high-frequency trading make matters worse when things go wrong?
A strange thing happened earlier this month. The New York Stock Exchange launched a new electronic trading platform.
A company called Knight Capital had created a new computer program to link up with the new platform in order to trade shares on it. The stock market opened, and Knight Capital prepared to launch its new software.
"There was some problem with the program," says Felix Salmon, finance blogger for Reuters in New York.
"We don't know exactly what. They switched it on and immediately they started losing literally $10 million [£6.4m] a minute. It looks like they were buying high and selling low many, many times per second, and losing 10 or 15 dollars each time. And this went on for 45 minutes. At the end of it all they wound up having lost $440 million [£281m]."
Oops. This was the latest chapter in the story of something called "high frequency trading". Investors have always valued being the first with the news. Nathan Rothschild, it is said, augmented his fortune after a carrier pigeon brought him the news that Napoleon had been defeated at Waterloo.
But high frequency trading is different. Algorithms - step-by-step mathematical procedures - generate automatic trades, conducted by computers, each one racing to be first. And while some computers do receive news about the outside world in electronic format, many high-frequency trading algorithms are simply responding to the hectic world of the electronic trading floor.
Humans still watch the systems, but the computers move far too quickly for us to react to everything they do - and at Knight Capital, the computer glitch meant the company was making trades it didn't intend to make. That's how to lose almost half a billion dollars in a little over half an hour.
To give you a sense of how fast high-frequency trading can be, in the time it takes Usain Bolt to react to the starting pistol, a high-frequency trading platform could complete about 165,000 separate trades.
Now this isn't quite as insane as it sounds. These computers, all competing with each other, are a lot cheaper and more efficient than human traders trying to match bids to buy and offers to sell. So within reason, automated, high-frequency trading is a good thing. But it's possible to have too much of a good thing.
On 6 May 2010, the UK was preoccupied with a General Election. But on the other side of the Atlantic, a very different story was unfolding.
"We were all sitting around in the middle of the afternoon on a relatively slow news day," says Salmon. "Suddenly the Dow Jones was down 600 points in a matter of five minutes. There was this huge crash for no reason. And then 10 minutes after that it went back up again. And no-one knew what had happened."
What may have happened was that somebody rather clumsily tried to make a very large trade on an electronic exchange called Globex. As the price dropped sharply in the process of trying to find willing buyers, the algorithms of the high-frequency traders plugged into Globex behaved unpredictably.
The "flash crash", as it was called, wasn't just what happened when the algorithms were in a frenzy - it was also what happened when humans pulled the plug on all of these individual algorithms.
"A whole bunch of high-frequency traders saw a bunch of weird stuff going on in the market which didn't make any sense," says Salmon.
"And they said 'you know what, we're all just going to hit our off buttons at the same time.'
"And what that did was it meant there was no liquidity in the market. There was no-one buying and selling. You had some crazy trades being done... stocks being sold for literally one penny."
What actually stopped the flash crash was absurdly simple. The exchange itself, Globex, shut down.
Donald Mackenzie, a sociologist at the University of Edinburgh who studies financial markets, says: "Globex has got a program built into it called the 'stop logic functionality.' And in this case it stopped the system trading for just five seconds.
"But that was enough time to halt the downward spiral. It gave human traders the chance to just take a quick glance at the rolling news feeds to discover that nothing catastrophic in the wider world seems to have happened, and to think 'well here, perhaps, is buying opportunity.'"
Mackenzie divides high-frequency trading into five categories.
First, there are algorithms designed not to lose money while executing a trade that's been placed by a human. If you try to buy a large block of shares all at once, for instance, you might find that there aren't enough potential sellers and you'll have to wait for others to show up.
Other computers may see that you've got this large unfilled order and exploit it, perhaps by snapping up shares and selling to you at a profit. To avoid this problem you can ask a computer to slice up your big trade into smaller, more subtle pieces.
Then there are algorithms designed simply to make money by finding buyers and sellers with a little margin between them.
Third, there are algorithms which find statistical relationships between different shares or bonds, and when the statistical relationship fails to hold - even for a moment - they jump in and make a bet that normal service will be resumed. These are called statistical arbitrage algorithms.
So far, so good - it would be hard to find many people in finance who would consider these three types of high-frequency trading to be immoral.
But there are two rather more predatory strategies. One is called algo-sniffing. Here, a super-fast computer tries to find other computers going about their everyday business of buying or selling shares, and figures out what they're going to do and when.
The algo-sniffer can then get ahead of the game and exploit the slower computer. And of course you could have algo-sniffer-sniffers and algo-sniffer-sniffer-sniffers in a high-frequency arms race. No wonder speed can be so important.
And finally, a particular sub-category of the algo-sniffer is the spoofer, which deliberately makes fake offers designed to lure other computers to show their hands, then cancels the offers. Spoofing might be illegal, or at least against the rules of stock exchanges, but it's hard to prove that it's going on.
Andrew Haldane, executive director for financial stability at the Bank of England, is increasingly interested in how high-frequency trading works - and what the future might hold.
"What we have out there now is this complex array of multiple mutating interacting machines, algorithms. It's constantly developing and travelling at ever higher velocities. And it's just difficult to know what will pop out next. And that's not an accident waiting to happen, that's an accident that has been happening with increasing frequency over the last few years.
"We shouldn't wait for the equivalent of the Space Shuttle disaster before remedying the situation. We already have enough light on the dashboard flashing red to want to do something differently."
He says he wants more powerful "circuit breakers" built into the system, designed to pause trading before colliding algorithms send it spinning out of control. He also suggests a sort of "non-transaction" tax to deter traders from clogging the system with trades they then cancel before executing.
But it's not obvious that such measures could successfully be applied to such a rapidly-evolving and global side of the financial system. In the meantime, we will have to wait and see what will "pop out next" - and we have to hope that, whatever it is, the system copes.
Additional reporting by Charlotte McDonald