Documentation icon indicating copy to clipboard operation
Documentation copied to clipboard

Research resampling example sums quote sizes instead of taking the last size

Open quantconnect-kronos-reviewer-2[bot] opened this issue 4 weeks ago • 1 comments

Problem

In 04 Research Environment/03 Datasets/01 Key Concepts/99 Examples.html, the Python example aggregates asksize and bidsize with sum (lines 81 and 84), describing the results as total ask/bid volume. These columns are quote-size snapshots, not traded quantities. Summing successive snapshots does not produce a five-minute QuoteBar's last size or traded volume.

The adjacent C# example uses QuoteBarConsolidator and LastAskSize / LastBidSize (lines 40 and 56–57), so the two examples produce different results for the same input. 06 LEAN Engine/03 Data Format/02 Core Data Types/03 Quote Bar.html correctly defines each size as the last size in the period.

Minimal reproduction

import pandas as pd

history = pd.DataFrame(
    {"asksize": [10] * 5, "bidsize": [10] * 5},
    index=pd.date_range("2024-01-02 10:00", periods=5, freq="min"),
)
print(history.resample("5min").agg({"asksize": "sum", "bidsize": "sum"}))
print(history.resample("5min").last())

Observed: the documented aggregation returns 50 for each side; the last snapshot is 10. With the same price estimate, the Python example therefore calculates five times the C# example's value for this input.

Suggested correction

Aggregate the size columns with last to match QuoteBar consolidation, and describe the result as a quoted-size/notional estimate rather than total traded volume. This is an existing discrepancy in the example, independent of any change to Lean's runtime behavior.

Hi! I would like to contribute to this issue. I can investigate the Python resampling example, correct the quote-size aggregation to use the last value, and verify that the explanation matches the C# example. Is this issue available for me to work on? Thank you!

jeevanabhi-r avatar Nov 04 '26 16:11 jeevanabhi-r