Many companies featured on Money advertise with us. Opinions are our own, but compensation and
in-depth research may determine where and how companies appear. Learn more about how we make money.

Money is not a client of any investment adviser featured on this page. The information provided on this page is for educational purposes only and is not intended as investment advice. Money does not offer advisory services.

immunization shot with dollar sign bubble in liquid
Boost your immunity to taxes.

This is the third installment in Money's Midyear Financial Checkup. You can read our first installment, on how to recalibrate your investments, here, and our second, on how to negotiate a raise this summer, here.

Rebalancing your portfolio by selling stocks makes a lot of sense after the fourth longest bull market in history. But it's not so simple. You know that selling long-term holdings at a profit has a bad side effect: capital gains taxes.

Use losses to offset gains. When you sell a long-term holding that's down, Uncle Sam compensates you for part of that loss. How? By letting you use those capital losses to reduce, dollar for dollar, any capital gains you have elsewhere in your portfolio. The good news: If you wind up with more losses than gains, you can use them to lower your taxable ordinary income up to $3,000 a year. Even better, you can carry forward leftover losses indefinitely, which means you can lower your tax bill for future years when you rebalance.

Sell before you lose the chance. Even though the market is modestly up this year, losses can be found in a number of areas, including European equities, emerging-market stocks, commodities, natural resource funds, and the energy sector (see chart). Investors often wait until the end of the year to harvest losers. But "if you wait until then, you might have fewer opportunities," says Los Angeles financial adviser Ara Oghoorian. He adds: "You don't know where the market will be in December."

Maintain your strategy. While rebalancing reduces risk, you don't want to change the makeup of your portfolio. So when you sell, immediately replace your losers with the same type of—but not identical—investments. The IRS's "wash sale" rule restricts you from buying back the same security you just sold for 30 days if you want to keep the tax break. However, this still leaves you plenty of room to maneuver, says tax expert Robert Willens.

For instance, if you sell Exxon Mobil , whose shares have sunk 14% in the past year because of weak oil prices, there's nothing stopping you from swapping it for a peer like Chevron , which generates a greater percentage of its energy production from oil and is therefore more likely to bounce back as crude prices recover. Or you can buy a broad-based energy fund like Vanguard Energy ETF , which charges just 0.12% in annual fees.