# Double Exponential Moving Average (DEMA)

> Reduced Lag and Overshoot

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

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

## Signature

```ts
calculateDemaComponents(values, span)
```

Double exponential moving average: `2 × EMA − EMA(EMA)`. Subtracting the second smoothing pass cancels most of the lag a single EMA introduces, at the cost of overshooting sharp reversals.

## Parameters

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

## Returns

`{ ema1, ema2, dema }[]` · length same-as-input

One record per position carrying both intermediate EMAs alongside the result, so the cancellation can be checked rather than taken on trust.

## Warm-up

The first `2 × (span − 1)` positions are `null`. Both passes must fill before the difference is defined.

## Errors

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

## Complexity

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

## 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]
```

Showing 6 of 8 elements.

`span`:

```json
3
```

### Call

```ts
calculateDemaComponents(values, span)
```

### Returns

object with 4 fields: 4, 5, 6, 7

```json
{
  "4": {
    "dema": 14.444444444444445,
    "status": "ready"
  },
  "5": {
    "dema": 17.305555555555557,
    "status": "ready"
  },
  "6": {
    "dema": 17.444444444444443,
    "status": "ready"
  },
  "7": {
    "dema": 19.618055555555557,
    "status": "ready"
  }
}
```

## Other exports

`calculateDema`, `demaSteadyStateWeights`. 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/dema/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/technical-indicators/trend-smoothing/dema/impl.ts
- Standalone repository: https://github.com/IslamBaraka90/Fintech-DEMA-Double-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
