Skip to main content

quantile

Calculate the rolling quantile of a target column within a given window size at a specified quantile percentage.

Quantiles are points dividing the range of a probability distribution into intervals with equal probabilities, or dividing the sample in the same way. This function is useful for understanding the distribution of data within a specified window, allowing for analysis of trends, identification of outliers, and assessment of risk.

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.quantile(data=returns, target="close", window=252, quantile_pct=0.25)
obb.quantitative.rolling.quantile(data=returns, target="close", window=252, quantile_pct=0.75)

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 quantile.False
windowintThe number of observations used for calculating the rolling measure.21False
quantile_pctfloatThe quantile percentage to calculate (e.g., 0.5 for median), default is 0.5.0.5False
indexstrThe name of the index column, default is "date".dateFalse

Returns​

OBBject
results : List[Data]
An object containing the rolling quantile values with the median.