This is determined by the exchanges. They use the SPAN (Standard portfolio analysis of risk) system which is built by Chicago Mercantile exchange to determine the margins.

Check this on CME, which has details on how SPAN margins are arrived at.

Standardized Portfolio Analysis of Risk or SPAN is a popular margin system accepted by several exchanges hosting Futures and Options trading.

SPAN margin calculation is based on an advanced series of algorithms. These algorithms determine the SPAN margin in accordance with the global assessment of the complete portfolio based on the risk faced by the trade in a single day.

Options and futures writers should have a sufficient amount of margin in their accounts to cover foreseeable losses.

The SPAN system, through its algorithms, places the boundary of each location to its calculated nastiest possible one-day move. The structure, after calculating the edge of each position, can change any surplus margin on existing positions to novel positions or existing positions that are short of margin.

SPAN margin requirements are determined by a calculation of probable losses. The SPAN margin is unique in that when setting up margin needs, it takes into consideration the complete portfolio, not just the previous trade.

SPAN itself presents one key benefit for options traders who unite calls and puts in writing schemes. Net option sellers can frequently receive constructive management.

Since SPAN rationally appears at the next day's worst-case directional progress, one side's losses are mainly compensated by other side's gain.