Programmed to scan the internet for words or phrases that might effect stock markets, the unthinking machines had immediately seized upon the tweet, noted the proximity of the words “Obama”, “explosions” and “White House” and unleashed a torrent of trades. Within seconds, the Dow Jones had plunged 140 points and more than $200 billion of capital had been wiped out.

A few minutes later the report was exposed as a hoax and the markets quickly returned to their pre-tweet levels. But, to many, the idea that one fake tweet could have such an enormous impact on the financial markets was incredible. Who was running Wall Street? Humans or machines?

If you thought “humans”, you were woefully out of date. Over the past decade or so there has been a technological coup d’etat on the trading floor. The old “Masters of the Universe” – the Gordon Gekko types with their slicked-back hair and $5,000 suits – have been superseded by unbelievably powerful computers capable of analysing vast amounts of data and buying or selling shares in the blink of an eye. Today, if you visit a trading floor, instead of pumped-up men in loose ties screaming down the phone, you are more likely to see rows of studious-looking people (most of them still men) sitting in front of computer screens, quietly monitoring trades being carried out on their behalf by machines.

Around 70 per cent of the orders to buy or sell on Wall Street are now placed by software programs, and the studious-looking people, mathematical geniuses who are responsible for writing these programs, are the new “smartest guys in the room”. It is the age of the algorithm.

Mathematicians made their first forays into the financial world in the late Sixties. Edward Thorp, a professor of mathematics at the University of California, published a book in 1967 called Beat the Market in which he laid out what he claimed was a foolproof way of making money on the stock market, all based on a system he had previously devised to beat casinos at blackjack. The blackjack system had been so successful it had forced casinos to change their rules and Beat the Market – which had to do with selling stocks and bonds at one price and buying them back at a lower price – proved to be even more groundbreaking. In 1974, Thorp founded a hedge fund called Princeton/Newport Partners and proceeded to make a killing on the markets.

At the same time, the job prospects for scientists had nosedived. Since the 1969 moon landing, the American government had cut funding for science programmes and diverted it to the war in Vietnam.

“A generation of physicists who had gone to graduate school left with their PhDs and entered a severely depressed job market,” explains James Owen Weatherall, author of The Physics of Finance. They had to earn a living somehow, and, seeing how much money that there was to be made on Wall Street, many decided to move into finance.

In Britain, the fall of the Soviet Union led to an influx of Warsaw Pact scientists. In both cases, these scientists brought with them a new methodology based on analysing data and also a faith that, using sufficient computing firepower, it was possible to predict the market. It was the start of a new discipline, quantitative analysis, and the most famous “quant” of all was a shambling donnish maths genius with a scraggly beard and aversion to socks called Jim Simons.

For those who know their physics, Simons is a living legend. A piece of mathematics he co-created, the Chern-Simons 3-form, is one of the most important elements of string theory, the so-called “theory of everything”. Highly academic, Simons never seemed the sort of person who would gravitate to the earthy environs of Wall Street. But in 1982, he founded an extraordinarily successful hedge fund management company, Renaissance Technologies, whose signature fund, Medallion, went on to earn an incredible 2,478.6 per cent return in its first 10 years, way above every other hedge fund on the planet, including George Soros’s Quantum Fund.

Physicist-turned-hedge fund mogul Jim Simons (AP)

Its success, based on a highly complex and secretive algorithm, continued in the Noughties and over the lifetime of the fund, Medallion’s returns have averaged 40 per cent a year, making Simons one of the richest men in the world with a net worth in excess of $10billion.

Of his 200 employees, ensconced in a fortress-like building in unfashionable Long Island, New York, a third have PhDs, not in finance, but in fields like physics, mathematics and statistics. Renaissance has been called “the best physics and mathematics department in the world” and, according to Weatherall, “avoids hiring anyone with even the slightest whiff of Wall Street bona fides. PhDs in finance need not apply; nor should traders who got their start at traditional investment banks or even other hedge funds. The secret to Simons’s success has been steering clear of the financial experts.”

Not surprisingly, old-style traders hate the quants. Not only have they pushed them off the top of the trading tree, there is also a basic clash of cultures. They are not flash and, invariably, rather awkward socially. As one anonymous software salesman who deals with hedge funds relates on a blog: “They don’t do small talk. When one of them picks me up from reception and we ride the elevator, I have learnt not to start chatting away about, say, the weather. They simply don’t seem to understand. They think you’re attempting to communicate something apparently important about meteorological conditions. Same thing with innocent jokes… blank stares.”

So what exactly do quantitative analysts do?

Patrick Boyle and Jesse McDougall run a hedge fund which they operate out of an Islington town house. Their offices are next to the sort of ethical café whose owners would probably be horrified at the rampant capitalism on display next door. When I meet them they are seated in a small room dominated by three computer screens. They start work at seven in the morning and end around 11 at night. “We have computer screens in our kitchen and living room,” says Boyle, 37. “So we can monitor the markets while having dinner and we can log in remotely if we are out in the evening.” He shows me a chart tracking his fund’s performance. The line doesn’t dip when the rest of the market dips and rises faster than the FTSE.

How do they do it?

“We do it with maths,” he says. “We buy stock market data and we analyse it. It’s like weather forecasting – we can say that there is a 65 per cent probability that the market will be up between open and close, so we are able to have better than 50 per cent odds on short-term movements and over time if you call short term well, you can make money.”

Who wrote the computer program they use? “I did,” says Boyle. How do you write something like that? “Slowly.”

The writing of the program may be slow but the speed of transactions is super fast. Some quants specialise in what is called High Frequency Trading (HFT), which involves large numbers of trades over very short periods of time. “In one millisecond the price could go up by one penny,” says McDougall. “You do it thousands of times on hundreds of shares and you make money.”

Boyle and McDougall’s hedge fund doesn’t do high frequency trades, so to find out more I meet Simon Jones, who was running the quants desk at a major bank up until a few months ago. He is 36 years old.

“The guys and women who worked with me were the best of the best. They came from all over the world: from India, Russia and China.” The job was intense and highly competitive. “Let’s say I have noticed that the moment the Dow goes up the FTSE goes up,” says Jones. “The first person to notice that and make a trade can make money but to do that means getting the data from New York to London and then getting my trading decision across the Atlantic and me buying my FTSE before anyone else does.”

In this game speed is critical and that has led to what has been dubbed an arms race between firms. It has got to a point where firms have actually started moving their servers nearer to an exchange to speed up connection times.

In 2010, a company called Spread Networks laid a new direct cable between New York and Chicago, going straight through the Allegheny mountains, which shaved a little bit more than 1,000th of a second off the transmission time between stock exchanges.

For the opportunity to use a similarly fast tube between New York and London, Jones’s old bank was asked to pay $50 million. “It would have given us an advantage over others of about a six thousandths of one second,” says Jones.

This focus on the shortest of short-term gains has vastly increased volatility. “Warren Buffett owns shares in Coca-Cola and when they go down he says 'I’m holding on to them because I think they will go back up’,” says Jones. “But the HFT guy, all he cares about is the next millisecond. And when too many people start panicking about the next millisecond that’s when you have a crash.”

“None of us knew what to do or what would happen next,” says Dave Lauer, a quant who was working on a HFT desk that day. “It was terrifying.”

For Lauer, the Flash Crash was a wake-up call. “I started to see how the race to be fastest had left things in a very fragile state,” he tells me. The following year his wife revealed she was pregnant which prompted him to make a big decision. “I remember thinking, 'How will I explain to my future child what I do for a living?’” Lauer quit his job and last year told the Senate Banking committee that High Frequency Trading had brought the market to crisis point.

The Flash Crash was partly caused by the HFT strategy of “spoofing”; making bogus offers to buy or sell shares to flush out the intentions of rivals. On the day, an astonishing 19.4 billion shares were traded, more than were traded in the entirety of the Sixties, but hundreds of millions of them were never actually sold; they were merely held for a few thousandths of a second as traders tested the waters.

Isn’t there something wrong with a system that promotes so much volatility to the benefit of no one except a handful of hedge funds? Can it be a meaningful investment of time and technology? Warren Buffett’s business partner, Charlie Munger, has described High Frequency Trading as “basically evil”. “I think it is very stupid to allow a system to evolve where half of the trading is a bunch of short-term people trying to get information one millionth of a nanosecond ahead of somebody else,” he said earlier this year. “It’s legalised front-running.” HFT is certainly of no clear benefit to everyday investors - savers in pension funds and life policies.

The quants I meet don’t believe what they do is necessarily dangerous but they do voice some doubts.

“Some of the guys who come from pure science and maths backgrounds are used to solving a problem and it works,” Patrick Boyle says. “They think they can find a formula that will perfectly describe how the market moves. That is the philosopher’s stone – it is utterly impossible.” The danger is that in only seeing numbers and patterns the human dimension is forgotten.

After 16 years in the City, Simon Jones is now planning to go travelling. “A quant can earn up to seven figures,” he tells me, “but sometimes I do wonder whether I contributed positively to society.”

And what does he conclude? He pauses. “I was working with the best of the best,” he says. “My bank employed the brightest engineers, chemists and scientists – and we were all working together to get richer. The chemical and physics and health industries are worse off because of what we do because I tell you this: if there was a pay bonus structure similar to what we had in the City for curing cancer, we’d have found a cure for cancer.”

I find that sad and a little bit frightening. So, I ask, quants: good or bad? Jones looks at me and says, “Humans just found a new way of being greedy.”