Dollar Bars Sampling

Data Preparation & Feature Engineering DS practice problem on Onlearn.

Difficulty: hard.

Topics: Understanding Financial Data Resampling via Dollar Bars, Dollar Value Accumulation, OHLC Bar Construction, Cumulative Sum Thresholding, Transaction-level Data Processing, Sample Frequency Normalization, Time Series Analysis, Quantitative Finance, Data Preprocessing, Statistical Sampling, Financial Engineering, Market Microstructure, Information-Driven Resampling, Volume-Based Sampling, Feature Engineering for ML, Data Aggregation.

Implement a function 'get dollar bars' that takes a Pandas DataFrame containing 'price' and 'volume' columns and a 'threshold' value. The function should return a new DataFrame representing the OHLC (Open, High, Low, Close) bars where each bar is formed once the cumulative dollar value (price volume) exceeds the threshold.