ForHosting KIT · Math

Weighted moving average calculator

Smooth an ordered series with a sliding weight pattern: with weights 1, 2 and 1, each window covers 3 values, the middle one counts double and the sum is divided by 4. A series of 5 values gives 3 averages. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Series
10, 20, 30, 40, 50
Weights
1, 2, 1
You get
Weighted moving average
20, 30, 40
Window size
3
Windows
3
Weight sum
4

A weighted moving average smooths an ordered series while letting selected positions inside each window matter more than others. Supply the observations and one fixed array of weights, and this calculator slides that weight pattern from the beginning of the series to the end. It returns one weighted average for every complete window, together with the window size, window count, and weight sum. The calculation is deterministic, validates every number, and clearly rejects empty weights or a weight array longer than the available series.

How a weighted moving average works

A moving average turns a long ordered series into a shorter, smoother sequence by evaluating consecutive windows. In this calculator, the length of the weights array is also the window length. For each complete window, the first observation is multiplied by the first weight, the second observation by the second weight, and so on.

Those products are added and divided by the sum of all weights. The same weight pattern then moves forward by one observation and the calculation repeats. A series with five observations and three weights therefore produces three results: one for positions one through three, another for positions two through four, and a final value for positions three through five.

This alignment is important because weights are positional. Weights such as one, two, and three emphasize the newest value when observations are ordered from oldest to newest, while three, two, and one emphasize the oldest value. Equal weights reduce the method to an ordinary simple moving average over the same window length.

Only complete windows are returned; the calculator does not invent padding, repeat edge values, or emit partial results at either end of the series.

Preparing inputs and interpreting the output

Send two arrays named series and weights. The series must preserve the order in which observations occurred, because changing that order changes every window. The weights array must contain at least one finite number and cannot be longer than the series.

Its total must also be non-zero, since the weighted sum is divided by that total. Individual negative or zero weights are accepted as mathematical coefficients, although most smoothing applications use non-negative weights. The first item corresponds to the first complete window, and each following item advances the window by exactly one series position.

The output contains exactly series length minus weight length plus one averages. Floating-point calculations follow standard JavaScript number arithmetic, so applications requiring decimal accounting rules should round the returned values according to their own domain policy.

Choosing weights and using the calculator reliably

Choose weights to express how much influence each position should have, not merely to make them add to one. The calculator always divides by their sum, so proportional arrays such as one, two, one and ten, twenty, ten produce the same averages. For recent-value emphasis in an oldest-to-newest series, weights usually rise toward the right side of the array.

For centered smoothing, symmetric weights can give the middle of each window the strongest influence. Keep the window short when you want the result to react quickly, and use a longer window when suppressing short-lived variation matters more than responsiveness. Before comparing this output with another package, check its conventions: some tools reverse weight order, require normalized weights, or produce padded edge values.

This capability uses the weights exactly in the supplied left-to-right order and returns complete windows only.

Smooth recent sensor readings

Apply a short, recent-heavy weight pattern to reduce noise while retaining changes in temperature, load, or other ordered measurements.

Track operational trends

Turn daily demand, ticket volume, or throughput observations into a stable sliding indicator for dashboards and alerts.

Teach windowed statistics

Show how window size, positional weighting, and normalization change a sequence compared with a simple moving average.

What formula is used for each window?

Each result is the sum of series[start + i] times weights[i], divided by the sum of the weights.

How many results will I receive?

The output contains series length minus weights length plus one results, because only complete windows are calculated.

Does the first or last weight apply to the newest observation?

Weights are applied left to right. If your series is ordered oldest to newest, the last weight applies to the newest observation in each window.

Do the weights need to add to one?

No. The calculator divides every weighted sum by the total weight, so any proportional non-zero weight array gives the same normalized result.

What happens at the start and end of the series?

Nothing is padded or guessed. Only complete windows are averaged, so the first result belongs to the first full window and no partial averages appear at either edge of the series.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/stat/weighted-moving-average

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/stat/weighted-moving-average \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"series":[10,20,30,40,50],"weights":[1,2,1]}'
{
  "series": [
    10,
    20,
    30,
    40,
    50
  ],
  "weights": [
    1,
    2,
    1
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "stat.weighted_moving_average",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_series_items100000
max_weights10000
max_operations10000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Preparing inputs and interpreting the output

Every item is validated as a finite JSON number; missing arrays, strings, null values, NaN-like values, and infinities are rejected rather than silently converted. The response field weighted_moving_average contains the results in chronological window order. The response also includes window_size, windows, and weight_sum so callers can verify the alignment and normalization without reconstructing them.

Choosing weights and using the calculator reliably

It runs locally in the free browser experience and uses the same pure calculation through the API, where each successful item costs $0.002. No network service, model, clock, or random source participates, making repeated calls with identical JSON suitable for tests, dashboards, teaching examples, and reproducible analytical pipelines.

What inputs cause an error?

Missing or empty arrays, non-finite numbers, weights longer than the series, a zero weight sum, and calculations beyond the published bounds return invalid_input.

How much does the API cost?

Each successful API request costs $0.002. The browser calculator runs free on your device.

Read the full KIT documentation →