Add company analysis view with financials, price history, filings, and AI reports

This commit is contained in:
2026-02-27 09:57:44 -05:00
parent e7320f3bdb
commit 7c3836068f
9 changed files with 512 additions and 2 deletions

View File

@@ -42,3 +42,73 @@ export async function getQuote(ticker: string): Promise<number> {
return fallbackQuote(normalizedTicker);
}
}
export async function getPriceHistory(ticker: string): Promise<Array<{ date: string; close: number }>> {
const normalizedTicker = ticker.trim().toUpperCase();
try {
const response = await fetch(`${YAHOO_BASE}/${normalizedTicker}?interval=1wk&range=1y`, {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; FiscalClone/3.0)'
},
cache: 'no-store'
});
if (!response.ok) {
throw new Error('Quote history unavailable');
}
const payload = await response.json() as {
chart?: {
result?: Array<{
timestamp?: number[];
indicators?: {
quote?: Array<{
close?: Array<number | null>;
}>;
};
}>;
};
};
const result = payload.chart?.result?.[0];
const timestamps = result?.timestamp ?? [];
const closes = result?.indicators?.quote?.[0]?.close ?? [];
const points = timestamps
.map((timestamp, index) => {
const close = closes[index];
if (typeof close !== 'number' || !Number.isFinite(close)) {
return null;
}
return {
date: new Date(timestamp * 1000).toISOString(),
close
};
})
.filter((entry): entry is { date: string; close: number } => entry !== null);
if (points.length > 0) {
return points;
}
} catch {
// fall through to deterministic synthetic history
}
const now = Date.now();
const base = fallbackQuote(normalizedTicker);
return Array.from({ length: 26 }, (_, index) => {
const step = 25 - index;
const date = new Date(now - step * 14 * 24 * 60 * 60 * 1000).toISOString();
const wave = Math.sin(index / 3.5) * 0.05;
const trend = (index - 13) * 0.006;
const close = Math.max(base * (1 + wave + trend), 1);
return {
date,
close: Number(close.toFixed(2))
};
});
}