Need to calculate compound interest in your application? This guide covers everything you need to know about compound interest calculations via API, including the formula, compounding frequencies, and implementation examples in multiple languages.
What is Compound Interest?
Compound interest is interest calculated on both the initial principal and the accumulated interest from previous periods. Unlike simple interest, compound interest grows exponentially over time, making it a powerful concept for investments and savings.
Albert Einstein reportedly called compound interest "the eighth wonder of the world." It's the foundation of long-term wealth building and is essential for any financial application.
The Compound Interest Formula
The compound interest formula is:
A = P(1 + r/n)^(nt)
Where:
A = Final amount
P = Principal (initial investment)
r = Annual interest rate (decimal)
n = Number of times interest compounds per year
t = Time in years
Compounding Frequencies
Interest can compound at different intervals:
- Annually (n=1): Once per year
- Semi-annually (n=2): Twice per year
- Quarterly (n=4): Four times per year
- Monthly (n=12): Twelve times per year
- Daily (n=365): Every day
Using the Compound Interest API
TinyFn provides a simple endpoint to calculate compound interest:
GET https://api.tinyfn.io/v1/math/compound-interest
Headers: X-API-Key: your-api-key
{
"principal": 10000,
"rate": 0.05,
"time": 10,
"compound_frequency": 12,
"final_amount": 16470.09,
"total_interest": 6470.09
}
Parameters
| Parameter | Type | Description |
|---|---|---|
principal |
number | Initial investment amount |
rate |
number | Annual interest rate (e.g., 0.05 for 5%) |
time |
number | Time period in years |
compound_frequency |
integer | Times interest compounds per year (default: 12) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/math/compound-interest?principal=10000&rate=0.05&time=10&compound_frequency=12',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.final_amount); // 16470.09
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/math/compound-interest',
params={
'principal': 10000,
'rate': 0.05,
'time': 10,
'compound_frequency': 12
},
headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['final_amount']) # 16470.09
cURL
curl "https://api.tinyfn.io/v1/math/compound-interest?principal=10000&rate=0.05&time=10&compound_frequency=12" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Investment Calculators: Project future value of investments
- Retirement Planning: Calculate retirement savings growth
- Savings Goals: Determine how long to reach a savings target
- Loan Comparisons: Compare different investment options
- Financial Education: Teach users about compound interest
Best Practices
- Use appropriate precision: Financial calculations require proper decimal handling
- Consider inflation: Adjust for inflation in long-term projections
- Show breakdowns: Display yearly or monthly breakdowns for transparency
- Validate inputs: Ensure positive values for principal, rate, and time
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-math": {
"url": "https://api.tinyfn.io/mcp/math/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all math tools available via MCP in our Math MCP Tools for AI Agents guide.
Try the Compound Interest Calculator API
Get your free API key and start calculating investment growth in seconds.
Get Free API Key