How TradingCalc formulas work
Every number TradingCalc returns is the result of a deterministic formula — derived from exchange documentation, regression-tested against exact-value vectors, and verifiable on demand. This page explains where each formula comes from and how correctness is enforced.
The core principle: same inputs, same outputs
TradingCalc is not an AI. It does not estimate, approximate, or sample. Given the same inputs, it always produces the same outputs — down to the last cent. This property is not incidental; it is enforced by design and verified continuously.
Three-layer verification system
Correctness is enforced at three independent levels. Breaking one layer surfaces in at least one other.
src/lib/verify.ts22 exact input/output pairs, each with step-by-step arithmetic in the source field. Written independently of the formula code — they define the expected answer, not the implementation.
src/lib/calculators/calculators.test.ts66 Vitest tests: 22 exact-value vector tests + 44 property tests (sign invariants, round-trips, monotonicity). Runs in CI on every push. A push that breaks any test does not deploy.
/api/mcp → system.verifyAny caller — human or AI agent — can call system.verify via MCP to run all 22 vectors against the live production code. Returns pass/fail per vector with expected vs actual values.
Formula reference — all 12 calculators
Each row shows the core formula, its exchange documentation source, and how many canonical test vectors cover it.
Net PnL = (exitPrice − entryPrice) × size − openFee − closeFeeBinance Futures documentation — "How to calculate PnL"
Liq (long) = entryPrice × (1 − 1/leverage + maintenanceMarginRate)Bybit Derivatives documentation — "Liquidation Price Calculation"
Breakeven (long) = entryPrice × (1 + openFeePct + closeFeePct)Derived from fee structure; verified against Binance and Bybit fee schedules
size = riskAmount / (|entryPrice − stopLoss| / entryPrice × entryPrice)Standard position sizing formula; cross-verified with broker documentation
avgEntry = Σ(price_i × qty_i) / Σ(qty_i)Weighted average formula; standard across all exchanges
exitPrice (long) = (targetPnl + size × entryPrice + openFee) / (size − closeFee)Derived from PnL formula by solving for exitPrice
fundingCost = notional × fundingRate × nPeriodsBinance Futures — "Funding Rate Mechanism"
totalCost = Σ (notional_t × fundingRate) where notional decays with P&LDerived; cross-verified with Bybit funding cost examples
annualYield = (rateA − rateB) × periodsPerYear × 100Standard carry trade formula; exchange-agnostic
shortSize = spotSize × (1 + fundingCost / spotNotional)Delta-neutral hedge formula; Binance spot + futures hedging guide
maxLev = 1 / (maintenanceMarginRate + (volatility × safetyFactor))Derived from maintenance margin requirements; cross-referenced with exchange margin tables
Applies PnL formula across N price targets; returns P&L tableComposed from PnL formula; no additional derivation
What a test vector looks like
Each vector in src/lib/verify.ts contains explicit step-by-step arithmetic so the expected answer can be verified by hand — independent of the implementation.
{
calc: 'pnl',
label: 'BTC long, 10× leverage, maker/taker fees',
input: {
side: 'long',
entryPrice: 60000,
exitPrice: 63000,
contractSize: 0.1,
leverage: 10,
feeOpenPct: 0.0002, // 0.02% maker
feeClosePct: 0.0005, // 0.05% taker
},
expected: {
grossPnl: 300,
openFee: 1.20,
closeFee: 3.15,
netPnl: 295.65,
roe: 49.275,
},
source: `
Gross = (63000 - 60000) × 0.1 = 300
Open fee = 60000 × 0.1 × 0.0002 = 1.20
Close fee = 63000 × 0.1 × 0.0005 = 3.15
Net = 300 - 1.20 - 3.15 = 295.65
Margin = 60000 × 0.1 / 10 = 600
ROE = 295.65 / 600 × 100 = 49.275%
`,
}Self-verification via MCP
AI agents and trading systems can call system.verify before relying on results. The response includes pass/fail per vector, expected vs actual values, and a timestamp.
// Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": { "name": "system.verify", "arguments": {} }
}
// Response
{
"status": "pass",
"passed": 22,
"failed": 0,
"total": 22,
"timestamp": "2026-04-09T...",
"results": [
{ "label": "BTC long, 10× leverage", "status": "pass", "calc": "pnl" },
{ "label": "Isolated long, 10× leverage", "status": "pass", "calc": "liquidation" },
...
]
}Live proof (runs on every page load, no cache): tradingcalc.io/verify
What this means in practice
Call system.verify before a trading session. If it passes, every formula call you make during that session returns auditable, exact outputs.
Embed the MCP endpoint. Your bot gets exact liquidation prices and position sizes — not LLM estimates that vary between calls.
The same formula runs in CI, in the API, and on the public /verify page. Three independent surfaces showing the same result.
Read the test vectors in verify.ts. If the arithmetic matches your manual calculation, you can trust the endpoint.
Start using deterministic calculations
19 MCP tools. Free tier, no signup required. Add to Claude Desktop, Cursor, or call the REST endpoint directly.