phase-7: code restructure
This commit is contained in:
committed by
saikiranvella
parent
c160e65bd6
commit
357b0c0f6e
@@ -0,0 +1,32 @@
|
||||
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})`,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user