# Bollinger Bands

`D07-F04-A03` · Technical Indicators → Volatility and Channels · archetype `series-transform` · difficulty 2/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/technical-indicators/volatility-and-channels/bollinger-bands/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { bollingerBands } from "fintech-algorithms/technical-indicators/volatility-and-channels/bollinger-bands";
```

## Signature

```ts
bollingerBands(close, p, multiplier)
```

A moving average with bands a number of standard deviations away, so the channel widens and narrows with realised volatility.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `close` | `number[]` | yes | Per-bar closing prices, chronological. |
| `p` | `number` | yes | Lookback for both the average and the standard deviation. · min: 1, integer: true |
| `multiplier` | `number` | yes | Number of standard deviations from the middle band to each outer band. · min: 0 |

## Returns

`Record<string, (number | null)[]>` · length same-as-input

Parallel series: `middle`, `stddev`, `upper`, `lower`, and `percent_b` — where price sits within the channel, 0 at the lower band and 1 at the upper.

## Warm-up

The first `p − 1` positions are `null`.

## Errors

- When p < 1, is not an integer, or multiplier is negative — throws RangeError

## Complexity

Time `O(n × p)`, space `O(n)`.

## Worked example

Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

### Input

`close`:

```json
[100, 100.54129063, 101.06589044, 101.55765885, 102.00153762, 102.3840473]
```

Showing 6 of 240 elements.

`p`:

```json
20
```

`multiplier`:

```json
2
```

### Call

```ts
bollingerBands(close, p, multiplier)
```

### Returns

object with 5 fields: middle, stddev, upper, lower, percent_b

```json
{
  "middle": [null, null, null, null, null, null],
  "stddev": [null, null, null, null, null, null],
  "upper": [null, null, null, null, null, null],
  "lower": [null, null, null, null, null, null],
  "percent_b": [null, null, null, null, null, null]
}
```

## Verification and provenance

Tier: **verified** (via scenario-fixture).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/technical-indicators/volatility-and-channels/bollinger-bands/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/technical-indicators/volatility-and-channels/bollinger-bands/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/technical-indicators/llms.txt
