From fa4ad6b15ab980b72ba1646e024da739fb0416e2 Mon Sep 17 00:00:00 2001 From: Celes Renata Date: Wed, 29 Apr 2026 22:02:23 +0000 Subject: [PATCH] fix: widen price matching tolerance for sparse market data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only ~9 price bars per ticker (Polygon returns daily bars, not intraday). Widened gap tolerance to 6h for intraday, 12h for 1d, etc. Also skip time-range filtering when price data is sparse (≤20 bars) to avoid showing no prices at all. --- frontend/src/pages/CompanyDetail.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/CompanyDetail.tsx b/frontend/src/pages/CompanyDetail.tsx index c6b4604..375883a 100644 --- a/frontend/src/pages/CompanyDetail.tsx +++ b/frontend/src/pages/CompanyDetail.tsx @@ -703,8 +703,8 @@ function TrendHistoryChart({ trends, latestTrends, ticker, marketPrices, selecte .filter((p) => p.bar_timestamp != null && p.close != null) .sort((a, b) => a.bar_timestamp - b.bar_timestamp); - // Filter prices to the selected window's time range - const windowPrices = sortedPrices.filter((p) => p.bar_timestamp >= cutoffTs); + // Filter prices to the selected window's time range (use all prices if sparse) + const windowPrices = sortedPrices.length <= 20 ? sortedPrices : sortedPrices.filter((p) => p.bar_timestamp >= cutoffTs); function findClosestPrice(ts: number): number | undefined { if (windowPrices.length === 0) return undefined; @@ -717,8 +717,16 @@ function TrendHistoryChart({ trends, latestTrends, ticker, marketPrices, selecte bestDiff = diff; } } - // Only match if within 2 hours (for intraday) or 36 hours (for daily) - const maxGap = selectedWindow === 'intraday' ? 2 * 3600_000 : 36 * 3600_000; + // Match if within reasonable gap for the window type + // With sparse price data (~1 bar per 4-6 hours), use wider tolerances + const maxGapHours: Record = { + intraday: 6, + '1d': 12, + '7d': 36, + '30d': 72, + '90d': 168, + }; + const maxGap = (maxGapHours[selectedWindow] ?? 36) * 3600_000; return bestDiff <= maxGap ? best.close : undefined; }