Skip to main content
Glama
apetta
by apetta

compound_interest

Calculate compound interest for investments or loans with various compounding frequencies, including annual, monthly, or continuous compounding.

Instructions

Calculate compound interest with various compounding frequencies.

Formulas: Discrete: A = P(1 + r/n)^(nt) Continuous: A = Pe^(rt)

Examples:

ANNUAL COMPOUNDING: £1000 at 5% for 10 years principal=1000, rate=0.05, time=10, frequency="annual" Result: £1628.89

MONTHLY COMPOUNDING: £1000 at 5% for 10 years principal=1000, rate=0.05, time=10, frequency="monthly" Result: £1647.01

CONTINUOUS COMPOUNDING: £1000 at 5% for 10 years principal=1000, rate=0.05, time=10, frequency="continuous" Result: £1648.72

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextNoOptional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification.
output_modeNoOutput format: full (default), compact, minimal, value, or final. See batch_execute tool for details.full
principalYesInitial principal amount (e.g., 1000)
rateYesAnnual interest rate (e.g., 0.05 for 5%)
timeYesTime period in years (e.g., 10)
frequencyNoCompounding frequencyannual

Implementation Reference

  • The main handler function implementing compound interest calculation using discrete or continuous compounding formulas based on principal, rate, time, and frequency.
    async def compound_interest( principal: Annotated[float, Field(description="Initial principal amount (e.g., 1000)")], rate: Annotated[float, Field(description="Annual interest rate (e.g., 0.05 for 5%)")], time: Annotated[float, Field(description="Time period in years (e.g., 10)", ge=0)], frequency: Annotated[ Literal["annual", "semi-annual", "quarterly", "monthly", "daily", "continuous"], Field(description="Compounding frequency"), ] = "annual", ) -> str: """Calculate compound interest.""" try: freq_map = { "annual": 1, "semi-annual": 2, "quarterly": 4, "monthly": 12, "daily": 365, } if frequency == "continuous": # Continuous compounding: A = Pe^(rt) final_amount = principal * math.exp(rate * time) else: # Discrete compounding: A = P(1 + r/n)^(nt) n = freq_map[frequency] final_amount = principal * (1 + rate / n) ** (n * time) interest_earned = final_amount - principal return format_result( float(final_amount), { "principal": principal, "rate": rate, "time": time, "frequency": frequency, "interest_earned": float(interest_earned), }, ) except Exception as e: raise ValueError(f"Compound interest calculation failed: {str(e)}")
  • The @mcp.tool decorator registering the compound_interest tool with name, description, examples, and annotations.
    @mcp.tool( name="compound_interest", description="""Calculate compound interest with various compounding frequencies. Formulas: Discrete: A = P(1 + r/n)^(nt) Continuous: A = Pe^(rt) Examples: ANNUAL COMPOUNDING: £1000 at 5% for 10 years principal=1000, rate=0.05, time=10, frequency="annual" Result: £1628.89 MONTHLY COMPOUNDING: £1000 at 5% for 10 years principal=1000, rate=0.05, time=10, frequency="monthly" Result: £1647.01 CONTINUOUS COMPOUNDING: £1000 at 5% for 10 years principal=1000, rate=0.05, time=10, frequency="continuous" Result: £1648.72""", annotations=ToolAnnotations( title="Compound Interest", readOnlyHint=True, idempotentHint=True, ), )
  • Pydantic schema definitions for the tool parameters including types, descriptions, constraints, and default value.
    principal: Annotated[float, Field(description="Initial principal amount (e.g., 1000)")], rate: Annotated[float, Field(description="Annual interest rate (e.g., 0.05 for 5%)")], time: Annotated[float, Field(description="Time period in years (e.g., 10)", ge=0)], frequency: Annotated[ Literal["annual", "semi-annual", "quarterly", "monthly", "daily", "continuous"], Field(description="Compounding frequency"), ] = "annual", ) -> str:
  • TOOL_CATEGORIES dictionary registering compound_interest under 'Financial' category for batch execution tool.
    TOOL_CATEGORIES = { "Basic": ["calculate", "percentage", "round", "convert_units"], "Arrays": ["array_operations", "array_statistics", "array_aggregate", "array_transform"], "Statistics": ["statistics", "pivot_table", "correlation"], "Financial": ["financial_calcs", "compound_interest", "perpetuity"], "Linear Algebra": ["matrix_operations", "solve_linear_system", "matrix_decomposition"], "Calculus": ["derivative", "integral", "limits_series"], }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/apetta/vibe-math-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server