On-Balance Volume (OBV)
Calculate the On-Balance Volume (OBV) for a given price series.
The On-Balance Volume (OBV) is a technical indicator that uses volume flow to predict changes in stock price. It accumulates the volume on up days and subtracts the volume on down days. The resulting OBV line provides insights into the buying and selling pressure behind price movements.
The formula is as follows:
\[\text{OBV} = \text{Previous OBV} + \text{Current Volume if Close} > \text{Previous Close}\]Also known as: OBV, volume momentum.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the On-Balance Volume (OBV) for you. Just ask in plain English.
Calculate the On-Balance Volume (OBV) in Python
The On-Balance Volume (OBV) is available in the Technicals module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_on_balance_volume as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(tickers=["AAPL", "MSFT"])
toolkit.technicals.get_on_balance_volume()
Which returns:
| Date | AAPL | MSFT | Benchmark |
|---|---|---|---|
| 2026-06-18 | 4.50241e+09 | 3.51706e+08 | 1.39684e+09 |
| 2026-06-22 | 4.45753e+09 | 3.06535e+08 | 1.35021e+09 |
| 2026-06-23 | 4.40552e+09 | 3.47183e+08 | 1.28336e+09 |
| 2026-06-24 | 4.35243e+09 | 3.02673e+08 | 1.22592e+09 |
| 2026-06-25 | 4.24518e+09 | 2.36312e+08 | 1.28005e+09 |
| 2026-06-26 | 4.50696e+09 | 4.22514e+08 | 1.20902e+09 |
| 2026-06-29 | 4.44053e+09 | 3.71284e+08 | 1.26705e+09 |
| 2026-06-30 | 4.50563e+09 | 4.1623e+08 | 1.32268e+09 |
| 2026-07-01 | 4.55579e+09 | 4.64295e+08 | 1.27558e+09 |
| 2026-07-02 | 4.63119e+09 | 5.0649e+08 | 1.21807e+09 |
Parameters
get_on_balance_volume accepts the following parameters:
- period (str, optional): The time period to consider for historical data. Can be “daily”, “weekly”, “quarterly”, or “yearly”. Defaults to “daily”.
- close_column (str, optional): The column name for closing prices in the historical data. Defaults to “Adj Close”.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
- growth (bool, optional): Whether to calculate the growth of the OBV. Defaults to False.
- lag (int | list[int], optional): The lag to use for the growth calculation.
- standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. Defaults to 1.
Related Breadth Indicators
The Technicals module page introduces the module, and the sidebar lists all of its functions.