Active stock traders are well familiar with the wash-sale rule, which simply states that if you sell a security at a loss and buy it back within 30 days, the loss from the initial sale cannot be written off one’s taxes—this is done to avoid people immediately rebuying an asset sold at a loss just to claim the tax writeoff, and it’s a rule that is not really all that controversial. It also has an odd side effect: helping fund managers.

To explain why, we first should dig into the “tax advantaged” genre of funds. These funds focus on tax optimization strategies that, for investors, minimizes their tax exposure and, within the fund, minimizes losses to taxes. This often involves strategically selling assets at a loss to harvest the tax-loss benefits of such a sale, thereby taking advantage of short-term market volatility to create tax offsets to be used when selling assets later in the fund.

To explain how this works, imagine a 50-stock fund that has a primary holding in Apple (AAPL) and Microsoft (MSFT). With a 30% profit in AAPL shares and a 10% loss in MSFT shares for two given lots, the fund will sell some of the MSFT shares at that loss so as to capture the tax writeoff, meanwhile buying a different stock within that 30-day period to stay in the market. After the 30 days are up, the fund might sell those shares (again at a loss or possible marginal gain) and buy into MSFT. The tax write-off gained by these trades will then offset the capital gains when, later in the year, the fund sells some of its AAPL holdings.

There are obvious risks in this kind of maneuvering, with the possibility of the MSFT holding shooting up within that 30-day window and the possibility of the replacement falling significantly both being risks for fund managers to consider. Then there’s the option of selling the MSFT to buy AAPL—and then selling off at the end of the 30-day period to rebalance into MSFT.

Fund managers need to weigh these risks, but there is a way to significantly offset them: instead of selling the MSFT shares and buying another company, sell instead and buy an index fund; in this case, a tech ETF like the Technology Sector SPDR (XLK) might be optimal.

Then there’s an even better way to extend and minimize the risks in this scenario: let’s say the fund sold MSFT at a 5% loss, bought into XLK and, after 30 days, XLK is down another 5%, leading to a near-10% loss in total. The fund can then sell XLK and buy the Vanguard Information Technology ETF (VGT), an almost identical fund, and get another round of tax write-offs, since selling one ETF and buying another similar but not identical one doesn’t go against the wash-sale rule. For an extended bear market, a fund can effectively bank these losses through careful rotations.

Of course, modeling the most tax effective way to do this is complicated, and it requires a deep knowledge of tax law, portfolio theory, and a statistical model of the likelihood of different scenarios. And that is exactly why the inherent complexities that are the byproduct of the wash sale rule turn out to be a rare gift to fund managers. And with taxes an ever-present concern, the market for tax-advantaged funds that do the complicated work of abiding by the wash sale rule and maximizing tax writeoffs is never at risk of disappearing.