How does the Initial Margin affect the above profit or loss ?
The initial margin is only a security provided by the client through the clearing member to the exchange. It can be withdrawn in full after the position is closed. Therefore it does not affect the above calculation of profit or loss. However there would may be a funding cost / transaction cost in providing the security. This cost must be added to your total transaction costs to arrive at the true picture. Other items in transaction costs would include brokerage, stamp duty etc.