realized gain formula