The CAGR Calculator API allows you to compute the missing value among Initial Value, Final Value, Number of Years, and CAGR (%), provided the other three are given. It is available at:
POST https://www.promptbox.cn/api/cagr.php
The API accepts a POST request with a JSON body containing
any 3 of the following 4 fields. The missing one will be calculated.
| Field | Type | Description |
|---|---|---|
initial |
number | Initial value (e.g., investment start amount). |
final |
number | Final value (e.g., investment end amount). |
years |
number | Number of years. |
cagr |
number | Compound Annual Growth Rate in percent (e.g., 12.5). |
Note: Exactly 3 fields must be provided. The API will calculate the 4th.
{
"initial": 1000,
"final": 2000,
"years": 5
}
The API responds with a JSON object containing all 4 fields, including the calculated one.
| Field | Type | Description |
|---|---|---|
initial |
number | Initial value (supplied or computed). |
final |
number | Final value (supplied or computed). |
years |
number | Number of years (supplied or computed, rounded to 2 decimals). |
cagr |
number | CAGR (%) (supplied or computed, rounded to 2 decimals). |
{
"initial": 1000,
"final": 2000,
"years": 5,
"cagr": 14.87
}
If the request is invalid, the API will return an error JSON object with an explanatory message.
| Status Code | Description | Example |
|---|---|---|
| 400 | Invalid input (e.g., not exactly 3 fields, or non-positive values). | {
"error": "Please provide exactly 3 fields to calculate the missing one."
} |
| 405 | Invalid HTTP method (only POST is allowed). | {
"error": "Only POST method is allowed."
} |
cagr is expressed in percent, not decimal (e.g., 12.5 means 12.5%).