# finmath Cost Basis Calculator

> finmath Cost Basis 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-13).

Computes cost basis for cryptocurrency or asset lots using configurable accounting methods (FIFO, LIFO, HIFO, etc.) given purchase lots and a sale quantity

## Facts

- Endpoint: POST https://finmath.qzqh5rrbkz.workers.dev/v1/cost_basis
- Price: $0.002/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-13
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/finmath-cost-basis-calculator-affc463c
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_VwvEKDTeDni4Fn2DyUX0E

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-cost-basis-calculator-affc463c -d '<json body>'
```

Example prompt: Calculate the FIFO cost basis for selling 1.5 ETH — I bought 1 ETH at $1,800 on Jan 5, then 1 ETH at $2,200 on Mar 10, and now I'm selling 1.5 ETH.

## When to prefer this

Use this endpoint when you need deterministic, exact cost basis arithmetic for tax reporting or portfolio tracking — especially for crypto assets where LLMs are known to make arithmetic errors. Prefer this over manual calculation or LLM reasoning when precision matters for FIFO/LIFO/HIFO lot matching or when computing realized gains for tax purposes.

## Known failure modes

- Missing required 'lots' array — returns validation error
- Missing required 'sell_qty' — returns validation error
- sell_qty exceeds total available quantity in lots — returns error or partial fill
- Invalid method string — may default to FIFO or return error
- Malformed lot objects missing price or quantity fields — returns parsing error
- Payment not provided or insufficient USDC — returns 402 Payment Required

## 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 computed cost basis result including lot allocations used, total cost basis amount, and metadata about the calculation method applied.

## Example request

```json
{
 "lots": [
  {
   "quantity": 1,
   "cost_per_unit": 1800
  },
  {
   "quantity": 1,
   "cost_per_unit": 2200
  }
 ],
 "method": "FIFO",
 "sell_qty": 1.5
}
```

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "required": [
  "lots",
  "sell_qty"
 ],
 "properties": {
  "lots": {
   "type": "array",
   "description": "lots"
  },
  "method": {
   "type": "string",
   "description": "method"
  },
  "sell_qty": {
   "type": "number",
   "description": "sell_qty"
  }
 }
}
```

## 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-cost-basis-calculator-affc463c/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)
