When you have capital gains you can offset the taxes from those with the capital losses you incurred.