# Weighted Moving Average (WMA)

> Newest-Heavy Linear Smoothing

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

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

## Signature

```ts
calculateWma(values, window)
```

Linearly weighted mean over `window` observations: the most recent observation carries weight `window`, the oldest weight 1.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `values` | `(number \| null)[]` | yes | Observation series in chronological order, oldest first. · nulls: propagate |
| `window` | `number` | yes | Number of observations in the weighted mean. · min: 1, integer: true |

## Returns

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

Weighted mean per position, `null` during warm-up.

## Warm-up

The first `window - 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 window < 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]
```

`window`:

```json
3
```

### Call

```ts
calculateWma(values, window)
```

### Returns

array of 6 nulls

```json
[null, null, 12, 13.666666666666666, 14, 16.166666666666668]
```

## 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/wma/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/technical-indicators/trend-smoothing/wma/impl.ts
- Standalone repository: https://github.com/IslamBaraka90/Fintech-WMA-Weighted-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
