Maybe it's time to give your portfolio a dose of pharmaceutical stocks.

The sector has taken a beating lately with the NYSE Arca Pharmaceutical Index down around 10% in the three months through Friday, while the  Market Vectors Pharmaceutical exchange-traded fund  (PPH) - Get Report , which tracks the sector, was off 13% in the same period. The S&P 500 Index was down 1% over that time span.

At least part of the selloff was a media circus that erupted when one company raised the price of an HIV drug by 5,000% and Democratic presidential candidate Hillary Clinton weighed in on the topic. What it means is that the sector is getting a lot of unwanted (and perhaps in some cases, unwarranted) attention, which adds to concerns about government interference in the industry. That, in turn, is making the stockholders nervous.

"Investors have become more cautious" on the sector, according to a recent report from Goldman Sachs. Major issues include what freedom the companies will have to price their medicines and whether the mergers and acquisitions in the sector can continue to add value, the report adds.

Still, as with all things on Wall Street, if something is worth doing, it's worth overdoing. That seems to be the case with this selloff. At least some of the stocks in the sector are now looking really cheap.

Take for instance,  Valeant Pharmaceuticals International (VRX) , down more than 60% in the three months through Friday amid questions about the company's accounting practices and business relationships.

"In our view, VRX is clearly not trading on fundamentals," wrote Shibani Malhotra, New York-based specialty pharmaceuticals analyst at Nomura, in an Oct. 26 report. That was quickly followed by a meeting with the CEO and another note the next day, which stated: "Our meeting left us confident that the recent bear reports accusing the company of fraud are unfounded."

In addition to seeing the shares as undervalued, the report notes that Valeant's priority is buying back its own debt on the open market. That debt is trading at less than face value, so retiring it would not only be a bargain but also reduce interest expense.

Nomura, which rates the stock a buy, sees substantial upside for Valeant shares with a target price of $220, which compares with a closing price of $94 on Friday.  Or put another way, it's trading at less than half of what Nomura calls its "intrinsic value."

Likewise, Nomura sees Endo International (ENDP) - Get Report , which mainly specializes in pain and urology medicines, as a victim of an excessive selloff.

"We believe recent noise that has affected sector valuation has left Endo's underlying organic growth potential overlooked," Malhotra said in a recent report. She rates it a buy, with a target price of  $100 a share, compared with Friday's close of $60.

How quickly those two stocks bounce back remains to be seen. But it's clear that with an aging population, pharmaceuticals should do well as a sector over the next few decades.

"We believe growth in health care products will stay strong owing to an aging population and increasing efforts to treat conditions with drugs and maximize the productivity of scarce health care labor," states a recent report from Deutsche Bank.

In fact that's why Deutsche Bank says that pharma is in the "sweet spot" of the trend.

This article is commentary by an independent contributor. At the time of publication, the author held no positions in the stocks mentioned.