Do you believe in magic? So goes the 1965 Lovin' Spoonful song. The "Magic" I'm referring to is private mortgage insurer MGIC Investment (NYSE:MTG).

MGIC filed its10-K with the Securities and Exchange Commission last week, and it reminded me that in the short term the market is rarely rational. At this time last year, shares traded for around $35 each. The stock recently climbed over $70 before settling back to $63.31 at Friday's close.

How can shares double when a company reports a 21% drop in net income and a doubling of loan-loss reserves to $766 million (or 44% of revenue)? Or maybe a better question is: Why did the shares fall as low as $35 one year ago?

Here's my MGIC story: I believed in MGIC when I first researched it in late 2002. Back then, the company was riding high on the back of moving into subprime mortgage insurance and a booming housing market. It was much the same story for competitors Radian Group (NYSE:RDN), PMI (NYSE:PMI), General Electric (NYSE:GE) subsidiary GE Mortgage Insurance, AIG (NYSE:AIG) subsidiary United Guaranty, and Old Republic International (NYSE:ORI) subsidiary Republic Mortgage Insurance.

The subprime market offers higher premiums to make up for expected higher loan losses. Typically, the defaults on new mortgages do not occur in the first couple of years after origination. In addition, unlike banks, the private mortgage industry does not reserve for loan losses until the client is actually delinquent. So even knowing that loan losses would be higher in the subprime market, no provision was made. The initial effect on MGIC's profit margins and net income was very positive.

Cracks first appeared in the MGIC edifice in 2002 as loan-loss reserves more than doubled from $161 million to $366 million. Market retribution was swift as the shares fell from $74 in July to $34 in November 2002. At that time, my conservative estimates had MGIC undervalued by some 40%. How could the stock price be so low? One answer was that MGIC seriously missed analysts' estimates. But in my opinion, investors' fear of future loan losses was the main culprit.

So, why did shares recently jump from around $55 in December 2003 to over $70 after the announcement of MGIC's worst results in five years? One reason, apparently, is that the 2003 fourth-quarter figures beat analysts' EPS estimates by 11%. And First Call's median analysts' estimates now have MGIC growing earnings at 12.5% over the next five years.

If you believe in the old market adage -- be greedy when others are fearful and fearful when others are greedy -- it might be time to be a little fearful. In my opinion, MGIC faces the same possibility of future loan-loss increases, but with the stock price almost double where it was last year, the margin of safety for investors is no longer there.

Tom Gardner's always digging up small, undervalued companies that offer the potential for future growth in his Motley Fool Hidden Gems newsletter. Check it out free for 30 days.

Fool contributor Philip Durell, otherwise known as admiraltroll on the Fool discussion boards, owns no shares of any companies mentioned in this article.