To prevent taxpayers from selling a security to claim a loss and then immediately repurchasing the same or a “substantially identical” security, the tax code has a “wash sale” rule: the loss is disallowed if the repurchase occurs within 30 days before or after the sale that resulted in the loss.