30 lines
817 B
JavaScript
30 lines
817 B
JavaScript
import { CREDIT_RATING_SCALE } from '../../config/ScoringConfig.js';
|
|
import { Asset } from './Asset.js';
|
|
|
|
export class Bond extends Asset {
|
|
constructor(data) {
|
|
super(data);
|
|
|
|
const creditRating = data.creditRating || 'BBB';
|
|
const creditRatingNumeric = CREDIT_RATING_SCALE[creditRating] ?? 7;
|
|
|
|
this.metrics = {
|
|
ytm: parseFloat(data.yieldToMaturity) || 0,
|
|
duration: parseFloat(data.duration) || 0,
|
|
creditRating,
|
|
creditRatingNumeric,
|
|
};
|
|
}
|
|
|
|
getDisplayMetrics() {
|
|
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})`,
|
|
};
|
|
}
|
|
}
|