# Should one calculate CVA even when exposure is negative?

I have an example, where two companies have the bilateral nature of derivative contract. Companies have exchanged collateral a number of times, so at a certain point in time each sides holds some amount of collateral.

According to the literature, when exposure of company A is negative, it has to calculate DVA instead of CVA (and the opposite for company B).

Does this mean, that CVA = 0 for company A, even though company B holds some of it's collateral? If at that moment B defaults, A may still lose this posted collateral...

Indeed, if the collateral is not segregated, it could be lost if the counterpart defaults. So, the credit exposure should be computed taking into account the collateral balance $$C(t)$$:
$$Exposure(t) = \max \left( MtM(t) - C(t) , 0 \right)$$
This means that, even if $$MtM(t) < 0$$, if $$C(t) < MtM(t) < 0$$, then you will have a strictly positive credit exposure.
Remark: Usually, the exposure is computed assuming that the counterparty default is happening and that it has stopped posting collateral in the past few days (called the margin period of risk or MPOR). So, if you want to keep things simple $$C(t)$$ above is actually the collateral balance as of $$t - MPOR$$.