Skip to main content

mean

Calculate the rolling mean (average) of a target column within a given window size.

The rolling mean is a simple moving average that calculates the average of a target variable over a specified window. This function is widely used in financial analysis to smooth short-term fluctuations and highlight longer-term trends or cycles in time series data.

Example​

from openbb import obb

stock_data = obb.equity.price.historical(symbol="TSLA", start_date="2023-01-01", provider="fmp").to_df()
returns = stock_data["close"].pct_change().dropna()
obb.quantitative.rolling.mean(data=returns, target="close", window=252)

Parameters​

NameTypeDescriptionDefaultOptional
dataList[Data]The time series data as a list of data points.False
targetstrThe name of the column for which to calculate the mean.False
windowintThe number of observations used for calculating the rolling measure.21False
indexstrThe name of the index column, default is "date".dateFalse

Returns​

OBBject
results : List[Data]
An object containing the rolling mean values.