Skip to content

Commit

Permalink
Handle invalid holdings
Browse files Browse the repository at this point in the history
  • Loading branch information
Eskils committed Sep 20, 2024
1 parent 0edb11b commit cdef3ec
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/RiskScore/RiskScoreConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export class RiskScoreConverter extends MorningstarConverter {
// Parse and cumulate risk scores by date

const sortedPortfolios: RiskScorePortfolio[] = [];
const errors: string[] = [];

for (const riskScorePortfolio of json.riskScores) {
const {
Expand All @@ -147,6 +148,21 @@ export class RiskScoreConverter extends MorningstarConverter {
retainedWeightProxied,
scoringMethodUsed
});

if (
riskScorePortfolio.metadata !== undefined &&
riskScorePortfolio.metadata.messages.length > 0
) {
for (const message of riskScorePortfolio.metadata.messages) {
const holdingNames = message.invalidHoldings.map(
invalidHolding => invalidHolding.identifier
);

errors.push(
`The holding(s) ${holdingNames.join(', ')} are invalid. ${message.message}`
);
}
}
}

sortedPortfolios.sort((a, b) => (
Expand Down Expand Up @@ -196,6 +212,10 @@ export class RiskScoreConverter extends MorningstarConverter {
}
}

if (errors.length > 0) {
throw new Error(errors.join('\n'));
}

return true;
}

Expand Down

0 comments on commit cdef3ec

Please sign in to comment.