The formula to calculate option writing margin is a bit too complex I guess. However to simplify things and to get a rough estimate - you can simply add the SPAN margin of futures + Premium. For Example let say you want to write nifty option. The SPAN for nifty futures say is @ 15000 (jus SPAN - not exposure margin). And the option premium say is 50. So the margin requirement will be SPAN+Premium = 15000 + 50*50 = 15000 + 2500 = 17500.

Keep this for ATM option. As you go ITM the premium increases, likewise roughly increase the SPAN too as risk increases (say by 5%). Example - say ITM option is @ 150. Then the margin will be 15750 + 150*50 = 15750+7500 = 23250.

Note - This is jus a rough estimate to calculate at finger tips and it will differ by 1k or 2k.

For accurate calculation you can refer to the margin calculators online : https://zerodha.com/margin-calculator/SPAN/