{
  "schemaVersion": 1,
  "slug": "currency-exchange-calculator",
  "category": "travel",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "e74cef53219c9d60cb65f499b9713c1d05129f14a011ae4d5edbabb65eebdd9d",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/currency-exchange-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": "Aₙ = max(0, A − min(A,F)); P = Aₙ·p/100; Y = (Aₙ − P)·r; S = (Aₙ − P)·(M − r)/M; T = min(A,F) + P + S",
    "vars": [
      [
        "A",
        "Amount in source-currency units"
      ],
      [
        "F",
        "Fixed fee in source-currency units"
      ],
      [
        "p",
        "Percentage fee (%)"
      ],
      [
        "r",
        "Quoted target units per source unit"
      ],
      [
        "M",
        "Optional mid-market reference rate"
      ],
      [
        "P",
        "Percentage fee (source units)"
      ],
      [
        "Y",
        "Amount received (target units)"
      ],
      [
        "S",
        "Rate difference vs reference (source units)"
      ],
      [
        "T",
        "Net cost vs reference (source units)"
      ]
    ],
    "note": "Costs are shown in source-currency units. The fixed fee is deducted first; the percentage fee applies to the remainder. The rate difference is converted to source units using the optional mid-market reference; without a reference, only entered fees are counted."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const fixedApplied = amount > 0 ? Math.min(amount, fixedFee) : 0; const afterFixed = Math.max(0, amount-fixedApplied); const feeAmount = afterFixed*feePercent/100; const net = afterFixed-feeAmount; const converted = net*rate; const markupCost = midMarketRate > 0 ? net*(midMarketRate-rate)/midMarketRate : 0; const totalCost = fixedApplied+feeAmount+markupCost; return { converted, effectiveRate: amount > 0 ? converted/amount : 0, feeAmount, markupCost, totalCost, costPercent: amount > 0 ? totalCost/amount*100 : 0 };",
    "inputs": [
      {
        "name": "amount",
        "type": "number",
        "default": 1000,
        "min": 0,
        "max": 10000000,
        "step": 1
      },
      {
        "name": "rate",
        "type": "number",
        "default": 0.92,
        "min": 0.000001,
        "max": 100000,
        "step": 0.000001
      },
      {
        "name": "midMarketRate",
        "type": "number",
        "default": 0.94,
        "min": 0,
        "max": 100000,
        "step": 0.000001
      },
      {
        "name": "feePercent",
        "type": "number",
        "default": 2.5,
        "min": 0,
        "max": 20,
        "step": 0.1,
        "slider": true
      },
      {
        "name": "fixedFee",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 100,
        "step": 0.5,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "converted",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "effectiveRate",
        "precision": 6,
        "unit": ""
      },
      {
        "name": "feeAmount",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "markupCost",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "totalCost",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "costPercent",
        "precision": 2,
        "unit": "%"
      }
    ],
    "interpret": null
  }
}
