calculate gain