Created
July 6, 2025 06:26
-
-
Save databento-bot/64b88bb3cd9d7d7f9b67a4eccd3b788c to your computer and use it in GitHub Desktop.
Resample 1-minute OHLCV bars to 5-minute OHLCV bars on Databento
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import databento as db | |
client = db.Historical() | |
data = client.timeseries.get_range( | |
dataset="XNAS.ITCH", | |
schema="ohlcv-1m", | |
symbols="AAPL", | |
start="2021-04-09", | |
end="2021-04-10", | |
) | |
df = data.to_df() | |
# Resample to 5-minute bars | |
resampled_df = df.resample('5min').agg({ | |
'open': 'first', # First value in the 5-minute window | |
'high': 'max', # Maximum high in the 5-minute window | |
'low': 'min', # Minimum low in the 5-minute window | |
'close': 'last', # Last value in the 5-minute window | |
'volume': 'sum', # Sum of volume in the 5-minute window | |
'symbol': 'last', # Last symbol value (should be consistent) | |
'instrument_id': 'last', # Last instrument_id value (should be consistent) | |
'publisher_id': 'last', # Last publisher_id value (should be consistent except for aggregated datasets) | |
'rtype': 'last' # Last rtype value (should be consistent) | |
}).dropna() | |
print(resampled_df.head(10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment