Margin
On pt-v22 an account that holds futures or options has to keep enough equity behind them. Equity is the account's net worth: cash, the stocks at their prices, each future's value over its settlement mark, and each option at its dealer's mid.
Initial and maintenance margin
A future's initial margin is set per contract at each close, by a scan of how far the contract can move in one session. The scan is sized to cover 99% of one-session moves, the confidence level a clearing house must meet under the CFTC's rule 17 CFR 39.13, with an allowance for the fat tails of daily moves. The maintenance margin is the initial margin over 1.1. On the first day of a run the index future asks about 4,400 dollars a contract at the median, on an index near 1,000: about 1.7% of its notional of 250,000 dollars. The scan follows the day's volatility, so half of runs ask between about 3,100 and 6,700 dollars.
Options are margined as a broker's portfolio-margin account is, under FINRA Rule 4210(g). Each name's options and its stock form one portfolio. The portfolio is valued at ten equally spaced moves of the stock, from 15% down to 15% up, and its margin is the largest loss among them. Gains and losses net within the name, so a covered call or a protective put asks less than its parts, and nothing nets across names. Each portfolio asks at least 0.375 dollars a share for every option held, 37.50 dollars a contract, the minimum the rule sets; for a long option, no more than it is worth. The maintenance margin is again the margin over 1.1.
Shares that an exercise or an assignment hands the account are margined too. While the account holds options in that name, the option scan covers them. Once it holds none, the shares ask 15% of their value, the loss at the end of the same range. That margin counts from the close the shares arrive, so an assignment at expiry that leaves the account holding a large stock position can make a margin call that same close.
quote(symbol) gives a contract's initial_margin and maintenance_margin, and an option's quote gives what one short contract asks. engine.option_margin(positions) runs the scan on any list of (symbol, contracts) and (ticker, shares) pairs, and engine.stock_margin(positions) the margin on stock held alone, as (ticker, shares).
The order check
An order is checked before it goes. If the account's equity after it would be under the initial margin the account would then owe, the order is refused with MarginError, a kind of OrderError. An order that asks no more margin than the account already owes, such as one that closes a position, always goes.
The margin call
pf.margin(engine)
# {'initial': 4865.18, 'maintenance': 4422.89, 'equity': 999502.73,
# 'excess': 994637.55, 'call': None}Portfolio.margin(engine) gives the account's initial and maintenance requirements, its equity, the excess of equity over the initial requirement, and the open call, if there is one.
- At each close, after the futures are marked, the account makes a margin call when its equity is under the maintenance requirement.
- At the next open, after anything that expired has settled, the call is met if equity is back at or above the initial requirement, which the night's moves can bring about. A call from a close that left equity below zero is never met this way: the account is liquidated at the open, whatever the night did, as a broker closes out an account in deficit.
- If it is not met, every future and option the account holds is closed at the market, through its book or its dealer. So is the stock in each name whose options the account held or that an exercise or an assignment delivered shares in. Other stock is kept.
- Each sale is sent again for what is left while the market still buys, as a broker works the order. A dealer shows a few levels and bids nothing under a cent, so one order can leave part of a position unsold. A long option nobody bids stays held: it can lose no more than its last few cents.
Portfolio.margin_calls keeps every call with its equity, maintenance and initial figures and whether it was met, and Portfolio.liquidations keeps each contract and stock position closed, with the quantity asked and filled. settle_close makes the call and settle_open decides it, and tf.evaluate, the gym environment and the library's MCP sessions call both.
The leverage cap still applies. With max_leverage set, a future counts at its full notional and an option at its delta times the underlying times 100, and an order that would take leverage over the cap is refused when it is placed.
The hosted app
observe shows account.margin on a session whose preset lists contracts: the requirements, equity, excess and the open call with the day whose close made it. The call, the next open's decision and each contract it closed are events of kind account in the market log, and the closing orders carry the note "closed on an unmet margin call". tfrun's market.margin reads the same.
Measured rows
| Row | What it measures | pt-v22 | Band |
|---|---|---|---|
| MG1 | share of one-session moves of the front futures past the initial margin set the close before | 0.010 | 0.005 to 0.015 |
| MG3 | share of a name's option portfolios' sessions that lose more than the margin set the close before | 0.00005 | 0 to 0.0011 |
| MG2 | margin calls that leave risk after the next open, and accounts below zero without a liquidation | 0 | 0 |
MG1's band is the clearing-house standard: a scan meant to cover 99% of one-session moves should see 0.5% to 1.5% of them go past it. MG3's comes from the market itself. A portfolio margined over moves of 15% loses more than its margin only when its stock moves further than that in one session, which large US stocks did on 0.05% of days over 2015 to 2025, most of them in March 2020. MG1 is read over 270 simulated histories of 21 years, MG3 over 270 simulated histories of option portfolios, and MG2 over every call in the traded runs. A call leaves risk when, after the liquidation, the account still holds a future, a short option, or an option the market would still buy.