# Exponential Moving Average (EMA)

`D07-F01-A02` · Technical Indicators → Trend Smoothing · archetype `series-transform` · difficulty 2/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/technical-indicators/trend-smoothing/ema/
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 { calculateEma } from "fintech-algorithms/technical-indicators/trend-smoothing/ema";
```

## Signature

```ts
calculateEma(values, span)
```

Exponentially weighted mean seeded with the simple mean of the first `span` observations, so the series is reproducible rather than dependent on where the data starts.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `values` | `(number \| null)[]` | yes | Observation series in chronological order, oldest first. · nulls: propagate |
| `span` | `number` | yes | Smoothing span; the decay factor is 2 / (span + 1). · min: 1, integer: true |

## Returns

`(number | null)[]` · length same-as-input

Smoothed series, `null` until the seed window closes.

## Warm-up

The first `span - 1` positions are `null`. Warm-up positions are null rather than a partial result, so a consumer never mistakes an incomplete window for a real value.

## Errors

- When span < 1 or is not an integer — throws RangeError

## Complexity

Time `O(n)`, space `O(1)`.

## Worked example

This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

### Input

`values`:

```json
[10, 13, 12, 15, 14, 18]
```

`span`:

```json
3
```

### Call

```ts
calculateEma(values, span)
```

### Returns

array of 6 nulls

```json
[
  null,
  null,
  11.666666666666666,
  13.333333333333334,
  13.666666666666666,
  15.833333333333334
]
```

## Other exports

`alphaFromSpan`, `calculateAdjustedEma`, `calculateTimeAwareEma`. Every module additionally exports `run` as an alias of its primary
function, and a `meta` object carrying its catalog id, domain, family, shape and article URL.

## Verification and provenance

Tier: **verified** (via input-expected).

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/trend-smoothing/ema/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/technical-indicators/trend-smoothing/ema/impl.ts
- Standalone repository: https://github.com/IslamBaraka90/Fintech-EMA-Exponential-Moving-Average-algorithm
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/technical-indicators/llms.txt
