Margin calculation