calculating profit and loss