# finmath Position Size Calculator

> finmath Position Size Calculator is a paid API for AI agents from finmath.qzqh5rrbkz.workers.dev, paid per call via x402, $0.002/call, status unknown (last checked 2026-09-15).

Calculates optimal position size for a trade given account equity, entry price, stop price, and risk fraction using exact arithmetic

## Facts

- Endpoint: POST https://finmath.qzqh5rrbkz.workers.dev/v1/position_size
- Price: $0.002/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/finmath-position-size-calculator-4f8e13be
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_ZMRQXj0uNrlpyE7rgYFSf

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability finmath-position-size-calculator-4f8e13be -d '<json body>'
```

Example prompt: I have a $50,000 account and I want to buy ETH at $3,200 with a stop loss at $3,000 — I'm willing to risk 1% of my equity on this trade. How many units should I buy?

## When to prefer this

Use this endpoint when you need deterministic, exact position sizing arithmetic — especially when LLM-native math might be unreliable. Ideal for trading agents that need to size positions precisely based on account equity, a defined entry, and a hard stop loss level, without relying on probabilistic model outputs.

## Known failure modes

- Missing required fields (stop_price, entry_price, risk_fraction, account_equity) returns validation error
- risk_fraction outside 0-1 range may produce nonsensical results
- entry_price equal to stop_price causes division by zero
- Negative equity or price values may return error or undefined behavior
- Payment failure (402) if USDC balance insufficient

## How this service works

Deterministic finance and crypto math for AI agents: TradFi (NPV, IRR, XIRR, Black-Scholes + Greeks, bonds, VaR, Sharpe) and DeFi (impermanent loss, perp liquidation, funding, Uniswap v3, health factor, cost basis). Exact, model-free arithmetic that LLMs get wrong — priced per call in USDC.

## Output

Returns the mathematically exact position size (number of units to trade) so that the total loss if the stop price is hit equals exactly the specified risk fraction of the account equity, along with metadata about the calculation.

## Example request

```json
{
 "stop_price": 95,
 "entry_price": 100,
 "risk_fraction": 0.02,
 "account_equity": 10000
}
```

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "required": [
  "stop_price",
  "entry_price",
  "risk_fraction",
  "account_equity"
 ],
 "properties": {
  "stop_price": {
   "type": "number",
   "description": "stop_price"
  },
  "entry_price": {
   "type": "number",
   "description": "entry_price"
  },
  "risk_fraction": {
   "type": "number",
   "description": "risk_fraction"
  },
  "account_equity": {
   "type": "number",
   "description": "account_equity"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "object",
 "required": [
  "result",
  "meta"
 ],
 "properties": {
  "meta": {
   "type": "object"
  },
  "result": {}
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/finmath-position-size-calculator-4f8e13be/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from finmath.qzqh5rrbkz.workers.dev](https://www.zero.xyz/host/finmath.qzqh5rrbkz.workers.dev/llms.txt)
