Standard Deviation Channel

Calculate the Standard Deviation Channel: a least-squares line through the prices with bands a number of standard deviations above and below it.

The line runs through all prices of the Toolkit’s date range, or the last window of them.

The channel shows the trend of the whole period and how far the prices stray from it: a price near an outer band lies far from the trend of the period. It is the thinkorswim study StDevAll, which draws the regression line of all bars (InertiaAll) with bands at 1, 2 and 3 standard deviations.

The formula is as follows, with time \(x = 0\), …, n - 1 over the n prices of the period:

\[\text{Linear Regression} = b_{0} + b_{1} \cdot x,\;\; \text{the least-squares line through the prices}\] \[\text{Upper Band}\; k = \text{Linear Regression} + k \cdot \operatorname{StdDev}(\text{Close})\] \[\text{Lower Band}\; k = \text{Linear Regression} - k \cdot \operatorname{StdDev}(\text{Close})\]

with the sample standard deviation (ddof=1) of the prices of the period.

Also known as: standard deviation channel, StDevAll, linear regression channel, regression bands.

Example · AAPL, MSFT · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_standard_deviation_channel:

from financetoolkit import Toolkit

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

toolkit.technicals.get_standard_deviation_channel(num_std_dev=[1, 2]).xs("AAPL", level=1, axis="columns")

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

Where did Apple trade within its standard deviation channel, one and two standard deviations around a linear regression, in 2025?

Which returns:

Parameters

get_standard_deviation_channel accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe time period to consider for historical data. Options are: “intraday” (intraday prices), “daily” (daily prices), “weekly” (weekly prices), “monthly” (monthly prices), “quarterly” (quarterly prices), “yearly” (yearly prices). Defaults to “daily”."weekly"
close_columnstrThe column name for closing prices in the historical data. Defaults to “Adj Close”."Close"
windowint | NoneThe number of latest periods the line is fitted over, at least 2. Defaults to None, which uses every period of the Toolkit’s date range.20
num_std_devfloat | list[float] | NoneThe number or numbers of standard deviations of the bands. Defaults to None, which uses 1, 2 and 3.3
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 Standard Deviation Channel. 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
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper thinkorswim (TD Ameritrade). thinkScript studies StDevAll and InertiaAll.
  • Library Referenced against pandas-ta-classic’s tos_stdevall
Share