phase-8:server code enhancements.
This commit is contained in:
committed by
saikiranvella
parent
93aac355cc
commit
ff1b99910b
@@ -11,7 +11,7 @@ export class BondScorer {
|
||||
context?: MarketContext | null,
|
||||
): ScoreResult {
|
||||
const { gates, weights, thresholds } = rules;
|
||||
const metrics = BondScorer._sanitize(m);
|
||||
const metrics = BondScorer.sanitize(m);
|
||||
const riskFreeRate = (context?.riskFreeRate ?? 4.0) / 100;
|
||||
|
||||
if (metrics.creditRatingNumeric < gates.minCreditRating) {
|
||||
@@ -37,7 +37,7 @@ export class BondScorer {
|
||||
};
|
||||
}
|
||||
|
||||
private static _sanitize(m: BondMetrics): SanitizedBondMetrics {
|
||||
private static sanitize(m: BondMetrics): SanitizedBondMetrics {
|
||||
const pct = (v: unknown): number =>
|
||||
parseFloat(typeof v === 'string' ? v.replace('%', '') : String(v)) / 100 || 0;
|
||||
return {
|
||||
|
||||
@@ -22,7 +22,7 @@ export class StockScorer {
|
||||
},
|
||||
): ScoreResult {
|
||||
const { gates, weights, thresholds } = rules;
|
||||
const m = StockScorer._sanitize(metrics);
|
||||
const m = StockScorer.sanitize(metrics);
|
||||
|
||||
const failures = [
|
||||
m.debtToEquity != null &&
|
||||
@@ -208,20 +208,20 @@ export class StockScorer {
|
||||
].filter(Boolean) as string[];
|
||||
|
||||
return {
|
||||
label: StockScorer._label(totalScore),
|
||||
label: StockScorer.label(totalScore),
|
||||
scoreSummary: `Score: ${totalScore}`,
|
||||
audit: { passedGates: true, breakdown, riskFlags: riskFlags.length ? riskFlags : null },
|
||||
};
|
||||
}
|
||||
|
||||
private static _label(score: number): string {
|
||||
private static label(score: number): string {
|
||||
if (score >= 8) return '🟢 BUY (High Conviction)';
|
||||
if (score >= 4) return '🟢 BUY (Speculative)';
|
||||
if (score >= 0) return '🟡 HOLD';
|
||||
return '🔴 REJECT';
|
||||
}
|
||||
|
||||
private static _sanitize(m: StockMetrics): SanitizedMetrics {
|
||||
private static sanitize(m: StockMetrics): SanitizedMetrics {
|
||||
const w52 =
|
||||
m.week52High != null && m.week52High > 0 && m.week52Low != null && m.currentPrice > 0
|
||||
? (m.currentPrice - m.week52Low) / (m.week52High - m.week52Low)
|
||||
|
||||
Reference in New Issue
Block a user