Files
worldquant-alpha-system/frontend/src/alphaMetrics.ts
T
yuxuanhui f3eb239e1a
Deploy production / deploy (push) Successful in 54s
fix: allow repeated platform checks and unify Alpha metric formatting
2026-09-12 22:42:37 +08:00

13 lines
569 B
TypeScript

/** Format the five headline Alpha metrics for display; stored/filter values stay raw.
* Unsupported fields return undefined so callers can retain their existing format.
*/
export function formatAlphaMetric(
key: string,
value: unknown,
): string | undefined {
const percent = key === "turnover" || key === "returns" || key === "drawdown";
if (!percent && key !== "sharpe" && key !== "fitness") return undefined;
if (typeof value !== "number" || !Number.isFinite(value)) return "—";
return percent ? `${(value * 100).toFixed(2)}%` : value.toFixed(2);
}