THE American housing market has deteriorated so sharply in the past two years that it is easy to fall prey to profound pessimism. Recent weeks have brought yet more bad news. To protect their thin capital, Fannie Mae and Freddie Mac, the big mortgage agencies, said they would limit the volume of new mortgages that they buy. JPMorgan Chase announced $1.5 billion in mortgage-related write-downs and gave warning of worsening housing conditions. Meanwhile, the Federal Reserve found that mortgage-underwriting terms were tightening by the greatest extent since the early 1990s.

Amid the despondency, however, supply and demand are moving towards balance. Sales of new homes, which had plunged nearly 60% from their average level of 2005, have been stable since March. Sales of existing homes stopped falling last autumn. Julia Coronado of Barclays Capital says that construction of homes built for sale, not counting units that already have a buyer, had dropped to 13% below the level of new-home sales in the first quarter (see chart 1). She thinks second-quarter data, due out on August 19th, will show the gap growing to 18%. That is why the inventory of unsold homes, though still near recent highs relative to monthly sales, has fallen sharply in absolute terms.

By the standards of previous cycles, residential construction should be nearing the bottom. Karl Case, a housing expert at Wellesley College and one of the creators of the S&P/Case-Shiller home-price indices, notes that in three previous housing cycles, residential investment peaked at about 5.5% of GDP and hit bottom at around 3.5%. In the latest cycle it peaked at 5.5% in 2006 and by the second quarter had fallen to 3.1% of GDP, below the troughs of 1975, 1982 and 1991. He does not expect much rebound. But like hitting yourself with a hammer, house building need only stop falling for the economy to feel better. Most forecasters expect construction to fall further in coming quarters but since that will be from a shrinking base, the impact on overall economic growth will diminish.

Finally, since home prices have dropped about 18% from their mid-2006 peak (based on the S&P/Case-Shiller composite of 20 cities) and incomes have steadily grown, homes are returning to more typical levels of affordability in some regions. Mr Case estimates that in Los Angeles, the ratio of home prices to annual income per person doubled from 2001-06 to 16, and has since fallen to 11. In Boston, it rose from nine to 12, and has since fallen back to nine.

There are numerous caveats, however. First, the scale of the housing boom means history is a flawed guide to how big a retrenchment is in store. As Mr Case succinctly puts it, “We really overdid it.” David Seiders, chief economist at the National Association of Home Builders (NAHB) in Washington, DC, thinks that in normal times, 3.6% of America's housing stock—including owner-occupied homes, rental units and builders' inventory—should be vacant. The figure is now 4.8%. That translates into 1.5m “excess” vacant units, one reason Mr Seiders thinks construction is going to keep falling until the second quarter of next year.

Some believe that with banks and other lenders dumping huge numbers of foreclosed homes, prices could fall well below equilibrium. That is debatable. A recent paper by Charles Calomiris of Columbia University and Stanley Longhofer and William Miles, both of Wichita State University, argues that foreclosure sales will impact prices less than commonly thought. They examined state-level data from 1981 to 2007 and found that even large increases in foreclosures have only a small marginal impact on prices, perhaps because they occur late in the cycle when the supply of newly built homes is shrinking.

Most serious is the prospect of a further squeeze on credit. The fate of the mortgage market has increasingly rested on the shoulders of Fannie Mae and Freddie Mac, as well as Ginnie Mae, their wholly government-owned counterpart. But they may not have much more staying power; last month, their issuance of mortgage-backed securities plunged by 41% from June, according to Inside Mortgage Finance, a newsletter (see chart 2). Even if Fannie and Freddie's capital constraints do not stop them guaranteeing mortgages, they have tightened their underwriting terms. Banks, which lack capital themselves, are passing these tighter terms on to customers. Mortgage rates have risen by half a percentage point since early June.

This has left both optimists and pessimists pinning hopes for a rebound on the federal government. Last month's housing-rescue law offers up to $7,500 to first-time homebuyers, a feature that the NAHB has been heavily promoting. The law also made the government's implicit backing of Fannie and Freddie explicit, if necessary by injecting capital into them. Ms Coronado admits her optimistic case goes out of the window if the two firms can no longer do their job. Which is why, she says, the government will ensure that they can.