OpenBB-finance/OpenBB · error · ValueError

Calculation asks for at least last {window} days of data

Error message

Calculation asks for at least last {window} days of data

What it means

In the regression helper (openbb_quantitative-style log regression in openbb_technical/helpers.py), raises when len(values) < window: the trend/regression fit requires at least `window` most-recent observations and refuses to run on shorter series.

Source

Thrown at openbb_platform/extensions/technical/openbb_technical/helpers.py:510

    window: int
        Length of look back period

    Returns
    -------
    float:
        R2 of fit to log data
    float:
        Coefficient of linear regression
    Series:
        Values for best fit line
    """
    # pylint: disable=import-outside-toplevel
    from numpy import arange, exp, log
    from pandas import Series
    from sklearn.linear_model import LinearRegression

    if len(values) < window:
        raise ValueError(f"Calculation asks for at least last {window} days of data")

    values = values[-window:]

    y = log(values)
    X = arange(len(y)).reshape(-1, 1)  # pylint: disable=invalid-name

    lr = LinearRegression()
    lr.fit(X, y)

    r2 = lr.score(X, y)
    coef = lr.coef_[0]
    annualized_coef = (exp(coef) ** 252) - 1

    return r2, annualized_coef, Series(lr.predict(X))


def calculate_fib_levels(
    data: "DataFrame",

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Reduce window to <= len(values).
  2. Fetch a longer history before computing the regression.
  3. Derive window from actual data length: window = min(window, len(values)).
  4. Confirm the data frequency matches the window's 'days' semantics.

Example fix

# before
regression(values=prices[:100], window=252)  # raises

# after
regression(values=prices, window=min(252, len(prices)))
Defensive patterns

Strategy: validation

Validate before calling

assert len(values) >= window, f"need >= {window} points, have {len(values)}"
window = min(window, len(values))

Type guard

def window_covers_series(values, window: int) -> bool:
    return len(values) >= window

Try / catch

try:
    r2, coef, fit = regression(values, window=window)
except ValueError as e:
    if "at least last" in str(e):
        window = len(values)
        r2, coef, fit = regression(values, window=window)
    else:
        raise

Prevention

When it happens

Trigger: Calling the regression/trendline helper (used by drawing/analysis endpoints) with a window larger than the series length, e.g. window=365 on 200 days of prices.

Common situations: Daily-bar assumptions applied to weekly/monthly series (a year of weekly bars is ~52, not 365); short history for new listings; window parameters copied from long-history charts.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/36dd42f4b8274093. Report an issue: GitHub.