Attached is a slide from Zerodha Varsity.
Here the profit is calculated as (the final contract value) - (the initial contract value).
My doubt is that since I had only invested the margin to get the contract, anyone else who would buy the contract from me would also only pay me the margin, and so, my profit/loss should be (margin received) - (margin given).
Money from your margin and buyers margin transacts on a daily basis. Margin is just the amount that the risk management software thinks that might be the max loss you could make on your trade. Thus the actual loss/profit is deducted/added to your margin on daily basis. It’s just a way to ensure that you don’t default on the contract.
Check out: forward contact and also M2M to get a understanding on how one could default on contract and how M2M would avoid such a situation.
Perhaps you misunderstood my question, my doubt was how are profits calculated, not that how margins function.
I looked it up online for further clarity and the concept is understood now.