Ratios, Proportions, Rates, and Percentages
Install and import#
npm install fintech-algorithmsimport { ratiosProportionsRatesAndPercentages } from "fintech-algorithms/foundations/mathematical-language-and-quantitative-reasoning/ratios-proportions-rates-and-percentages";Signature#
ratiosProportionsRatesAndPercentages(input)Turns a part-and-whole pair into a ratio and a percentage, and turns the same part spread over an elapsed span into a rate per period.
Parameters#
| Name | Type | Notes |
|---|---|---|
input | D00Input | A plain object. Every F01 topic first reads values, which must be a non-empty array of finite numbers, and validates it before any per-topic branch runs. This topic then reads part, whole and elapsed, each coerced with Number; values is demanded but not used by this calculation. |
Returns#
{ ratio: number; percentage: number; ratePerPeriod: number }
ratio is part / whole, percentage is that ratio times 100, and ratePerPeriod is part / elapsed.
Errors#
- When input is not a plain object — throws TypeError
- When values is missing, empty, or not an array — throws RangeError
- When values contains a value that is not a finite number — throws RangeError
- When whole is zero, or elapsed is zero or negative — throws RangeError
Complexity: time O(n),
space O(n).
Worked example#
verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.
Input#
{
"values": [1, 2, 3, 4, 5],
"startingCash": 1000,
"inflows": 250,
"outflows": 120,
"slope": 2,
"intercept": 1,
"part": 25,
"whole": 200,
"elapsed": 5,
"old": 4.5,
"new": 4.75,
"base": 16,
"exponent": 0.5,
"a": 2
}Showing 14 of 28 fields.
Call#
ratiosProportionsRatesAndPercentages(input)Returns#
object with 2 fields: ratio, percentage
{
"ratio": 0.125,
"percentage": 12.5
}Diagrams#
Calculation flow#
Ratios, Proportions, Rates, and Percentages — four-part map
flowchart LR
A["Name the input"] --> B["Apply: expense share = expenses / revenue; cost per customer = expenses / customers"]
B --> C["Check units and boundary"]
C --> D["Explain the output"]
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- NIST/SEMATECH e-Handbook of Statistical Methods — NIST/SEMATECH
- Author-derived and synthetic boundary