33 lines
951 B
TypeScript
33 lines
951 B
TypeScript
import { CREDIT_RATING_SCALE } from '../config/ScoringConfig';
|
|
import { Asset } from './Asset';
|
|
import type { BondData, BondMetrics } from '../types/models.model';
|
|
|
|
export class Bond extends Asset {
|
|
metrics: BondMetrics;
|
|
|
|
constructor(data: BondData) {
|
|
super(data);
|
|
|
|
const creditRating = data.creditRating || 'BBB';
|
|
const creditRatingNumeric = CREDIT_RATING_SCALE[creditRating] ?? 7;
|
|
|
|
this.metrics = {
|
|
ytm: parseFloat(String(data.yieldToMaturity)) || 0,
|
|
duration: parseFloat(String(data.duration)) || 0,
|
|
creditRating,
|
|
creditRatingNumeric,
|
|
};
|
|
}
|
|
|
|
getDisplayMetrics(): Record<string, string> {
|
|
return {
|
|
Ticker: this.ticker,
|
|
Type: 'BOND',
|
|
Price: this.formatCurrency(this.currentPrice),
|
|
'YTM%': `${this.metrics.ytm.toFixed(2)}%`,
|
|
Duration: this.metrics.duration.toFixed(1),
|
|
Rating: `${this.metrics.creditRating} (${this.metrics.creditRatingNumeric})`,
|
|
};
|
|
}
|
|
}
|