UI enhancemnts
This commit is contained in:
@@ -6,24 +6,34 @@ export class Etf extends Asset {
|
||||
|
||||
constructor(data: EtfData) {
|
||||
super(data);
|
||||
// Preserve null for missing fields — coercing to 0 would auto-fail gates
|
||||
// in EtfScorer for data Yahoo simply didn't return.
|
||||
const num = (v: unknown): number | null => {
|
||||
if (v == null) return null;
|
||||
const f = parseFloat(String(v));
|
||||
return Number.isFinite(f) ? f : null;
|
||||
};
|
||||
this.metrics = {
|
||||
expenseRatio: parseFloat(String(data.expenseRatio)) || 0,
|
||||
totalAssets: parseFloat(String(data.totalAssets)) || 0,
|
||||
yield: parseFloat(String(data.yield)) || 0,
|
||||
volume: parseFloat(String(data.volume)) || 0,
|
||||
fiveYearReturn: parseFloat(String(data.fiveYearReturn)) || 0,
|
||||
expenseRatio: num(data.expenseRatio),
|
||||
totalAssets: num(data.totalAssets),
|
||||
yield: num(data.yield),
|
||||
volume: num(data.volume),
|
||||
fiveYearReturn: num(data.fiveYearReturn),
|
||||
};
|
||||
}
|
||||
|
||||
getDisplayMetrics(): Record<string, string> {
|
||||
const m = this.metrics;
|
||||
const fmt = (v: number | null, dec: number, suffix = '') =>
|
||||
v != null ? `${v.toFixed(dec)}${suffix}` : '—';
|
||||
return {
|
||||
Ticker: this.ticker,
|
||||
Type: 'ETF',
|
||||
Price: this.formatCurrency(this.currentPrice),
|
||||
'Exp Ratio%': `${this.metrics.expenseRatio.toFixed(2)}%`,
|
||||
'Yield%': `${this.metrics.yield.toFixed(2)}%`,
|
||||
AUM: this.formatLargeNumber(this.metrics.totalAssets),
|
||||
'5Y Return%': `${this.metrics.fiveYearReturn.toFixed(1)}%`,
|
||||
'Exp Ratio%': fmt(m.expenseRatio, 2, '%'),
|
||||
'Yield%': fmt(m.yield, 2, '%'),
|
||||
AUM: m.totalAssets != null ? this.formatLargeNumber(m.totalAssets) : '—',
|
||||
'5Y Return%': fmt(m.fiveYearReturn, 1, '%'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user