Skip to content

Investment · Calculation

Compare supplied investment cash-flow ledgers

Compares caller-supplied before- and after-tax dated flows for two to eight alternatives over a common horizon of up to 50 years. Optional weights control the balanced objective. Position determines the anonymous strategy ID.

Example result · state: available See output

Cost per success
20 calculation credits
Production plans
Standard, Business, Scale, Enterprise
Plan allowances
Free sandbox
Not available

Integration example

Make a request

Use a production key scoped to investor-compare-cash-ledgers.

Keep the key on your server. A successful call uses 20 calculation credits.

Production request

Set HT_PRODUCTION_KEY on your server. Save as example.mjs and run node example.mjs with Node.js 18 or later.

import { randomUUID } from "node:crypto";

const key = process.env.HT_PRODUCTION_KEY;
if (!key) throw new Error("Set HT_PRODUCTION_KEY on your server.");
const endpoint = "https://calc.hasstechapi.com/v2/calc/investor-compare-cash-ledgers";
const input = {
  "horizonStart": "2025-01-01",
  "horizonEnd": "2026-01-01",
  "discountRatePct": 0,
  "objective": "npv",
  "strategies": [
    {
      "capitalInvested": 100,
      "beforeTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 120
        }
      ],
      "afterTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 110
        }
      ]
    },
    {
      "capitalInvested": 100,
      "beforeTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 140
        }
      ],
      "afterTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 130
        }
      ]
    }
  ]
};
const requestId = process.env.HT_REQUEST_ID || Date.now() + "." + randomUUID();
// Keep this ID to look up usage if the connection is interrupted.
console.error("Usage lookup ID:", requestId);

const response = await fetch(endpoint, {
  method: "POST",
  redirect: "error",
  headers: {
    "Authorization": "Bearer " + key,
    "Content-Type": "application/json",
    "Idempotency-Key": requestId
  },
  body: JSON.stringify(input)
});
if (!response.ok) {
  const problem = await response.json().catch(() => null);
  const code = problem?.error?.code || response.statusText;
  const delay = response.headers.get("retry-after");
  if (delay) console.error("Retry-After (seconds):", delay);
  console.error("HTTP " + response.status + " " + code + ". Usage lookup ID: " + requestId);
  if (Array.isArray(problem?.error?.details)) {
    for (const issue of problem.error.details) console.error("Input issue:", JSON.stringify(issue));
  }
  process.exitCode = 1;
} else {
  console.log(JSON.stringify(await response.json(), null, 2));
}
cURL (shell)

Set HT_PRODUCTION_KEY on your server. Run in a POSIX shell with cURL 7.76+ and Python 3.7+ to create a request ID.

(
  set -eu
  : "${HT_PRODUCTION_KEY:?Set HT_PRODUCTION_KEY on your server}"
  request_id="${HT_REQUEST_ID:-}"
  if [ -z "$request_id" ]; then
    request_id=$(python3 -c 'import time, uuid; print(str(time.time_ns() // 1000000) + "." + str(uuid.uuid4()))')
  fi
  printf 'Usage lookup ID: %s\n' "$request_id" >&2
  # On INVALID_INPUT, read error.details in the JSON response body.
  curl --disable --silent --show-error --fail-with-body --include \
    --request POST 'https://calc.hasstechapi.com/v2/calc/investor-compare-cash-ledgers' \
    --header "Authorization: Bearer $HT_PRODUCTION_KEY" \
    --header 'Content-Type: application/json' \
    --header "Idempotency-Key: $request_id" \
    --data-binary @- <<'HT_INPUT'
{
  "horizonStart": "2025-01-01",
  "horizonEnd": "2026-01-01",
  "discountRatePct": 0,
  "objective": "npv",
  "strategies": [
    {
      "capitalInvested": 100,
      "beforeTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 120
        }
      ],
      "afterTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 110
        }
      ]
    },
    {
      "capitalInvested": 100,
      "beforeTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 140
        }
      ],
      "afterTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 130
        }
      ]
    }
  ]
}
HT_INPUT
)
If your request fails
400 INVALID_INPUT

Read error.details when present. Node prints each issue. cURL returns the JSON body. Each path points into your request. An empty path refers to the whole body.

Check the accepted inputs for required fields, units and ranges. Send the corrected JSON as a new request.

401 or 403
Check that the server has the bearer key for the endpoint’s environment and that the key includes investor-compare-cash-ledgers.
429
Read the service error code, check your allowance, and wait for the Retry-After interval when supplied before trying again.
Lost response, 409 or 503
Open Request lookup, select the same environment and enter the printed usage lookup ID. A settled ID has already consumed credits. To retry the same calculation, set HT_REQUEST_ID to the original ID and reuse the same inputs. A settled request does not return its result again. Unset the variable for a new request, which can consume credits.

The usage lookup ID is the Idempotency-Key your server sends. The response’s x-request-id identifies the HTTP exchange for support.

Output

Example result

These values come from running this operation on the example inputs.

state
available
formulaVersion
compare-strategies-2.0.0
value.horizonStart
2025-01-01
How to interpret this result
  • Compares caller-supplied before- and after-tax dated flows for two to eight alternatives over a common horizon of up to 50 years. Optional weights control the balanced objective. Position determines the anonymous strategy ID.
Full example response (JSON)
{
  "status": "available",
  "result": {
    "state": "available",
    "fieldErrors": {},
    "warnings": [],
    "assumptions": [
      {
        "key": "dayCount",
        "value": "ACT/365F",
        "source": "default"
      }
    ],
    "provenance": [
      {
        "source": "Microsoft XNPV/XIRR ACT/365F definitions",
        "asOf": "2026-08-13"
      }
    ],
    "formulaVersion": "compare-strategies-2.0.0",
    "ruleVersions": [],
    "auditTrail": [
      "Compared 2 strategies over 2025-01-01 through 2026-01-01.",
      "Discounted every dated before-tax and after-tax ledger at 0% using ACT/365F.",
      "Ranked by npv; exposed scores and non-dominated frontier."
    ],
    "value": {
      "horizonStart": "2025-01-01",
      "horizonEnd": "2026-01-01",
      "discountRatePct": "0",
      "dayCount": "ACT/365F",
      "objective": "npv",
      "strategies": [
        {
          "id": "strategy-1",
          "label": "Strategy 1",
          "capitalInvested": "100",
          "beforeTaxNpv": "20",
          "afterTaxNpv": "10",
          "afterTaxIrr": 0.10000000000000002,
          "irrState": "available",
          "afterTaxEquityMultiple": "1.1",
          "afterTaxNetCash": "10",
          "score": 10,
          "dominated": true
        },
        {
          "id": "strategy-2",
          "label": "Strategy 2",
          "capitalInvested": "100",
          "beforeTaxNpv": "40",
          "afterTaxNpv": "30",
          "afterTaxIrr": 0.2999999999999903,
          "irrState": "available",
          "afterTaxEquityMultiple": "1.3",
          "afterTaxNetCash": "30",
          "score": 30,
          "dominated": false
        }
      ],
      "ranking": [
        "strategy-2",
        "strategy-1"
      ],
      "frontier": [
        "strategy-2"
      ]
    }
  },
  "formulaVersion": "compare-strategies-2.0.0",
  "units": {
    "capitalInvested": "USD",
    "beforeTaxFlows": "dated signed USD",
    "afterTaxFlows": "dated signed USD",
    "discountRatePct": "annual percent",
    "weights": "relative nonnegative weights; at least one positive",
    "afterTaxIrr": "fractional annual rate",
    "afterTaxEquityMultiple": "times invested cash"
  },
  "assumptions": [
    "Compares caller-supplied before- and after-tax dated flows for two to eight alternatives over a common horizon of up to 50 years. Optional weights control the balanced objective. Position determines the anonymous strategy ID."
  ],
  "warnings": [],
  "creditCost": 20
}

Request contract

Accepted inputs

Fields for this example. Expand the schema for all supported combinations and limits.

FieldType, units and limits

horizonStartRequired
string

Gregorian calendar date, YYYY-MM-DD.

Format: date · Min length 10 · Max length 10
horizonEndRequired
string

Gregorian calendar date, YYYY-MM-DD.

Format: date · Min length 10 · Max length 10
discountRatePctRequired
number

Annual discount rate for net present value, in percent (8 means 8%).

Min -50 · Max 100
objectiveRequired
stringAllowed: "npv", "irr", "equity-multiple", "balanced"
dayCountOptional
stringAllowed: "ACT/365F", "ACT/360", "30/360US", "ACT/ACT-ISDA"
weightsOptional
object
weights.npvRequired
number

Nonnegative unitless weight on normalized after-tax NPV in the balanced objective.

Min 0 · Max 100
weights.irrRequired
number

Nonnegative unitless weight on normalized after-tax IRR in the balanced objective.

Min 0 · Max 100
weights.equityMultipleRequired
number

Nonnegative unitless weight on normalized after-tax equity multiple in the balanced objective.

Min 0 · Max 100
strategiesRequired
arrayMin items 2 · Max items 8
strategies[].capitalInvestedRequired
number

Capital invested in the strategy, in USD.

Min 0 · Max 1000000000
strategies[].beforeTaxFlowsRequired
arrayMin items 1 · Max items 64
strategies[].beforeTaxFlows[].dateRequired
string

Gregorian calendar date, YYYY-MM-DD.

Format: date · Min length 10 · Max length 10
strategies[].beforeTaxFlows[].amountRequired
number

Before-tax cash at the associated date, in signed USD. Positive amounts are receipts.

Min -1000000000 · Max 1000000000
strategies[].afterTaxFlowsRequired
arrayMin items 1 · Max items 64
strategies[].afterTaxFlows[].dateRequired
string

Gregorian calendar date, YYYY-MM-DD.

Format: date · Min length 10 · Max length 10
strategies[].afterTaxFlows[].amountRequired
number

Cash after caller-modeled taxes at the associated date, in signed USD. Positive amounts are receipts.

Min -1000000000 · Max 1000000000
Example request body (JSON)
{
  "horizonStart": "2025-01-01",
  "horizonEnd": "2026-01-01",
  "discountRatePct": 0,
  "objective": "npv",
  "strategies": [
    {
      "capitalInvested": 100,
      "beforeTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 120
        }
      ],
      "afterTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 110
        }
      ]
    },
    {
      "capitalInvested": 100,
      "beforeTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 140
        }
      ],
      "afterTaxFlows": [
        {
          "date": "2025-01-01",
          "amount": -100
        },
        {
          "date": "2026-01-01",
          "amount": 130
        }
      ]
    }
  ]
}
Full JSON schema
{
  "type": "object",
  "properties": {
    "horizonStart": {
      "type": "string",
      "format": "date",
      "minLength": 10,
      "maxLength": 10,
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
      "description": "Gregorian calendar date, YYYY-MM-DD."
    },
    "horizonEnd": {
      "type": "string",
      "format": "date",
      "minLength": 10,
      "maxLength": 10,
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
      "description": "Gregorian calendar date, YYYY-MM-DD."
    },
    "discountRatePct": {
      "type": "number",
      "minimum": -50,
      "maximum": 100,
      "description": "Annual discount rate for net present value, in percent (8 means 8%)."
    },
    "objective": {
      "enum": [
        "npv",
        "irr",
        "equity-multiple",
        "balanced"
      ]
    },
    "dayCount": {
      "enum": [
        "ACT/365F",
        "ACT/360",
        "30/360US",
        "ACT/ACT-ISDA"
      ]
    },
    "weights": {
      "type": "object",
      "properties": {
        "npv": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Nonnegative unitless weight on normalized after-tax NPV in the balanced objective."
        },
        "irr": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Nonnegative unitless weight on normalized after-tax IRR in the balanced objective."
        },
        "equityMultiple": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Nonnegative unitless weight on normalized after-tax equity multiple in the balanced objective."
        }
      },
      "required": [
        "npv",
        "irr",
        "equityMultiple"
      ],
      "additionalProperties": false
    },
    "strategies": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "capitalInvested": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000,
            "description": "Capital invested in the strategy, in USD."
          },
          "beforeTaxFlows": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string",
                  "format": "date",
                  "minLength": 10,
                  "maxLength": 10,
                  "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                  "description": "Gregorian calendar date, YYYY-MM-DD."
                },
                "amount": {
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000,
                  "description": "Before-tax cash at the associated date, in signed USD. Positive amounts are receipts."
                }
              },
              "required": [
                "date",
                "amount"
              ],
              "additionalProperties": false
            },
            "minItems": 1,
            "maxItems": 64
          },
          "afterTaxFlows": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string",
                  "format": "date",
                  "minLength": 10,
                  "maxLength": 10,
                  "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                  "description": "Gregorian calendar date, YYYY-MM-DD."
                },
                "amount": {
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000,
                  "description": "Cash after caller-modeled taxes at the associated date, in signed USD. Positive amounts are receipts."
                }
              },
              "required": [
                "date",
                "amount"
              ],
              "additionalProperties": false
            },
            "minItems": 1,
            "maxItems": 64
          }
        },
        "required": [
          "capitalInvested",
          "beforeTaxFlows",
          "afterTaxFlows"
        ],
        "additionalProperties": false
      },
      "minItems": 2,
      "maxItems": 8
    }
  },
  "required": [
    "horizonStart",
    "horizonEnd",
    "discountRatePct",
    "objective",
    "strategies"
  ],
  "additionalProperties": false,
  "description": "Compares caller-supplied before- and after-tax dated flows for two to eight alternatives over a common horizon of up to 50 years. Optional weights control the balanced objective. Position determines the anonymous strategy ID."
}

Production endpoint: POST https://calc.hasstechapi.com/v2/calc/investor-compare-cash-ledgers
Formula: compare-strategies-2.0.0