A wash sale occurs when an investor sells or trades a security at a loss, and then that investor, their spouse, or a company the investor controls purchases an identical or very similar security within 30 days. The IRS’s wash-sale rule prevents a taxpayer from using a wash sale to take a tax deduction. The tax-loss harvesting algorithm applied automatically finds securities that are dissimilar enough from the initial security that they do not violate the wash-sale rule.