{
  "schemaVersion": 1,
  "slug": "crypto-tax-calculator",
  "category": "crypto",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "a287a0f09909faf5f9841de7558364d6cac25ad30f29c825a02e525daa118d16",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/crypto-tax-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "Tx = max(0, (P_s − P_b) × q − F − L) × r ÷ 100",
    "vars": [
      [
        "P_s",
        "Sell price"
      ],
      [
        "P_b",
        "Buy price"
      ],
      [
        "q",
        "Quantity"
      ],
      [
        "F",
        "Fees"
      ],
      [
        "L",
        "Other losses deducted"
      ],
      [
        "r",
        "Tax rate (%)"
      ]
    ],
    "note": "Taxable gain = max(0, capital gain − entered losses); tax = taxable gain × selected user rate. The 365-day threshold is a simplified proxy for a U.S. more-than-one-year holding period, not legal tax classification."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const empty={grossProceeds:null,costBasis:null,capitalGain:null,taxableGain:null,taxRateUsed:null,taxOwed:null,afterTaxProfit:null,holdingType:null};const v=[buyPrice,sellPrice,quantity,holdingDays,fees,shortTermRate,longTermRate,otherLosses].map(Number);if(v.some(n=>!Number.isFinite(n))||buyPrice<0||sellPrice<0||quantity<=0||!Number.isInteger(holdingDays)||holdingDays<0||fees<0||shortTermRate<0||shortTermRate>60||longTermRate<0||longTermRate>60||otherLosses<0)return{...empty,__error:'inputError'};const proceeds=sellPrice*quantity,basis=buyPrice*quantity+fees,gain=proceeds-basis,taxable=Math.max(0,gain-otherLosses),isLong=holdingDays>365,rate=isLong?longTermRate:shortTermRate,tax=taxable*rate/100,afterTax=gain-tax;if(![proceeds,basis,gain,taxable,rate,tax,afterTax].every(Number.isFinite))return{...empty,__error:'inputError'};return{grossProceeds:proceeds,costBasis:basis,capitalGain:gain,taxableGain:taxable,taxRateUsed:rate,taxOwed:tax,afterTaxProfit:afterTax,holdingType:isLong?'Long-term rate selected':'Short-term rate selected'};",
    "inputs": [
      {
        "name": "buyPrice",
        "type": "number",
        "default": 20000,
        "min": 0,
        "max": 100000000,
        "step": 0.01
      },
      {
        "name": "sellPrice",
        "type": "number",
        "default": 45000,
        "min": 0,
        "max": 100000000,
        "step": 0.01
      },
      {
        "name": "quantity",
        "type": "number",
        "default": 1,
        "min": 0,
        "max": 1000000000,
        "step": 0.0001
      },
      {
        "name": "holdingDays",
        "type": "number",
        "default": 400,
        "min": 0,
        "max": 36500,
        "step": 1
      },
      {
        "name": "fees",
        "type": "number",
        "default": 100,
        "min": 0,
        "max": 10000000,
        "step": 0.01
      },
      {
        "name": "shortTermRate",
        "type": "number",
        "default": 32,
        "min": 0,
        "max": 60,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "longTermRate",
        "type": "number",
        "default": 15,
        "min": 0,
        "max": 60,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "otherLosses",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 10000000,
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "taxOwed",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "capitalGain",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "grossProceeds",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "costBasis",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "taxableGain",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "taxRateUsed",
        "precision": 1,
        "unit": "%"
      },
      {
        "name": "afterTaxProfit",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "holdingType",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
