---
title: "Calculate average balance"
method: POST
path: "/v1/accounts/{accountId}/average-balance"
tags: ["Average balance"]
---

# Calculate average balance

`POST /v1/accounts/{accountId}/average-balance`

## Request

- Base URL: `https://sandbox.pismolabs.io/savings-products`
- URL: `https://sandbox.pismolabs.io/savings-products/v1/accounts/{accountId}/average-balance`
- Auth: HTTP bearer

Calculate an average balance for an account.<br>
Using this endpoint, you specify a datetime range and calculate the [average balance](https://www.investopedia.com/terms/a/average-balance.asp) of an account for that period. The calculation multiplies each unchanged balance by the number of days it remains constant, sums those values, and divides the total by the number of days in the selected range.<br>
The `begin_date_datetime` and `end_date_datetime` values are interpreted in the account's time zone, determined in the following order: the account's division, its parent division, the program, and finally UTC when no time zone is available. Only the calendar date of each value is considered. The calculation period begins at `00:00:00 `on the start date and ends at `23:59:59` on the end date in the time zone. The period cannot exceed 366 days, and the end date must have already passed in that time zone; otherwise, the request is rejected with `HTTP 400`.
Requests for the same calendar days are treated as the same calculation, regardless of the time of day provided. If a matching calculation already exists, the request is rejected with `HTTP 409`, and the details field contains the idempotency key of the existing calculation, which can be used with the `GET` endpoint.<br>
This endpoint generates the [Average balance calculated](https://developers.pismo.io/events/docs/average-balance-calculated-average-balance-1) event once calculation is complete.

## Path parameters

- `accountId` string, required

## Headers

- `idempotency` string, required

## Request body

- CalculateAverageBalanceRequest
  - `begin_date_datetime` string, date-time: The specified datetime when the average balance calculation begins. The datetime is displayed in the RFC 3339 format; for example: `2024-01-28T10:33:01Z`.<br> The date time is converted to the account's time zone (refer to the operation description), and only the resulting calendar date is considered. The calculation starts at the beginning of that day (`00:00:00`). For example, `2024-01-28T02:00:00Z` converts to `2024-01-27` in the `America/Sao_Paulo` time zone, so the calculation begins at `2024-01-27T00:00:00-03:00`.
  - `end_date_datetime` string, date-time: The specified datetime when the average balance calculation ends. The datetime is displayed in the RFC 3339 format; for example: `2024-01-29T10:33:01Z`.<br> The date time is interpreted in the account's time zone (see the operation description), and only the calendar date is used. The calculation ends at `23:59:59` on that date. The date must have already passed in the account's time zone. The current date and future dates are rejected with `HTTP 400`.
  - `balance_types_to_calculate` string[]: Choose a balance to calculate its average balance, you can select multiple balance types to calculate their average balances simultaneously. The balance types are:<br> * `available` * `savings` * `held_funds`

## Response `202`

Accepted

- CalculateAverageBalanceResponse
  - `account_id` number: Account ID.
  - `idempotency_key` string: Idempotency key.
  - `status` 'PROCESSING' | 'COMPLETE': Status of the average balance calculation request.
  - `message` string: Message.

## Other responses

- `400`: Bad request
- `404`: Bad request
- `409`: Conflict
- `500`: Internal error

---

[API](https://skmtc.dev/pismo/apis/banking-interest-bearing-accounts.md) - [All operations](https://skmtc.dev/pismo/apis/banking-interest-bearing-accounts/llms.txt) - [OpenAPI document](https://skmtc.dev/pismo/apis/banking-interest-bearing-accounts/revisions/c68f61feb8a8?raw)
