Vertical Horizontal Filter (VHF)

Calculate the Vertical Horizontal Filter (VHF): the range of a window as a share of the path travelled, which shows whether prices trend or move sideways.

The Vertical Horizontal Filter tells a trending market from a congested one by dividing the range of the closes over the window (the vertical move) by the sum of the absolute changes from period to period (the path, horizontal in a range). A high or rising VHF says the price moves in one direction, which suits trend-following indicators; a low or falling VHF says it moves back and forth, which suits oscillators.

The formula is as follows:

\[\text{VHF} = \frac{\max(\text{Close},\; \text{window}) - \min(\text{Close},\; \text{window})}{\operatorname{Sum}(\left|\operatorname{Close}(i) - \operatorname{Close}(i - 1)\right|,\; \text{window})}\]

Also known as: VHF, vertical horizontal filter.

Example · AAPL, MSFT · 2021 to 2025

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

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_vertical_horizontal_filter()

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

Were Apple and Microsoft trending or moving sideways in 2025, according to the Vertical Horizontal Filter?

Which returns:

Parameters

get_vertical_horizontal_filter 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"
windowintThe number of periods of the range and the path. Defaults to 28.20
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 indicator 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
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 White, A. (1991). “Trending or Trading? The Vertical Horizontal Filter.” Futures Magazine.
  • Library Referenced against TA-Lib’s VHF
Share