# Stochastic Oscillator

`D07-F03-A02` · Technical Indicators → Momentum · archetype `series-transform` · difficulty 2/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/technical-indicators/momentum/stochastic-oscillator/
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 { stochastic } from "fintech-algorithms/technical-indicators/momentum/stochastic-oscillator";
```

## Signature

```ts
stochastic(high, low, close, kp, sk, sd)
```

Where the close sits within the high–low range of the lookback, expressed as 0–100, then smoothed twice.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `high` | `number[]` | yes | Per-bar high prices, chronological. |
| `low` | `number[]` | yes | Per-bar low prices, chronological. |
| `close` | `number[]` | yes | Per-bar closing prices, chronological. |
| `kp` | `number` | yes | %K lookback: the window over which the high–low range is measured. · min: 1, integer: true |
| `sk` | `number` | yes | Smoothing applied to raw %K to produce slow %K. · min: 1, integer: true |
| `sd` | `number` | yes | Smoothing applied to slow %K to produce %D. · min: 1, integer: true |

## Returns

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

Parallel series: `fast_k`, `slow_k` and `slow_d`.

## Warm-up

The first `kp − 1 for fast %K, then sk − 1 and sd − 1 more for each smoothing stage` positions are `null`.

## Errors

- When any period is < 1 or is not an integer — throws RangeError
- When the input series are not all the same length — throws RangeError

## Complexity

Time `O(n × kp)`, 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

`high`:

```json
[101, 101.992465, 103.28276, 104.655405, 105.856544, 106.661472]
```

Showing 6 of 120 elements.

`low`:

```json
[99.08, 99.149664, 100.233798, 101.654978, 103.180913, 104.534685]
```

Showing 6 of 120 elements.

`close`:

```json
[100, 100.999214, 102.324548, 103.755998, 105.030823, 105.911843]
```

Showing 6 of 120 elements.

### Call

```ts
stochastic(high, low, close, kp, sk, sd)
```

### Returns

object with 3 fields: fast_k, slow_k, slow_d

```json
{
  "fast_k": [null, null, null, null, null, null],
  "slow_k": [null, null, null, null, null, null],
  "slow_d": [null, null, null, null, null, null]
}
```

## Other exports

`rsi`, `stochasticRsi`, `williamsR`, `cci`, `ultimateOscillator`, `tsi`, `connorsRsi`. 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 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/momentum/stochastic-oscillator/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/technical-indicators/momentum/stochastic-oscillator/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/technical-indicators/llms.txt
