Verified calculations, checked live on every request
Every formula is traceable. Every output is regression-tested. This page runs live on every request.
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.
The same vectors are also available to AI agents via the system.verify MCP tool at tradingcalc.io/api/mcp.
| # | CALCULATOR | TEST CASE | STATUS |
|---|---|---|---|
| 1 | pnl | BTC long +10%: gross=500, fees=3.75, pnl=496.25 | PASS |
| 2 | pnl | ETH short −10%: gross=300, fees=1.95, pnl=298.05 | PASS |
| 3 | pnl | Zero fees: pnl equals gross exactly | PASS |
| 4 | pnl | Inverse (coin-margined) long, $1M contracts: gross=100 BTC, fees=0.3 BTC, pnl=99.7 BTC | PASS |
| 5 | pnl | Inverse short, price falls 20%, zero fees: gross=0.25 BTC | PASS |
| 6 | pnl | Inverse short max loss bound, zero fees: as exit price -> infinity, coin loss converges to size/entry = 500 BTC, never beyond it | PASS |
| 7 | pnl | Inverse 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 not | PASS |
| 8 | pnl | maxLossBound is null for a linear short - linear contracts have no such finite ceiling (USD loss is genuinely unbounded as price rises) | PASS |
| 9 | pnl | maxLossBound 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 |
| 10 | liquidation | BTC long 10x: liqPrice=45250 (Binance isolated-margin formula) | PASS |
| 11 | liquidation | BTC short 10x: liqPrice=54750 | PASS |
| 12 | liquidation | Inverse long 10x: liqPrice≈45662.1005 (Bybit inverse isolated-margin formula) | PASS |
| 13 | liquidation | Inverse short 10x: liqPrice≈55248.6188 | PASS |
| 14 | breakeven | Long with standard exchange fees: breakeven≈100.0700 | PASS |
| 15 | breakeven | Zero fees: breakeven=entry, totalFees=0, distance=0 | PASS |
| 16 | breakeven | Inverse long, $1M contracts: BE≈100.3003 (mirrors linear short formula) | PASS |
| 17 | breakeven | Inverse short, $1M contracts: BE≈99.7003 | PASS |
| 18 | risk_sizer | Long, 5% stop, $10 risk: stopDistPct=5, sizeBase≈1.9734 | PASS |
| 19 | risk_sizer | Inverse long, 5% stop, $1000 risk: sizeQuote=19000 USD contracts | PASS |
| 20 | risk_sizer | Inverse short, 5% stop, $1000 risk: sizeQuote=21000 USD contracts | PASS |
| 21 | funding_cost | Long, 0.01% per 8h, 7 days: totalCost=0.21, annualPct=10.95 | PASS |
| 22 | funding_cost | Short receives when rate is positive: totalCost=−0.03 | PASS |
| 23 | funding_cost | Inverse long, $1M contracts, 0.01%/8h, 7 days: totalCost=21 coin, breakevenShift≈0.2104 | PASS |
| 24 | average_entry | Weighted average: (100×1+200×3)/4=175 | PASS |
| 25 | average_entry | Inverse (coin-margined): two equal-USD fills at 2000 and 4000 average to the harmonic mean 2666.67, not the arithmetic mean 3000 | PASS |
| 26 | target_exit | Target pnl=0 → net pnl is zero (round-trip breakeven) | PASS |
| 27 | target_exit | Long target $10 PnL no fees: pnl≈10, exit above entry | PASS |
| 28 | target_exit | Inverse long, $1M contracts, target 50 coin PnL, zero fees: exitPrice≈100.5025 | PASS |
| 29 | target_exit | Inverse short, $1M contracts, target 50% ROE, zero fees: exitPrice≈95.2381 | PASS |
| 30 | scenario | Long +10% no fees: scenarios[0].pnl=10 | PASS |
| 31 | scenario | Inverse long +25%, $1M contracts, no fees: scenarios[0].gross=100 coin | PASS |
| 32 | max_leverage | 10k acct, 10% max drawdown, 3% vol: maxLev=2.8x, safeMargin=3500 | PASS |
| 33 | max_leverage | Extreme volatility: leverage is always ≥1 (floored) | PASS |
| 34 | max_leverage | 30% drawdown, 2.5% vol, 0.5% mmr: exactly 10.0x (the 0.1 boundary is decided by the inputs, not float noise) | PASS |
| 35 | hedge_ratio | Full hedge 2x: perpNotional=10000, margin=5000, dailyCost=3 | PASS |
| 36 | hedge_ratio | 50% hedge 1x: perpNotional=5000, margin=5000 | PASS |
| 37 | funding_arb | 0.02% net rate 30d: gross=180, net=170, APY=21.9% | PASS |
| 38 | funding_arb | Hyperliquid 1h interval: 24 periods/day | PASS |
| 39 | compound_funding | 1000 USDT, 0.01%/8h, 1 day, 100% reinvest: finalCapital≈1000.3003 | PASS |
| 40 | compound_funding | reinvestPct=0: capital unchanged, totalEarned=0 | PASS |
| 41 | compound_funding | Fractional duration (1.5d): dailyEarnings uses the 2 whole days actually simulated, not the fractional 1.5 input | PASS |
| 42 | compound_funding | Extreme -150%/period rate flips capital negative under a non-integer duration exponent: annualizedAPY clamps to -100 instead of NaN | PASS |
| 43 | pre_trade_check | BTC long 10x, 5% SL, 1% risk, 0.01%/8h funding: size=0.04, liqDist=9.5%, safety=warn | PASS |
A required parameter is missing, out of range, or the wrong type.
Inputs are valid but the combination produces a mathematically undefined result (e.g. liquidation price below zero).
The requested exchange / margin type / side combination is not supported by the formula.
The caller has exceeded the call quota for their tier. Retry after the window resets.
The endpoint requires a valid API key. Anonymous quota exhausted.
Unexpected server-side error. The formula did not execute. Safe to retry.
- Fixed: max_leverage returned 9.9x instead of 10.0x for inputs that give exactly 10 on paper (for example 30% drawdown, 2.5% volatility, 0.5% maintenance margin); the 0.1 rounding is now exact
- Verification: 43 canonical test vectors (was 42)
- 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)
- 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)
- Added: every MCP tools/call response is signed (ECDSA P-256); system.pubkey returns the public key for offline verification
- 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)
- 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
- 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)
- 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)
- Initial release: pnl, breakeven, target_exit, position_sizer, average_entry, scenario, liquidation, funding_cost
- Verification: 12 canonical test vectors
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.
8cd6b67b577a0fef0083e36f8ca4d5f25b2fa59fff3bd767f14cdf9dc0c4a702WALLET8Hi6TUCbcp7UShRcDD5FGP6K6y5DzhrCEa8YH7NWXmHL