Skip to content

Markets route reports a five-day price move as the daily change (range=5d + chartPreviousClose) #25

Description

@JackMN1

fetchYahoo() requests range=5d and then computes change / changePercent against meta.chartPreviousClose:

https://github.com/NoblerWorks-HQ/IRONSIGHT/blob/main/src/app/api/markets/route.ts#L22

const url = `...chart/${sym}?interval=1d&range=5d`;
...
const prev = meta.chartPreviousClose ?? meta.previousClose ?? price;
const pct  = prev ? Math.round(((price - prev) / prev) * 10000) / 100 : 0;

chartPreviousClose is the close immediately before the requested window — not the previous trading day. With range=5d it is therefore the close from five sessions ago, and every value the route labels a daily change is really a five-session move.

Reproduction (same instant, same instrument, same field — only range differs):

$ curl -s '.../chart/BA?interval=1d&range=5d' | jq '.chart.result[0].meta | {regularMarketPrice, chartPreviousClose}'
{ "regularMarketPrice": 239.45, "chartPreviousClose": 214.01 }   =>  +11.89%

$ curl -s '.../chart/BA?interval=1d&range=1d' | jq '.chart.result[0].meta | {regularMarketPrice, chartPreviousClose}'
{ "regularMarketPrice": 239.45, "chartPreviousClose": 237.16 }   =>  +0.97%

An earlier run of the same check gave +11.48% vs +0.59% on BA. The inflation factor varies with the week, but the sign of the error does not: in a trending market it is systematically overstated.

Why it matters beyond the number being wrong: the dashboard presents defence-contractor moves next to conflict events, so an inflated "daily" move reads as a market reaction to today's news. A threshold-based view of these values ends up flagging almost every instrument.

Fix: request range=1d. chartPreviousClose is then the actual previous close, and nothing else in the handler needs to change.

The oil/energy route has the identical defect — filed separately as #26 in case you would rather fix them in one commit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions