The IRS even reduces your taxes if you lose money in the stock market, if your business property depreciates, and so forth. I like to refer to those cases as "the government paying you to be a loser." Just another case where doing better means you do worse.
Let's not even try to pretend this is a fair or well-designed system. Even Warren Buffet, surely one of the greatest beneficiaries of the system, has spoken out against it.