Machine Trading Protocol/guides/instruments

Guide: perpetual futures (perp)

Status
guide
Source
github.com/lgalabru/machine-trading/tree/main/specs

This guide explains perpetual futures to someone who has never traded one: what a position is, what makes it gain and lose, what can wipe it out, and how a mandate keeps an agent trading one inside limits. The instrument profile is the normative text; when this guide and the profile disagree, the profile is right.

It builds one idea at a time, on a single example: you have $1,000, and SPCX trades at $100. The figures use made-up prices and a simplified venue; a venue profile, such as Phoenix, defines the real rules.

1. What a perp is

A perpetual future is a contract that tracks an underlying's price, such as a stock or a token, without anyone owning the underlying. Buying one (going long) gains when the price rises. Selling one (going short) gains when it falls. Shorting is as easy as buying, which is the main reason traders use perps.

A perp never expires: you hold it for as long as you like. What keeps its price close to the underlying's is a payment between longs and shorts called funding, which comes later, once the basics are in place.

1.1. The underlying

The underlying is whatever the perp's price follows. You never hold it: the perp only borrows its price, through the venue's index. On Phoenix, it can be one of five kinds of thing, and the kind decides where the price comes from and when:

Kind Example perp Its underlying Where the price comes from
Crypto SOL, BTC The token itself Spot markets, which trade around the clock
Stock SPCX, AAPL One share of a listed company: SpaceX, Apple US stock trading, 24 hours a day on weekdays
ETF SPY, QQQ A stock index: the S&P 500, the Nasdaq 100 The index's prices, on the same weekday hours
Commodity GOLD, WTIOIL Gold's spot price; a crude oil futures contract Spot and futures markets, closed from Friday to Sunday evening and for an hour each weekday evening
Pre-IPO ANTHROPIC A private company's valuation: $1 of the perp is $1 billion No public market: Phoenix's own pricing, within bounds it resets every four hours

The further the underlying is from a market that trades around the clock, the more of the week the perp spends without its anchor, which comes up again below. This guide follows SPCX throughout. Phoenix lists every market and its underlying in its market specs.

1.2. Your first trade

You have $1,000, and you think SPCX, trading at $100, is going up. Without a perp, your $1,000 buys 10 SPCX. With a perp, you open a long position on a venue instead, and the trade comes down to five numbers, in the order you meet them:

Number Your trade What it is
SPCX price $100 What SPCX trades at when you open.
Margin $1,000 What you commit: you deposit it on the venue. It's the most you can lose.
Leverage 5× The one number you choose: how many times your margin the bet is.
Notional $5,000 The size of your bet in dollars: margin × leverage. You never pay it.
Position 50 SPCX The notional in SPCX: $5,000 ÷ $100. Long is +50; short would be −50.

You don't own any SPCX. You hold a contract that gains $50, $1 for each of your 50 SPCX, every time SPCX rises $1, and loses $50 every time it falls $1. Buying 10 SPCX outright is the same ticket at 1×: a $1,000 notional, 10 SPCX.

1.3. As SPCX moves

Two more numbers follow from the ticket as SPCX moves. Your PnL (profit and loss) is your position times how far SPCX has moved. Your equity is your margin plus your PnL: what's left, and what you'd walk away with if you closed now.

SPCX PnL: 50 × (SPCX − $100) Equity: $1,000 + PnL
$110 +$500 $1,500
$100 $0 $1,000
$90 −$500 $500
≈ $82.47 ≈ −$876 ≈ $124, and the venue closes your position

The last row is the catch: the venue closes the position before your equity reaches zero. That is liquidation, and the next section explains exactly where it happens. Going short is the mirror image: short 50 SPCX gains $50 for every $1 SPCX falls.

The ticket and the ledger, in four lines:

notional = margin × leverage                 $1,000 × 5    = $5,000
position = notional ÷ SPCX at entry          $5,000 ÷ $100 = 50 SPCX
PnL      = position × (SPCX now − SPCX at entry)
equity   = margin + PnL

No money changes hands while SPCX moves: the venue re-values your position at its mark price for SPCX, recomputed continuously, and your equity moves with it. The PnL becomes real dollars when you close. On Phoenix the mark is the middle of three prices: an oracle price for SPCX, its own order book (best bid, best ask and last trade), and a smoothed blend of the two. Taking the middle one means a single odd trade or a single bad oracle update can't move the mark, or liquidate anyone, on its own.

What your dollars become

The ticket from above: set your margin and leverage, then drag where SPCX goes. The blue line is your equity with the perp, the grey one what your margin would be worth if you had bought SPCX with it.

Each $1 SPCX moves is worth $1 per unit you hold. Leverage sets how many units your dollars carry, so it steepens the line, and it moves the liquidation point closer: past it, the line drops to zero. The next section explains exactly where that point is.

2. Leverage and liquidation

Leverage is the one number on the ticket you choose. With the same $1,000 of margin, it sets everything else:

Leverage Margin Notional Position Each $1 SPCX moves SPCX moves 1%
1× $1,000 $1,000 10 SPCX $10 1% of your margin
5× $1,000 $5,000 50 SPCX $50 5% of your margin
20× $1,000 $20,000 200 SPCX $200 20% of your margin

Leverage multiplies the percentage you gain or lose on your margin. It works in both directions, and the losing direction has a floor.

2.1. Liquidation

The venue doesn't let your equity fall to zero. It requires it to stay above the maintenance margin: a share of what your position is worth now, 3% on this venue. Here is the ledger from your first trade again, at 5×, with the columns the venue watches:

SPCX PnL Equity Notional now (50 × SPCX) Maintenance (3% of notional) Leverage now (notional ÷ equity)
$100 $0 $1,000 $5,000 $150 5×
$90 −$500 $500 $4,500 $135 9×
$85 −$750 $250 $4,250 $127.50 17×
≈ $82.47 ≈ −$876 ≈ $124 ≈ $4,124 ≈ $124 33×: liquidated

Liquidation happens where equity meets the maintenance margin:

1,000 + 50 × (P − 100) = 0.03 × 50 × P
1,000 + 50 P − 5,000   = 1.5 P
48.5 P                 = 4,000
P                      = 82.47

The last column shows the same thing from the other side. The position stays 50 SPCX while your equity shrinks, so your leverage climbs as you lose: 5×, 9×, 17×. The venue liquidates you when it reaches 1 ÷ 3%, about 33×.

When it does, the venue sells SPCX out of your position into the market, at whatever the price is by then. It doesn't wait for zero because selling takes time and costs money: the $124 cushion pays for that and for the venue's liquidation fee, so your loss never lands on the venue or other traders. Phoenix sells only as much as it takes to bring your account back above the floor, so a liquidation can be partial; if the book can't absorb it, a backstop account takes the position over. This guide simplifies: it closes the whole position and counts what's left as lost. A liquidation is final: if SPCX is back at $100 an hour later, you are no longer in the trade.

To open a position, the venue asks for more than the maintenance margin: the initial margin. If it is 10%, a $5,000 notional needs at least $500 of margin, so 10× is the most you can open with. The gap between the two is your room to lose. Leverage above 1 ÷ maintenance (33× here) is impossible: the position would be liquidated the moment it opened.

On Phoenix, SPCX allows at most 15×, so its initial margin is 1 ÷ 15 ≈ 6.67% of the notional, and its maintenance margin is half of that, about 3.33%. This guide uses a round 3%: at Phoenix's 3.33%, your first trade would be liquidated at $82.76 instead of $82.47.

Where SPCX has to go to liquidate you

Your $1,000 again, SPCX at $100. Move the leverage and watch the liquidation prices close in on today's price. The shaded band is how far SPCX moves on an ordinary day.

The liquidation price moves toward today's price roughly as one over the leverage. Once a line enters the band, a normal day's move is enough to end the trade.

3. Funding

A dated future, the older kind of future, has an expiry date on which it settles at the underlying's price, so its price has to meet the underlying's by then. A perp never settles, so something else has to stop its price drifting away from the underlying's. That something is funding: at a regular interval the venue compares the perp's price with the underlying's, and moves money between longs and shorts.

Funding is paid on the notional, whatever the margin. It is small per interval and adds up over time. On Phoenix it settles every hour, on your position times the index price. With no premium at all, an equity perp's longs still pay shorts a small base rate, 0.005% per 8 hours, about 0.06 bp an hour; the guide's figures use made-up rates around it. It is also how perps are used without a view on the price: a trader who is paid funding on a perp and holds the opposite position elsewhere earns the funding with no price exposure.

What funding does to your $1,000

SPCX stays at $100 the whole time in this figure: everything that happens to your dollars is funding.

Funding grows in a straight line with the days held and the size of the position. A rate that looks tiny per hour is large per year, and leverage multiplies it on your dollars.

3.1. When SPCX's own market is closed

SPCX tracks one share of SpaceX, which trades on US stock exchanges. The perp is a separate market between perp traders on the venue, and it trades around the clock, so for part of the week it trades when its anchor can't.

On Phoenix, the index follows external prices 24 hours a day, 5 days a week: from Sunday 8 PM to Friday 8 PM Eastern, across pre-market, the regular session, post-market and overnight trading. Outside that window, over weekends and holidays, Phoenix switches to its own pricing:

External window (Sunday 8 PM – Friday 8 PM ET) Closed (weekends, holidays)
Index price Follows external SPCX prices Starts at the last external price, and drifts toward the price Phoenix's own order book implies, smoothed over about an hour
Perp price Held near the index by funding and arbitrage Capped within 1 ÷ max leverage of the last external price: 6.67% for SPCX, which allows 15×. Trades outside the cap don't execute
News Moves both Moves the perp, within the cap
Your position Re-valued and liquidated as usual Re-valued and liquidated as usual

When the external window reopens, the index snaps to wherever external SPCX trades, in one step. If perp traders guessed wrong over the weekend, or the news moved SPCX further than the cap allowed, the mark price follows, and a position can be liquidated at a price nobody traded at in between.

Phoenix's index price and impact pricing pages describe the details. Other venues handle closed hours differently, and their venue profiles should say how.

4. Parameters

What a perp is, as the specs and a venue describe it:

Parameter Who sets it What it means
Instrument reference The mandate <venue>:perp:<symbol>, such as phoenix:perp:SPCX.
max_position The mandate The largest position, long or short, in base units. Open orders don't count until they fill.
max_drawdown_usd The mandate How far, in USD, the account's value may fall below its running peak. It covers the account, not one perp.
Base unit and lot size The venue profile What one unit of the position is, and the smallest step it trades in.
Mark price The venue The price positions are valued and liquidated at.
Funding rate and interval The venue How much longs and shorts pay each other, and how often.
Initial and maintenance margin The venue The margin needed to open a position, and the margin below which it is liquidated. Together they cap leverage.
Fees The venue What each trade costs, usually less for orders that rest on the book than for orders that take from it.

The mandate's two limits are the ones an agent is held to. The venue's are the ones the market holds everyone to.

5. Risks

6. When to use it, and when not to

7. Trading a perp under a mandate

The mandate bounds an agent with two numbers for a perp, and the agent is responsible for both:

The venue's liquidation is a separate, harder floor. An agent that keeps the mandate's drawdown limit normally stays far from liquidation, but leverage decides how far: the mandate limits the loss in dollars, the venue limits it as a share of the margin.

8. Scenarios

Each scenario plays 48 hours of a made-up SPCX market against one perp position, under a mandate. The three panels share a time axis: hover one to read all three at that hour. The top panel is the market, the middle what the position made, and the bottom how far it fell from its best, against the mandate's drawdown limit.

48 hours of SPCX, under a mandate

SPCX starts at $100. Choose what it does over the next two days, then size your position and set the mandate's limits.

The drawdown limit counts from the running peak, not from entry: a position that first gains and then gives it back can break it without ever being down overall. Sizing so that max_drawdown_usd ÷ position is larger than the moves you expect keeps the mandate.

9. Check yourself

Three questions for each idea, all on SPCX. Work each one out on the ticket first (margin, leverage, notional, position), then open the answer.

9.1. PnL and leverage

You're long 10 SPCX from $100 at 5×. SPCX falls to $95. What is your PnL, and what share of your margin is it?

−$50. The notional is 10 × $100 = $1,000, so the margin is $1,000 ÷ 5 = $200, and −$50 is 25% of it: 5× the 5% move.

You put $1,000 of margin at 10× into a long, with SPCX at $100. SPCX rises to $104. What is your equity?

$1,400. The notional is $10,000, so the position is 100 SPCX, and the PnL is 100 × $4 = +$400: a 4% move is 40% on your margin.

You're short 20 SPCX from $100 at 4×. SPCX rises to $103. What is your PnL, and what's left of your margin?

−$60, leaving $440. The notional is $2,000, so the margin is $500. A short loses when SPCX rises: 20 × $3 = $60, which is 12% of the margin.

9.2. Funding

Funding is +1 bp an hour and you're short $10,000 of notional. Do you pay or receive, and how much a day?

You receive. Positive funding means longs pay shorts: 0.01% × $10,000 × 24 = $24 a day.

You're long 50 SPCX at $100, and funding is −0.5 bp an hour. Do you pay or receive, and how much a day?

You receive. Negative funding means shorts pay longs: 0.005% × $5,000 × 24 = $6 a day.

You're long with $1,000 of margin at 5×, and funding is +2 bp an hour. SPCX doesn't move. How long until funding has cost you 10% of your margin?

About 4 days. Funding is paid on the $5,000 notional, not the margin: 0.02% × $5,000 × 24 = $24 a day, and $100 ÷ $24 ≈ 4.2 days.

9.3. The drawdown limit

Your mandate's drawdown limit is $1,000 and you're long 50 SPCX. How far can SPCX fall from its peak before you break it?

$20: $1,000 ÷ 50 SPCX. From a peak of $110, SPCX falling below $90 breaks it. Funding paid along the way uses up some of that room.

Your limit is $500 and you're long 25 SPCX from $100. SPCX rises to $120, then falls. At what price do you break the limit?

Below $100, where you started. The peak is at $120, and the limit allows $500 ÷ 25 = $20 from there. You break the mandate with a PnL of zero, because the limit counts from the peak, not from your entry.

Your limit is $1,000 and you're short 40 SPCX. How far can SPCX rise before you break it?

$25 from its lowest point since you opened: $1,000 ÷ 40 SPCX. For a short, the peak of your account is where SPCX bottomed.

9.4. The mandate's rules

Why can a winning trade still break the mandate?

Because the position cap is independent of PnL: a position over max_position breaks the mandate whether or not it is making money. And the drawdown limit counts from the peak, so giving back gains counts too.

Your max_position is 70. You're long 60 SPCX, with a buy order for 20 more resting on the book. Have you broken the mandate?

Not yet: open orders don't count until they fill. But if the order fills, you're long 80 SPCX and over the cap. Size resting orders so that no fill can take you past it: here, 10 SPCX at most.

Your mandate's universe is only phoenix:perp:SPCX. You leave an order on another Phoenix market resting, and it never fills. Have you broken the mandate?

Yes. The universe rule covers open orders as well as positions: an order in an instrument outside the universe breaks it, filled or not.

10. Glossary

Every term this guide uses is in the glossary. In the text, an underlined term shows its definition when you hover it or tap it.