# Loan Calculator

## /loan-calculator

This endpoint calculates the monthly payment for a loan based on the provided loan amount, annual interest rate, and duration in years. It accepts a POST request with form data including the `loanAmount`, `annualInterestRate`, and `durationYears`. If any of the provided values are not valid numeric values, it returns a 400 error with a corresponding message. If the calculation results in a valid monthly payment, it returns the monthly payment rounded to 2 decimal places. If the calculation is invalid, it returns a 400 error with a corresponding message.

**Headers**:

* `Content-Type`: `application/x-www-form-urlencoded`

**Request Body (loanAmount, annualInterestRate, durationYears)**

Form Data:

* `loanAmount`: The amount of the loan.
* `annualInterestRate`: The annual interest rate (in percentage).
* `durationYears`: The duration of the loan in years.

**Example**:

```plaintext
loanAmount: 10000
annualInterestRate: 5
durationYears: 3
```

**Response**\
Upon successful calculation, the endpoint responds with the monthly payment amount.

**Example**:

```json
{
    "monthlyPayment": "299.71"
}
```

**Error Responses**

* **Status Code: 400 Bad Request**

  **Body**: `"Please provide valid numeric values for loan amount, interest rate, and duration."`

  **Description**: Occurs if any of the parameters are missing or not a valid number.
* **Status Code: 400 Bad Request**

  **Body**: `"Invalid calculation. Please check the input values."`

  **Description**: Occurs if the calculation cannot be completed due to invalid input values, such as an interest rate of 0% over a 0 year duration, which are not mathematically viable for the formula.

This endpoint allows for a quick calculation of the monthly payments required for a loan based on the principal amount, the interest rate, and the loan duration. The calculation assumes that payments are made monthly and that the interest is compounded monthly as well.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ziomark.xyz/post-endpoints/loan-calculator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
