Design and implement a margin-account simulator that processes a chronological stream of stock trades for a single user and, after each trade, reports whether a margin call has been triggered. You are given an initial cash balance, an initial-margin percentage (the cash the user must put up to open a leveraged position), and a maintenance-margin percentage (the minimum equity percentage that must be kept while positions are open). For every trade you must update the user’s positions (long or short), compute the running market value of the portfolio, track the cash balance, and determine the account’s equity (portfolio value + cash). If, after any trade, the equity percentage (equity ÷ portfolio value) drops below the maintenance-margin requirement, you must emit a margin-call event. Positions may be closed fully, partially, or even reversed (e.g., long → short); you must correctly update quantity and average cost-basis in each case. You should also handle edge cases such as zero-quantity positions and portfolio value rounding to two decimals. The goal is an efficient simulation that can process up to 10⁵ trades and return the sequence of margin-call events in the order they occur.