# Comparing a week still trading: like-for-like periods in a sales screener

By Farhad Rezaei (https://farhad-rezaei.com) · Published 2026-11-22
Canonical: https://farhad-rezaei.com/blog/comparing-a-week-still-trading
Product: Fundai (https://fundai.ir/en)

> A week still trading has to be compared with the same first days of every other week, not with whole weeks: on a Monday, 40 against last week's full 70 reads as -43%, but against last week's same three days, 20, it's +100%. Fundai's screener now cuts every baseline that way, stores compared_days on the row so the interface can say how it was read, and rebuilds last week whole once a new week opens.

[Fundai](https://fundai.ir/en) is the stock-research platform for the Tehran Stock Exchange that I co-founded in 2023. Many listed companies also sell their products, steel slabs and coils among them, on the Iran Mercantile Exchange, and Fundai turns those trades into a weekly sales screener: for each company and product, this week's sales against the week before, the same week last month and last year, and the fiscal year's average, lowest and highest week. Earlier this month I wrote about the caching behind Fundai's market cards in [One rebuild, not twenty](https://farhad-rezaei.com/blog/one-rebuild-not-twenty); this is about whether the numbers on one of those screens compare like with like.

Every Monday, almost every company on the screener looked like it was falling. Nothing had changed except the calendar.

Picture a shop owner who checks the till at lunchtime on Monday and compares it with last week's total takings. Of course Monday morning looks bad. The fair comparison is Monday morning against last Monday morning, and the owner would also want the note on the receipt to say so.

## What the screener was doing

The Iranian week starts on Saturday, so by Monday the week still trading has three days of sales. Here's one product from the feature's test. This week, Saturday to Monday, it sold 40. Last week, whole, it sold 70. The screener reads that as -43%, a sharp fall, and so does every other company that sells steadily through the week. By Wednesday the same products look like they're recovering, and by the weekend the dip is gone, because the comparison finally covers the same span of days.

The data was right. The comparison was wrong, and a screener's whole job is the comparison: an investor filters for falling sales and gets a list of companies that are simply early in their week.

![On a Monday, this week's 40 against last week's whole 70 reads as -43%; against the same three days of last week, 20, it reads as +100%.](https://farhad-rezaei.com/images/blog/comparing-a-week-still-trading/window.svg)

## Deciding what the screen should promise

Before changing code, we settled two rules.

Compare like with like. A week still trading is read against the same first days of every week it's compared with: Saturday to Monday this week against Saturday to Monday of the week before, of the same week last month and last year, and of every week behind the fiscal-year average, lowest and highest. Against the same three days, last week sold 20, and the product's -43% becomes +100%.

Say so. A cut comparison is still a different kind of number from a whole-week one, so the row records how many days it was read on, and the screen can show it in the hover. A partial number never passes for a full week.

A third rule follows from the first: a week that has finished is read whole again. Last week's row was itself built while that week was trading, so once a new week opens, the week before is always rebuilt, and from then on it compares whole against whole.

## How it works

Each weekly row now carries a `compared_days` field. It's set only on the week still trading, and every baseline for that row is computed over the same first days of its own week. A whole week leaves the field empty, and so does the week before once it has been rebuilt, so the screen only shows the note when it applies. Months follow the same idea: a row for the month still trading names what it was compared against in `compared_period`, so the hover can say the comparison was cut to the row's day.

```python
# From the feature's test: a Monday of the week still trading
build(company, company.financial_date, today=WEEK + 2 * DAY)
row = self.row(slab, ProductAttr.SALE_AMOUNT)
assert (row.value, row.previous_week, row.compared_days) == (40, 20, 3)

# The next run, a week later: the week before is rebuilt whole
build(company, company.financial_date, since=WEEK + 8 * DAY, today=WEEK + 8 * DAY)
row = self.row(slab, ProductAttr.SALE_AMOUNT)
assert (row.previous_week, row.compared_days) == (70, None)
```

The averages are cut the same way. The fiscal-year average for that Monday is the average of the same three days across the weeks before, not of whole weeks, so a slow start to every week doesn't drag the average down twice.

## How I checked it

The tests cover each rule against a small, invented set of trades. A Monday of the week still trading meets the same days of the weeks it's compared with, and the row says 3. A week that has finished reads the others whole once the next week's run rebuilds it. A Friday, when the week's trading is over, compares the full week. For months, the month still trading names its comparison source, a running total is cut to the day too, and a whole month, or a comparison with last year's average of whole months, says nothing.

One limit follows from the design. The cut is by day of the week, so it's fair about the calendar and nothing else: a holiday that closes the exchange early in one week and not in another still leaves the two windows unequal, and the row doesn't correct for it.

## What carries over

- Any "this period versus last period" view has this problem while the current period is still running. Check it on the first day of a period, not the last.
- Cut the baselines to the current period's elapsed days rather than scaling the current number up, which guesses at sales that haven't happened.
- Record how a number was compared, next to the number, so the interface can say it.
- When a period closes, recompute what was built while it was open.

For an investor, the screener now shows a fall only when sales actually fall, on any day of the week. The change itself is small, a field and a different window for every baseline, but it comes from treating the comparison as part of the data, which is what a reader acts on.

## Further reading

- Same-store sales, the retail version of like-for-like comparison: https://en.wikipedia.org/wiki/Same-store_sales
- Seasonal adjustment, and why calendar effects distort period comparisons: https://en.wikipedia.org/wiki/Seasonal_adjustment
- Iran Mercantile Exchange: https://en.wikipedia.org/wiki/Iran_Mercantile_Exchange
