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

Open Beginner friendly
#2,838 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@jeevanabhi-r is already working on this.

Since Nov 4, 2026.

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp, python
Domain
documentation

Research direction

The Python example is in 04 Research Environment/03 Datasets/01 Key Concepts/99 Examples.html around lines 81 and 84, where asksize and bidsize are aggregated with sum. Compare it with the C# example at lines 40 and 56-57 and with the QuoteBar definition in 06 LEAN Engine/03 Data Format/02 Core Data Types/03 Quote Bar.html. Run the reproduction in the issue to confirm the sum gives 50 and last gives 10. Done when the Python aggregation uses last and the surrounding wording describes the result as a quoted-size estimate, not traded volume.

Written by the indexing model from the issue text.

Description

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.

Dominant language
HTML
Stars
266
Forks
189
Avg merge
7h 25m
Merged PRs (30d)
81

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from QuantConnect/Documentation

All issues in QuantConnect/Documentation

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.