Internal Rate of Return
finance.irr
Overview
You send cashflows numbered by period; we search for the rate whose net present value is zero, using halving over the fixed range -0.999999 to 10 so the same series always gives the same rate. When a series has more than one sign change it may have several real answers, and we say so instead of picking one: you get converged false and a reason rather than a number nobody can defend. Discounting is shared with finance.npv, so both skills agree on what a rate means.
Spreadsheet rate functions start from a guess, so two people with the same cashflows can get two different rates and neither can prove which is right. We fix the range, halve it in exact decimals, and tell you when your series simply does not have one answer.
Reliability
Same series, same rate, every time: the range is fixed at -0.999999 to 10, the step count is capped, and your guess is deliberately ignored. A refusal is reported as converged false with a reason, so you can tell "no single answer" apart from "something went wrong". The three refusals are answers, not errors: they come back as a successful call with converged false, and irr and residualNpv are both absent, so nothing can be misread as a rate of zero. What the fixed range costs you is explicit: a series whose true rate exceeds 1000 percent per period, or sits at or below -99.9999 percent, is reported NO_ROOT_IN_BRACKET — we do not widen the range to find it, because a reproducible range matters more than reaching a rate no lender would write. A tolerance so loose that the range closes before the value does still converges, and residualNpv is how you see it: that is the number to check, not converged alone. IRR_CASHFLOWS_INVALID — trigger: fewer than two cashflows, two entries claiming the same period, an amount we cannot read or one beyond the 1E18 cap, or an entry with a property we do not define; retryable: no, the same payload always fails; next: check the position we name in the details, one entry per period, amounts as plain decimal strings. IRR_SIGNS_UNIFORM — trigger: every amount points the same way, so no rate can bring the series to zero; retryable: no; next: include the outlay as a negative amount and the receipts as positive ones. IRR_TOLERANCE_INVALID — trigger: a tolerance we cannot read, or one outside 0.000000000000001 to 0.000001; retryable: no; next: send a plain decimal in that range, or leave it out for 0.000000000001. NPV_CASHFLOW_LIMIT_EXCEEDED — trigger: more than 1,200 cashflows in one call, whether you overshoot by one entry or by a thousand; retryable: no; next: aggregate the series into fewer periods, since a rate over thousands of periods is dominated by the first few anyway.
Context footprint
Returns one rate and a short account of how it was reached, with no per-period rows. A successful call costs 1 execution credit.
When to use it
When your series goes out once and comes back over later periods, and you want a rate you can reproduce.
When the series changes direction more than once, or when you already know the rate and want a value instead.
Scope
Non-goals
- Does not pick one answer when a series has several real ones
- Does not use your starting guess, so it cannot drift to a different root
- Does not convert dates to periods or handle several currencies
- Does not compare the result against a hurdle rate for you
Properties
Capabilities
Cost & billing
Flat rate per invocation
File handling
How we handle your data
What this means
This skill may receive sensitive content, but it does not target sensitive data and returns only a structured non-sensitive result.
Squillify guarantees
- Runs inside Squillify
- This skill runs inside Squillify.
- Payloads are not sent to an external service by this skill.
- Squillify does not permanently store submitted payloads.
- Telemetry records metadata only, not submitted content.
- Submitted payloads are not used for training.
- Submitted payloads are not reviewed by humans.
- This skill does not target sensitive data.
- The response does not contain submitted content.
Your responsibility
Squillify does not determine whether submitted content is sensitive. Your application is responsible for deciding what data it is allowed to submit. Your application is responsible for securing the response.
Input schema
| Field | Type | Required | Description |
|---|---|---|---|
| cashflows | array | Yes | From 2 through 1,200 closed cashflows with unique periods and at least one negative and one positive amount. |
| guess | object | No | Optional starting rate greater than -1, read then ignored because the search range is fixed; omit it for the same search. |
| tolerance | object | No | Optional rate precision from 1e-15 through 1e-6; omit it for 0.000000000001. |
| maxIterations | integer | No | Optional cap on halving steps from 1 through 500; omit it for 200. |
Output schema
| Field | Type | Required | Description |
|---|---|---|---|
| irr | string | No | Per-period rate as a decimal such as 0.25 for 25 percent; omitted when converged is false so a refusal cannot read as zero. |
| converged | boolean | Yes | True when a single rate was found inside the range at the requested precision; false is a successful refusal. |
| reasonCode | string | Yes | Why the search ended. |
| iterations | integer | Yes | How many halving steps were taken, or 0 when the series was refused before searching. |
| residualNpv | string | No | Net present value left at the reported rate to 12 places; present exactly when irr is present. |
| bracket | object | Yes | Fixed search range as low and high decimal strings, published because rates outside it are never sought. |
| tolerance | string | Yes | Rate precision the search actually ran to, filled in with the default when you left it out. |
| signChanges | integer | Yes | How many times the series changes direction when ordered by period. |
API contract
POST /v1/executecurl -sS -X POST "$BASE/v1/execute" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"skillKey":"finance.irr","input":{"cashflows":[{"period":0,"amount":"-1000.00"},{"period":1,"amount":"500.00"},{"period":2,"amount":"500.00"},{"period":3,"amount":"500.00"}]}}'import { Squillify } from "@squillify/sdk";
const sq = new Squillify({ apiKey: process.env.SQUILLIFY_API_KEY });
const { output } = await sq.execute("finance.irr", {"cashflows":[{"period":0,"amount":"-1000.00"},{"period":1,"amount":"500.00"},{"period":2,"amount":"500.00"},{"period":3,"amount":"500.00"}]});Errors
| Code | HTTP | Retryable | Description |
|---|---|---|---|
| VALIDATION_ERROR | 400 | No | The request payload failed schema validation. |
| UNAUTHORIZED | 401 | No | Missing or invalid API key. |
| SKILL_NOT_ACCESSIBLE | 403 | No | The API key is not granted access to this skill. |
| SKILL_NOT_AVAILABLE_FOR_PLAN | 403 | No | This skill is not included in your current plan. |
| PLAN_ELIGIBILITY_UNAVAILABLE | 503 | Yes | Plan eligibility could not be decided. Retry after backoff. |
| SKILL_NOT_FOUND | 404 | No | The requested skill or version does not exist. |
| TENANT_RATE_LIMITED | 429 | Yes | Request rate limit exceeded. Retry after backoff. |
| QUOTA_EXCEEDED | 429 | Yes | Plan quota exhausted. Retryable once the quota period resets. |
| EXECUTION_TIMEOUT | 504 | Yes | Execution exceeded the allowed time budget. |
| IRR_CASHFLOWS_INVALID | 400 | No | The request payload failed this skill's input validation. |
| IRR_SIGNS_UNIFORM | 400 | No | The request payload failed this skill's input validation. |
| IRR_TOLERANCE_INVALID | 400 | No | The request payload failed this skill's input validation. |
| NPV_CASHFLOW_LIMIT_EXCEEDED | 429 | No | A size, quota, rate, or time limit was exceeded. |
Other limits
| Limit | Value |
|---|---|
| Recommended inline bytes | 32 KiB |
Limitations
- Does not pick one answer when a series has several real ones
- Does not use your starting guess, so it cannot drift to a different root
- Does not convert dates to periods or handle several currencies
- Does not compare the result against a hurdle rate for you
- Series that swing between paying out and paying in repeatedly
- Cashflows still expressed as calendar dates
- Comparing projects of different sizes, where the rate flatters the smaller one
How to call
POST /v1/execute (requires authentication)
{
"skillKey": "finance.irr",
"input": {
"cashflows": [
{
"period": 0,
"amount": "-1000.00"
},
{
"period": 1,
"amount": "500.00"
},
{
"period": 2,
"amount": "500.00"
},
{
"period": 3,
"amount": "500.00"
}
]
}
}Examples
One outlay and three equal receipts
{
"cashflows": [
{
"period": 0,
"amount": "-1000.00"
},
{
"period": 1,
"amount": "500.00"
},
{
"period": 2,
"amount": "500.00"
},
{
"period": 3,
"amount": "500.00"
}
]
}{
"bracket": {
"low": "-0.999999",
"high": "10"
},
"irr": "0.233751928528",
"tolerance": "0.000000000001",
"residualNpv": "0.00000000089",
"reasonCode": "CONVERGED",
"converged": true,
"iterations": 44,
"signChanges": 1
}Two sign changes are refused rather than guessed
{
"cashflows": [
{
"period": 0,
"amount": "-100.00"
},
{
"period": 1,
"amount": "300.00"
},
{
"period": 2,
"amount": "-250.00"
}
]
}{
"signChanges": 2,
"converged": false,
"tolerance": "0.000000000001",
"bracket": {
"low": "-0.999999",
"high": "10"
},
"reasonCode": "MULTIPLE_SIGN_CHANGES",
"iterations": 0
}Recommended use cases
- Report the return on an investment with one outlay and later receipts
- Check whether a payment plan clears an agreed hurdle rate
- Reproduce a spreadsheet rate with an answer you can audit
Avoid for
- Series that swing between paying out and paying in repeatedly
- Cashflows still expressed as calendar dates
- Comparing projects of different sizes, where the rate flatters the smaller one
Related skills
Composable with
Safety & privacy
- Runs without calling any external service.
- Your payloads are never stored permanently.
- Telemetry captures metadata only — never your payload contents.
- We never train models on your payloads.
- No human reviews your payloads.