Well it is only 19k in their situation. 40k 12month hold, 5k less than 12 months, 7k losses, no carried forward losses.
To work it out, you first add all the profits, 40+5 = 45
Minus the losses 45-7-0(no carried forward losses) = 38k
You have max of 20k in discount losses you can apply, but the max you can do is 50% of that 38k figure which means 19k taxable and only 19k of the 20k is applied.
They would of needed to only have 4K or less in losses to get the full 20k discount.
40+5 = 45
45-4 =41
Apply 50% discounts of 20k, leaves them with 21k taxable.