Calculate the streak every series is on: whether its latest value is positive, negative or zero, since when it has been without a break and how long that is, the run before it, and the longest earlier run of the same sign.

Where get_level_significance measures how unusual the latest level is, this measures how long a series has been on one side of zero, which is the question for inflation, growth and spreads: producer prices that fell year over year for 41 months in a row, a spread between two series that turned positive after three years, or a yield curve that has been inverted since a given month. With column=”Return” it measures the changes instead: a price that rose for eight days in a row, or with Econometrics(data=..., changes="difference") an unemployment rate that rose for six months in a row. Through the Toolkit it measures the prices of the tickers; with Econometrics(data=...) any series, such as the economic calendar of Economics with as_series=True, its inflation rates or the yield curves of FixedIncome.

A run is a stretch of consecutive observations with the same sign (positive, negative or zero), counted in observations: months for a monthly series. The current run is the one the latest observation belongs to, the previous run the one just before it and the longest earlier run the longest run of the current sign before the current one (the most recent of them when several are as long).

Also known as: streak, run length, consecutive months, months in a row, how long has it been negative, first positive since.

Streaks in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_streaks as shown below.

from financetoolkit import Economics, Econometrics

economics = Economics(api_key="FINANCIAL_MODELING_PREP_KEY")

prices = economics.get_economic_calendar(
    start_date="2021-06-01",
    end_date="2026-11-09",
    countries="China",
    events="Producer Price Index YoY,Inflation Rate YoY",
    impact="All",
    as_series=True,
)

econometrics = Econometrics(
    data=prices["China"][["Producer Price Index YoY", "Inflation Rate YoY"]]
)

econometrics.get_streaks(period="monthly").T

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

How long have China's producer price inflation and consumer price inflation been positive or negative in a row, by month, from June 2021 to October 2026?

Which returns:

  Producer Price Index YoY Inflation Rate YoY
Start Date 2021-05 2021-05
Observations 66 66
Latest Date 2026-10 2026-10
Latest Value 0.057 0.007
Sign Positive Positive
Run Start 2026-03 2025-10
Run Length 8 13
Previous Sign Negative Negative
Previous Run Start 2022-10 2025-08
Previous Run End 2026-02 2025-09
Previous Run Length 41 2
Longest Earlier Run Start 2021-05 2021-05
Longest Earlier Run End 2022-09 2023-05
Longest Earlier Run Length 17 25

Using Your Own Data

get_streaks runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:

from financetoolkit import Economics, Econometrics

economics = Economics(start_date="2000-01-01")

unemployment = economics.get_unemployment_rate(
    countries=["United States", "Germany"], period="monthly"
)

econometrics = Econometrics(data=unemployment, changes="difference")

econometrics.get_streaks()

Parameters

get_streaks accepts the following parameters.

ParameterTypeDescriptionExample
periodstr | NoneThe data frequency (daily, weekly, monthly, quarterly, or yearly); the weekly to yearly periods take the last value of each period. Defaults to None, which is “daily”: the series at the dates they are observed, so a monthly series is counted month by month."weekly"
columnstrThe historical data column to measure. Defaults to “Close”, the traded close of the tickers and the series themselves with data=; “Return” measures their changes."Return"
spread_overstr | NoneThe name of a series to subtract from every other series, so the streaks of the spreads over it are measured instead (named “ - "), e.g. producer price inflation over consumer price inflation. The spread exists on the dates both series have, so with period="daily" a weekly series minus a daily one is measured on the weekly dates. Defaults to None, which measures the series themselves.None, which measures the series themselves
ratioboolWhether to divide every other series by the spread_over series instead of subtracting it (named “ / "). Defaults to False.False
levelfloat | NoneThe level the runs are measured against, so the runs are above or below it (“27 years below 2%”) with the signs “Above Level”, “Below Level” and “At Level”. Defaults to None, which is zero: the sign of the values."general"
include_benchmarkboolWhether to include “Benchmark” among the assets. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the class (4 unless set otherwise).2
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
Share