{
  "schemaVersion": 1,
  "slug": "stock-profit-calculator",
  "category": "finance",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "0fb51c4b9a81e5feff6c7ef36c67af101022f8a23dda1318a5d82bc7ae16c237",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/stock-profit-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": "profit = (p₂n − f) − p₁n; ROI = profit ÷ (p₁n) × 100",
    "vars": [
      [
        "p₁",
        "Buy price"
      ],
      [
        "p₂",
        "Sell price"
      ],
      [
        "n",
        "Shares"
      ],
      [
        "f",
        "Fees"
      ]
    ],
    "note": "Cost basis = buy price × shares; net proceeds = sell price × shares − fees; profit = proceeds − cost basis; return = profit ÷ cost basis. Return is undefined when cost basis is zero."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const costBasis = buyPrice*shares; const proceeds = sellPrice*shares - fees; const profit = proceeds - costBasis; return { profit, returnPercent: costBasis>0 ? profit/costBasis*100 : null, proceeds, costBasis };",
    "inputs": [
      {
        "name": "buyPrice",
        "type": "number",
        "default": 50,
        "min": 0,
        "max": 1000000,
        "step": 0.01
      },
      {
        "name": "sellPrice",
        "type": "number",
        "default": 60,
        "min": 0,
        "max": 1000000,
        "step": 0.01
      },
      {
        "name": "shares",
        "type": "number",
        "default": 100,
        "min": 0,
        "max": 10000000,
        "step": 1
      },
      {
        "name": "fees",
        "type": "number",
        "default": 10,
        "min": 0,
        "max": 1000000,
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "profit",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "returnPercent",
        "precision": 2,
        "unit": "%",
        "optional": true
      },
      {
        "name": "proceeds",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "costBasis",
        "precision": 2,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
