The tax law doesn’t want you to be able to churn your holdings solely for tax advantage without really changing your economic position. To this end, there is a restriction in the tax law called the wash sale rule. This rule prevents you from recognizing a loss on the sale of a security if you acquire a substantially identical one within 30 days before or after the date of sale. For instance, if you sell 10 shares of Y Corp. at a loss on May 1, and 2 weeks later on May 15 you buy 10 shares of Y Corp., you cannot deduct the loss on the May 1 sale.
The wash sale rule has no applicability to gains. You can sell for profit as often as you want (each gain must be reported). However, the wash sale rule applies to short sales. If you incur a loss when you close a short sale within 30 days before or after another similar short sale, the loss cannot be recognized.
The loss from a wash sale generally is not lost forever; it is preserved in the basis of the newly acquired security. Thus, the fact that you really suffered an economic loss when you made the sale is taken into account. You add the disallowed loss to the basis of the new security, so that when the newly acquired security is sold, the deferred loss will be recognized (or the gain will be minimized to the extent of the deferred loss).
Caution: You can’t avoid the wash sale rule simply by selling in your personal account and then causing your IRA to buy substantially identical securities within the wash sale period. In this case, the wash sale rule applies.