Resample panda dataframes from Liberator into a common time axis
Lets first look at two different independent datasets: trades and minute_bars
import liberator
symbols = ['TSLA']
as_of = '2024-06-07'
back_to = '2024-06-04'
%time df1 = liberator.get_dataframe(liberator.query(symbols = symbols, name = 'minute_bars', as_of = as_of, back_to = back_to))
liberator.get_dataframe(liberator.query(name = 'daily_bars', symbols = symbols, as_of = as_of, back_to = back_to))
We can query them both together at the same time using SuperQuery and specify how they are re-indexed/merged together,
Final result in 1D format
For a 3 day query we will get 3 rows back with daily bars and the final minute bar of each day
df = liberator.get_dataframe(liberator.query(symbols = symbols, name = ['daily_bars', 'minute_bars'], as_of = as_of, back_to = back_to, superq_periods_per_batch_override = 5, superq_resample_rule = '1D'))
df
Final result in 60T format
For a 3 day query we will get 24 rows back per day, our eod daily bar data is timestamped 8pm
%time df4 = liberator.get_dataframe(liberator.query(symbols = symbols, name = ['daily_bars','minute_bars'], as_of = as_of, back_to = back_to, superq_periods_per_batch_override = 5, superq_resample_rule = '60T'))
df
superq_resample_rule
The superq_resample_rule uses Offset Periods.
https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases