How to calculate profit and loss