Calculate the Stochastic Oscillator indicator for a given price series.

The Stochastic Oscillator is a momentum indicator that shows the location of the close relative to the high-low range over a set number of periods. It consists of the %K line (fast) and the %D line (slow).

The formula is as follows:

\[\%K = 100 \cdot ((\text{Close} - \text{Lowest Low}) / (\text{Highest High} - \text{Lowest Low}))\] \[\%D = \operatorname{SMA}(\%K,\; \text{smooth\_window})\]

Also known as: stochastic oscillator, percent K, percent D.

Stochastic Oscillator in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_stochastic_oscillator as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["GBPUSD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.technicals.get_stochastic_oscillator().xs("GBPUSD", level=1, axis="columns").tail(5)

Or, after setting up the Finance Toolkit MCP, ask:

How did the stochastic oscillator %K and %D lines of the pound against the dollar move from 26 to 31 December 2025?

Which returns:

Date Stochastic %D Stochastic %K
2025-12-26 85.0072 83.2421
2025-12-28 83.9852 83.2421
2025-12-29 83.2421 83.2421
2025-12-30 79.3458 71.5532
2025-12-31 75.4495 71.5532

Parameters

get_stochastic_oscillator accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe time period to consider for historical data. Can be “intraday”, “daily”, “weekly”, “monthly”, “quarterly” or “yearly”. Defaults to “daily”."weekly"
close_columnstrThe column name for closing prices in the historical data. Defaults to “Adj Close”, in which case the open, high and low prices are adjusted for dividends in the same way."Close"
windowintThe number of periods to consider for the %K line calculation. Defaults to 14.20
smooth_windowintThe number of periods used to smooth the %K line into the %D signal line. Defaults to 3.5
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the %K and %D values. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
Share