LIVE, NO CACHE, EVERY REQUEST

Verified calculations, checked live on every request

Every formula is traceable. Every output is regression-tested. This page runs live on every request.

60 passed · 60 total vectors · checked live at Sat, 21 Nov 2026 21:17:57 GMT
01WHAT IS THIS

Every calculator on TradingCalc runs against a set of canonical test vectors: exact input/output pairs derived step-by-step from the underlying formulas. This page executes all vectors in real time on each request (no cache) and reports the result.

The vectors cover all 12 calculators: PnL, Liquidation, Breakeven, Risk Sizer, Funding Cost, Average Entry, Target Exit, Scenario, Max Leverage, Hedge Ratio, Funding Arb, and Compound Funding. These are the core calculators behind the perpetual futures tools. Options, forex, risk and statistics, prediction-market, and on-chain tools are covered by their own test suites in CI, with reference values cross-checked against independent libraries where they exist. For example, the Black-Scholes price and Greeks match QuantLib to within 1e-10 on 5,000 random options, and again on 5,000 options with a dividend yield (method and results). The Black-Scholes formula with a dividend yield q is published as: Black-Scholes with a continuous dividend yield q (percent per year in dividendYieldPct, 0 for crypto): d1 = [ln(S/K) + (r − q + σ²/2)T] / (σ√T), d2 = d1 − σ√T; Call = S·e^(−qT)·N(d1) − K·e^(−rT)·N(d2); Put = K·e^(−rT)·N(−d2) − S·e^(−qT)·N(−d1); Delta(call) = e^(−qT)·N(d1), Delta(put) = −e^(−qT)·N(−d1); Gamma = e^(−qT)·φ(d1) / (S·σ·√T); Vega = S·e^(−qT)·φ(d1)·√T; Theta(call) = −S·e^(−qT)·φ(d1)·σ/(2√T) + q·S·e^(−qT)·N(d1) − r·K·e^(−rT)·N(d2), Theta(put) = −S·e^(−qT)·φ(d1)·σ/(2√T) − q·S·e^(−qT)·N(−d1) + r·K·e^(−rT)·N(−d2), per year (the tool reports per day); Rho(call) = K·T·e^(−rT)·N(d2), Rho(put) = −K·T·e^(−rT)·N(−d2).

The same vectors are also available to AI agents via the system.verify MCP tool at tradingcalc.io/api/mcp.

02FORMULA ASSUMPTIONS
pnlNet PnL (linear) = gross − entryPrice × size × feeOpenPct − exitPrice × size × feeClosePct; gross long = (exitPrice − entryPrice) × size, short = (entryPrice − exitPrice) × size. Inverse: size is USD contracts, gross(coin) long = size × (1/entryPrice − 1/exitPrice), short = size × (1/exitPrice − 1/entryPrice), fees on the coin notional at each fill.
breakevenBreakeven (linear) long = entryPrice × (1 + feeOpenPct) / (1 − feeClosePct), short = entryPrice × (1 − feeOpenPct) / (1 + feeClosePct). Inverse swaps the two fee roles.
target_exitExit (linear) long = (targetPnl + entryPrice × sizeBase × (1 + feeOpenPct)) / (sizeBase × (1 − feeClosePct)), short = (entryPrice × sizeBase × (1 − feeOpenPct) − targetPnl) / (sizeBase × (1 + feeClosePct)). Inverse (sizeBase in USD contracts, PnL in the coin): long = (1 + feeClosePct) / ((1 − feeOpenPct) / entryPrice − targetPnl / sizeBase), short = (1 − feeClosePct) / (targetPnl / sizeBase + (1 + feeOpenPct) / entryPrice). An ROE target in percent points becomes targetPnl = targetValue / 100 × margin, margin = entryPrice × sizeBase / leverage (inverse: sizeBase / (entryPrice × leverage)).
risk_sizersizeBase (linear) = riskUsdt / (|entryPrice − stopLoss| + entryPrice × feeOpenPct + stopLoss × feeClosePct): the loss at the stop, both fees included, equals riskUsdt. Inverse: size in USD contracts.
average_entryAverage entry (linear) = Σ(price × quantity) / Σ(quantity). Inverse: Σ(quantity) / Σ(quantity / price), the harmonic mean.
scenarioThe PnL formula applied at each move in deltasPct: exitPrice = entryPrice × (1 + delta / 100).
liquidationLiq (linear) long = entryPrice × (1 − 1/leverage) / (1 − m), short = entryPrice × (1 + 1/leverage) / (1 + m), floored at 0, with m = mmr + liqFeeRate (maintenance margin on the position value at the liquidation price, the Bybit, KuCoin and Hyperliquid form; liqFeeRate defaults to 0). With mmBase "entry" (maintenance margin on the entry value, the MEXC form) long = entryPrice × (1 − 1/leverage + m), short = entryPrice × (1 + 1/leverage − m). Inverse long = entryPrice × (1 + m) / (1 + 1/leverage), short = entryPrice × (1 − m) / (1 − 1/leverage); with mmBase "entry" long = entryPrice / (1 + 1/leverage − m), short = entryPrice / (1 − 1/leverage + m). A denominator of 0 or below, or a result more than 1e9 times the entry price, means no liquidation price: liqPrice is null. When m >= 1/leverage (maintenance margin plus fee at least the initial margin) the position is liquidated the moment it opens: liqPrice is the entry price and liquidatedAtEntry is true. Isolated margin with one flat maintenance rate: no extra margin. Optional tiered mode with shared collateral (any of tiers, walletBalance, otherMaintenanceMargin, otherUnrealizedPnl selects it, and size is then required; size alone leaves the flat model on). Linear: liqPrice = (WB − TMM1 + UPNL1 + cum − s × size × entryPrice) / (size × (mmr − s)) with s = +1 long, −1 short, for the tier (mmr, cum) that holds size × liqPrice. Inverse (size in USD contracts; bands, cum, WB, TMM1, UPNL1 in the base coin): with WBnet = WB − TMM1 + UPNL1, long liqPrice = size × (1 + mmr) / (WBnet + size / entryPrice + cum), short liqPrice = size × (1 − mmr) / (size / entryPrice − WBnet − cum), for the tier that holds size / liqPrice; a short whose denominator is not positive in every band has liqPrice null. cum(n) = cum(n−1) + upTo(n−1) × (mmr(n) − mmr(n−1)); the last tier is open-ended (an upTo given on it is ignored); mmBase "entry" and liqFeeRate are refused in this mode (no liquidation fee term); tier rows supplied by the caller.
max_leverageMax leverage = maxDrawdownPct / (volatilityPct + mmr × 100), every term in percent points, rounded down to 0.1x, minimum 1x.
hedge_ratioShort notional = spotSize × hedgeRatio / 100; margin = short notional / leverage; funding per day = short notional × fundingRatePct / 100 × (24 / intervalHours), 3 payments a day at the default 8 hours. Inverse (needs entryPrice): the short is the same USD contracts, margin and funding are those USD figures divided by entryPrice, paid in the base coin.
funding_costtotalCost (linear, sizeBase in the coin) = ± sizeBase × entryPrice × fundingRate × (24 / intervalHours) × days; inverse (sizeBase in USD contracts, cost in the coin) = ± (sizeBase / entryPrice) × fundingRate × (24 / intervalHours) × days. fundingRate is a decimal per funding interval of intervalHours hours (default 8, so 3 payments a day; some symbols pay every 4, 2 or 1 hours); + for a long, − for a short (a negative cost is funding received).
funding_arbAnnualized yield % = (shortFundingRate − longFundingRate) × (24 / intervalHours) × 365, rates in percent per interval.
compound_fundingEach funding period: earned = capital × fundingRatePct / 100. Funding received: capital += earned × reinvestPct / 100, the rest is withdrawn and still counts as earned. Funding paid comes out of capital in full, at most the capital there is (a rate of −100% or worse per interval wipes the account out in the first period). Days are rounded up to whole days; totalEarned = finalCapital + totalWithdrawn − initialCapital; APY % = (((finalCapital + totalWithdrawn) / initialCapital)^(365 / days) − 1) × 100, or −100 when that end value is 0.
pre_trade_checkComposite: orchestrates risk_sizer + breakeven + liquidation + funding_cost. Safety = liqDistance / stopDistance ratio (danger <1.5x, warn <3x).
03TEST VECTORS
#CALCULATORTEST CASESTATUS
1pnlBTC long +10%: gross=500, fees=3.75, pnl=496.25PASS
2pnlETH short −10%: gross=300, fees=1.95, pnl=298.05PASS
3pnlZero fees: pnl equals gross exactlyPASS
4pnlInverse (coin-margined) long, $1M contracts: gross=100 BTC, fees=0.3 BTC, pnl=99.7 BTCPASS
5pnlInverse short, price falls 20%, zero fees: gross=0.25 BTCPASS
6pnlInverse short max loss bound, zero fees: as exit price -> infinity, coin loss converges to size/entry = 500 BTC, never beyond itPASS
7pnlInverse short max loss bound, nonzero opening fee: the bound must include feeOpenPct - the closing fee vanishes as exit->infinity but the opening fee (fixed at open) does notPASS
8pnlmaxLossBound is null for a linear short - linear contracts have no such finite ceiling (USD loss is genuinely unbounded as price rises)PASS
9pnlmaxLossBound is null for an inverse long too - the bound only applies to inverse SHORTS (an inverse long has the opposite, unbounded-as-price-falls-to-0 asymmetry instead)PASS
10liquidationBTC long 10x: liqPrice≈45226.1307 (maintenance margin on the value at the liquidation price, Bybit USDT form)PASS
11liquidationBTC short 10x: liqPrice≈54726.3682PASS
12liquidationLinear long 20x with mmr 6%: maintenance margin exceeds the initial margin, liquidated at once at the entry price (liqPrice=8000, not the 8085.1 the ordinary formula would give)PASS
13liquidationInverse long 10x: liqPrice≈45681.8182 (Bybit inverse form)PASS
14liquidationInverse short 10x: liqPrice≈55277.7778PASS
15liquidationLinear long 25x, maintenance margin on the entry value: liqPrice=7720 (MEXC help-center example)PASS
16liquidationLinear short 25x, maintenance margin on the entry value: liqPrice=8280PASS
17liquidationLinear long 50x with a 0.06% liquidation fee: liqPrice≈29535.8645 (KuCoin help-center example)PASS
18liquidationInverse long 10x, maintenance margin on the entry value: liqPrice≈45662.1005PASS
19liquidationInverse short 10x with a 0.06% liquidation fee: liqPrice≈55244.4444PASS
20liquidationETHUSDT long, cross margin, tier rate 10% with maintenance amount 135365: liqPrice≈1153.2565 (Binance help-center example, page figure 1153.26)PASS
21liquidationBTCUSDT long, cross margin, tier rate 2.5% with maintenance amount 16300: liqPrice≈26316.8933 (Binance help-center example, page figure 26316.89)PASS
22liquidationBTC long 45 at 50000, 2x isolated, five Bybit-style tiers: the position starts in tier 3 (notional 2.25M) and is liquidated in tier 2 at 25114.2379PASS
23liquidationBTC short 45 at 50000, 5x isolated, five Bybit-style tiers: liquidated in tier 4 at 59702.3198PASS
24liquidationBTCUSD inverse long 10,000,000 USD at 50000, 10x isolated, Bybit inverse tiers: liquidated in tier 2 at 45753.1144PASS
25liquidationBTCUSD inverse short 10,000,000 USD at 50000, 10x isolated, Bybit inverse tiers: liquidated in tier 2 at 55230.1255PASS
26breakevenLong with standard exchange fees: breakeven≈100.0700PASS
27breakevenZero fees: breakeven=entry, totalFees=0, distance=0PASS
28breakevenInverse long, $1M contracts: BE≈100.3003 (mirrors linear short formula)PASS
29breakevenInverse short, $1M contracts: BE≈99.7003PASS
30risk_sizerLong, 5% stop, $10 risk: stopDistPct=5, sizeBase≈1.9734PASS
31risk_sizerInverse long, 5% stop, $1000 risk: sizeQuote=19000 USD contractsPASS
32risk_sizerInverse short, 5% stop, $1000 risk: sizeQuote=21000 USD contractsPASS
33funding_costLong, 0.01% per 8h, 7 days: totalCost=0.21, annualPct=10.95PASS
34funding_costShort receives when rate is positive: totalCost=−0.03PASS
35funding_costInverse long, $1M contracts, 0.01%/8h, 7 days: totalCost=21 coin, breakevenShift≈0.210442 (up)PASS
36funding_costInverse short paying a negative rate, $1M contracts, -0.01%/8h, 7 days: totalCost=21 coin, breakevenShift≈0.209560 (down)PASS
37average_entryWeighted average: (100×1+200×3)/4=175PASS
38average_entryInverse (coin-margined): two equal-USD fills at 2000 and 4000 average to the harmonic mean 2666.67, not the arithmetic mean 3000PASS
39target_exitTarget pnl=0 → net pnl is zero (round-trip breakeven)PASS
40target_exitLong target $10 PnL no fees: pnl≈10, exit above entryPASS
41target_exitInverse long, $1M contracts, target 50 coin PnL, zero fees: exitPrice≈100.5025PASS
42target_exitInverse short, $1M contracts, target 50% ROE, zero fees: exitPrice≈95.2381PASS
43scenarioLong +10% no fees: scenarios[0].pnl=10PASS
44scenarioInverse long +25%, $1M contracts, no fees: scenarios[0].gross=100 coinPASS
45max_leverage10k acct, 10% max drawdown, 3% vol: maxLev=2.8x, safeMargin=3500PASS
46max_leverageExtreme volatility: leverage is always ≥1 (floored)PASS
47max_leverage30% drawdown, 2.5% vol, 0.5% mmr: exactly 10.0x (the 0.1 boundary is decided by the inputs, not float noise)PASS
48hedge_ratioFull hedge 2x: perpNotional=10000, margin=5000, dailyCost=3PASS
49hedge_ratio50% hedge 1x: perpNotional=5000, margin=5000PASS
50hedge_ratioInverse full hedge 2x at 50,000: 100,000 USD contracts, margin 1 coin, funding 0.0006 coin a dayPASS
51hedge_ratioHourly funding (Hyperliquid style) 1x: 10,000 short, 0.001% an hour, funding 2.4 a dayPASS
52funding_arb0.02% net rate 30d: gross=180, net=170, APY=21.9%PASS
53funding_arbHyperliquid 1h interval: 24 periods/dayPASS
54compound_funding1000 USDT, 0.01%/8h, 1 day, 100% reinvest: finalCapital = 1000 × 1.0001^3 ≈ 1000.30003PASS
55compound_fundingreinvestPct=0: capital unchanged, every payment withdrawn and still counted as earnedPASS
56compound_fundingFractional duration (1.5d): dailyEarnings uses the 2 whole days actually simulated, not the fractional 1.5 inputPASS
57compound_fundingA -150%/period rate takes the whole capital in the first period: capital 0, nothing paid or earned after that, APY -100PASS
58pre_trade_checkBTC long 10x, 5% SL, 1% risk, 0.01%/8h funding: size=0.04, liqDist≈9.55%, safety=warnPASS
59pre_trade_checkBTC short 10x, 5% SL, 1% risk, +0.01%/8h funding received, 0.02%/0.05% fees: the breakeven moves up by about 5PASS
60pre_trade_checkBTC long 10x on an hourly-funding venue (Hyperliquid, dYdX, Kraken), 0.01%/h over 8h: 8 payments, not 1PASS
04ERROR MODEL
INVALID_INPUT

A required parameter is missing, out of range, or the wrong type.

OUT_OF_DOMAIN

Inputs are valid but the combination produces a mathematically undefined result (e.g. liquidation price below zero).

UNSUPPORTED_COMBINATION

The requested exchange / margin type / side combination is not supported by the formula.

RATE_LIMITED

The caller has exceeded the call quota for their tier. Retry after the window resets.

AUTH_REQUIRED

The endpoint requires a valid API key. Anonymous quota exhausted.

INTERNAL_ERROR

Unexpected server-side error. The formula did not execute. Safe to retry.

05VERSION HISTORY
v1.8.0 · 2026-10-23
  • Added: every canonical vector is checked against an independent Python reference written from the definitions
  • Verification: 46 canonical test vectors (was 43)
v1.6.0 · 2026-09-30
  • Added: public daily anchor. Once a day the verification state is signed and its hash is written to Solana; records are readable at GET /api/anchors (see the section below)
v1.5.0 · 2026-09-25
  • Added: maxLossBound on pnl for inverse short positions (the coin-denominated loss ceiling as exit price rises without limit)
  • Verification: 42 canonical test vectors (was 35)
v1.4.0 · 2026-09-19
  • Added: every MCP tools/call response is signed (ECDSA P-256); system.pubkey returns the public key for offline verification
v1.3.0 · 2026-09-08
  • Added: contractType ('linear' | 'inverse') on pnl, liquidation, average_entry, breakeven, target_exit, scenario, risk_sizer, funding_cost
  • Inverse (coin-margined) contracts settle in the base coin and use reciprocal price math: average_entry's inverse average is the harmonic mean of fill prices, not arithmetic
  • Verification: 35 canonical test vectors (was 23)
v1.2.1 · 2026-03-31
  • Changed: pre_trade_check output now includes summary_a/b/c: human-readable Russian decision strings
  • summary_a: position size, breakeven price, funding cost per 24h
  • summary_b: liquidation distance ratio with safety verdict (ok/warn/danger)
  • summary_c: overnight breakeven shift over hold_hours
v1.2.0 · 2026-03-31
  • Added: pre_trade_check, a composite intent tool (orchestrates risk_sizer + breakeven + liquidation + funding_cost)
  • Returns decision card: position size, breakeven, funding cost, liquidation safety, overnight breakeven shift
  • Verification: 23 canonical test vectors (was 22)
v1.1.0 · 2026-03-30
  • Added: max_leverage, hedge_ratio, funding_arb, compound_funding
  • Changed: tool grouping into 3 canonical suites (Trade Planning / Risk & Margin / Funding & Carry)
  • Verification: 22 canonical test vectors (was 12)
v1.0.0 · 2025-12-01
  • Initial release: pnl, breakeven, target_exit, position_sizer, average_entry, scenario, liquidation, funding_cost
  • Verification: 12 canonical test vectors
MCP ENDPOINT: POST /api/mcp · TOOL: system.verify · API DOCS
06PUBLIC ANCHOR

Verification state, written to Solana every day

Once a day the state of this page (pass/fail, vector counts, the hashes of the vector set and of the results) is signed and its hash is written to the Solana blockchain. A past day cannot be edited afterwards, by us or anyone else.

LATEST DAY (UTC)2026-11-21
DAYS IN A ROW53
RECORDS ANCHORED53
HASH OF THE LATEST RECORD57e5e5d783c2b04770a81b93d063558a260ec0da8bd772e4e1929c7717e38165WALLET8Hi6TUCbcp7UShRcDD5FGP6K6y5DzhrCEa8YH7NWXmHL