CORRECTED 5 p.m.: Spelling of Leslie Rahl.

So where were the quants?

That’s what has been running through my head as I watch some of the oldest and seemingly best-run firms on Wall Street implode because of what turned out to be really bad bets on mortgage securities.

Before I started covering the Internet in 1997, I spent 13 years covering trading and finance. I covered my share of trading disasters from junk bonds, mortgage securities and the financial blank canvas known as derivatives. And I got to know bunch of quantitative analysts (“quants”): mathematicians, computer scientists and economists who were working on Wall Street to develop the art and science of risk management.

They were developing systems that would comb through all of a firm’s positions, analyze everything that might go wrong and estimate how much it might lose on a really bad day.

We’ve had some bad days lately, and it turns out Bear Stearns, Lehman Brothers and maybe some others bet far too much. Their quants didn’t save them.

I called some old timers in the risk-management world to see what went wrong.

I fully expected them to tell me that the problem was that the alarms were blaring and red lights were flashing on the risk machines and greedy Wall Street bosses ignored the warnings to keep the profits flowing.

Ultimately, the people who ran the firms must take responsibility, but it wasn’t quite that simple.

In fact, most Wall Street computer models radically underestimated the risk of the complex mortgage securities, they said. That is partly because the level of financial distress is “the equivalent of the 100-year flood,” in the words of Leslie Rahl, the president of Capital Market Risk Advisors, a consulting firm.

But she and others say there is more to it: The people who ran the financial firms chose to program their risk-management systems with overly optimistic assumptions and to feed them oversimplified data. This kept them from sounding the alarm early enough.

Top bankers couldn’t simply ignore the computer models, because after the last round of big financial losses, regulators now require them to monitor their risk positions. Indeed, if the models say a firm’s risk has increased, the firm must either reduce its bets or set aside more capital as a cushion in case things go wrong.

In other words, the computer is supposed to monitor the temperature of the party and drain the punch bowl as things get hot. And just as drunken revelers may want to put the thermostat in the freezer, Wall Street executives had lots of incentives to make sure their risk systems didn’t see much risk.

“There was a willful designing of the systems to measure the risks in a certain way that would not necessarily pick up all the right risks,” said Gregg Berman, the co-head of the risk-management group at RiskMetrics, a software company spun out of JPMorgan. “They wanted to keep their capital base as stable as possible so that the limits they imposed on their trading desks and portfolio managers would be stable.”

One way they did this, Mr. Berman said, was to make sure the computer models looked at several years of trading history instead of just the last few months. The most important models calculate a measure known as Value at Risk — the amount of money you might lose in the worst plausible situation. They try to figure out what that worst case is by looking at how volatile markets have been in the past.

But since the markets were placid for several years (as mortgage bankers busily lent money to anyone with a pulse), the computers were slow to say that risk had increased as defaults started to rise.

It was like a weather forecaster in Houston last weekend talking about the onset of Hurricane Ike by giving the average wind speed for the previous month.

But many on Wall Street did even worse, as Mr. Berman describes it. They continued to trade very complex securities concocted by their most creative bankers even though their risk management systems weren’t able to understand the details of what they owned.

A lot of deals were nonstandard in many ways, “so you really had to go through the entire prospectus and read every single line to pick up all the nuances,” Mr. Berman said. “And that slows down the process when mortgage yields looked very attractive.”

So some trading desks took the most arcane security, made of slices of mortgages, and entered it into the computer if it were a simple bond with a set interest rate and duration. This seemed only like a tiny bit of corner-cutting because the credit-rating agencies declared that some of these securities were triple-A. (20/20 hindsight: not!) But once the mortgage market started to deteriorate, the computers were not able to identify all the parts of the portfolio that might be hurt.

Lying to your risk-management computer is like lying to your doctor. You just aren’t going to get the help you really need.

All this is not to say that the models would have gotten things right if only they were fed the most accurate information. Ms. Rahl said that it was now clear that the computers needed to assume extra risk in owning a newfangled security that had never been seen before.

“New products, by definition, carry more risk,” she said. The models should penalize investments that are complex, hard to understand and infrequently traded, she said. They didn’t.

“One of the things that has caused great pain is complex products,” Ms. Rahl said.

That made me think back to some of the great trading debacles of the last century, such as the collapse of Askin Capital Management, a hedge fund that fell apart because of complex mortgage security investments gone bad. Wasn’t the moral of those stories that you shouldn’t put your money (or your client’s money) in something you didn’t understand? Furthermore, even if you are convinced you do understand it, you’re not going to be able to sell it when you need the money if no one else does.

“In some ways there is nothing new,” said Ms. Rahl, who helped investigate what went wrong at Askin. “The big deals are front-page news, then they go into the recesses of people’s memories.”

And, ultimately, the most important risk-management systems are the ones that have gray hair. “It’s not just the Ph.D.’s who must run risk management,” Ms. Rahl said. “It is the people who know the markets and have lifelong perspective.” And at too many firms it is those people who failed to make sure the quants really did their jobs.