From ffc6309850991a99b3bf298d3e05867e77bd60a8 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 7 Jul 2024 08:25:51 +0200 Subject: [PATCH] Feature/refactor thresholds of x ray rules (#3545) * Refactor thresholds * Update changelog --- CHANGELOG.md | 1 + .../account-cluster-risk/current-investment.ts | 10 +++++----- .../currency-cluster-risk/current-investment.ts | 10 +++++----- .../rules/emergency-fund/emergency-fund-setup.ts | 14 +++++++------- .../rules/fees/fee-ratio-initial-investment.ts | 10 +++++----- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9d7f731..886e5f92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the allocations by ETF holding on the allocations page for the impersonation mode (experimental) - Improved the detection of REST APIs (`JSON`) used via the scraper configuration +- Refactored the thresholds of the rules in the _X-ray_ section - Upgraded `Nx` from version `19.2.2` to `19.4.0` ## 2.92.0 - 2024-06-30 diff --git a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts index a9a60f91..3b1433da 100644 --- a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts +++ b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts @@ -55,10 +55,10 @@ export class AccountClusterRiskCurrentInvestment extends Rule { const maxInvestmentRatio = maxItem?.investment / totalInvestment || 0; - if (maxInvestmentRatio > ruleSettings.threshold) { + if (maxInvestmentRatio > ruleSettings.thresholdMax) { return { evaluation: `Over ${ - ruleSettings.threshold * 100 + ruleSettings.thresholdMax * 100 }% of your current investment is at ${maxItem.name} (${( maxInvestmentRatio * 100 ).toPrecision(3)}%)`, @@ -70,7 +70,7 @@ export class AccountClusterRiskCurrentInvestment extends Rule { evaluation: `The major part of your current investment is at ${ maxItem.name } (${(maxInvestmentRatio * 100).toPrecision(3)}%) and does not exceed ${ - ruleSettings.threshold * 100 + ruleSettings.thresholdMax * 100 }%`, value: true }; @@ -80,12 +80,12 @@ export class AccountClusterRiskCurrentInvestment extends Rule { return { baseCurrency: aUserSettings.baseCurrency, isActive: true, - threshold: 0.5 + thresholdMax: 0.5 }; } } interface Settings extends RuleSettings { baseCurrency: string; - threshold: number; + thresholdMax: number; } diff --git a/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts index 8ebb24ac..fa2a8e52 100644 --- a/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts +++ b/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts @@ -41,10 +41,10 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule { const maxValueRatio = maxItem?.value / totalValue || 0; - if (maxValueRatio > ruleSettings.threshold) { + if (maxValueRatio > ruleSettings.thresholdMax) { return { evaluation: `Over ${ - ruleSettings.threshold * 100 + ruleSettings.thresholdMax * 100 }% of your current investment is in ${maxItem.groupKey} (${( maxValueRatio * 100 ).toPrecision(3)}%)`, @@ -56,7 +56,7 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule { evaluation: `The major part of your current investment is in ${ maxItem?.groupKey ?? ruleSettings.baseCurrency } (${(maxValueRatio * 100).toPrecision(3)}%) and does not exceed ${ - ruleSettings.threshold * 100 + ruleSettings.thresholdMax * 100 }%`, value: true }; @@ -66,12 +66,12 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule { return { baseCurrency: aUserSettings.baseCurrency, isActive: true, - threshold: 0.5 + thresholdMax: 0.5 }; } } interface Settings extends RuleSettings { baseCurrency: string; - threshold: number; + thresholdMax: number; } diff --git a/apps/api/src/models/rules/emergency-fund/emergency-fund-setup.ts b/apps/api/src/models/rules/emergency-fund/emergency-fund-setup.ts index 20e9502b..0f56e6e3 100644 --- a/apps/api/src/models/rules/emergency-fund/emergency-fund-setup.ts +++ b/apps/api/src/models/rules/emergency-fund/emergency-fund-setup.ts @@ -19,16 +19,16 @@ export class EmergencyFundSetup extends Rule { } public evaluate(ruleSettings: Settings) { - if (this.emergencyFund > ruleSettings.threshold) { + if (this.emergencyFund < ruleSettings.thresholdMin) { return { - evaluation: 'An emergency fund has been set up', - value: true + evaluation: 'No emergency fund has been set up', + value: false }; } return { - evaluation: 'No emergency fund has been set up', - value: false + evaluation: 'An emergency fund has been set up', + value: true }; } @@ -36,12 +36,12 @@ export class EmergencyFundSetup extends Rule { return { baseCurrency: aUserSettings.baseCurrency, isActive: true, - threshold: 0 + thresholdMin: 0 }; } } interface Settings extends RuleSettings { baseCurrency: string; - threshold: number; + thresholdMin: number; } diff --git a/apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts b/apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts index 69db9634..ba487f81 100644 --- a/apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts +++ b/apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts @@ -26,10 +26,10 @@ export class FeeRatioInitialInvestment extends Rule { ? this.fees / this.totalInvestment : 0; - if (feeRatio > ruleSettings.threshold) { + if (feeRatio > ruleSettings.thresholdMax) { return { evaluation: `The fees do exceed ${ - ruleSettings.threshold * 100 + ruleSettings.thresholdMax * 100 }% of your initial investment (${(feeRatio * 100).toPrecision(3)}%)`, value: false }; @@ -37,7 +37,7 @@ export class FeeRatioInitialInvestment extends Rule { return { evaluation: `The fees do not exceed ${ - ruleSettings.threshold * 100 + ruleSettings.thresholdMax * 100 }% of your initial investment (${(feeRatio * 100).toPrecision(3)}%)`, value: true }; @@ -47,12 +47,12 @@ export class FeeRatioInitialInvestment extends Rule { return { baseCurrency: aUserSettings.baseCurrency, isActive: true, - threshold: 0.01 + thresholdMax: 0.01 }; } } interface Settings extends RuleSettings { baseCurrency: string; - threshold: number; + thresholdMax: number; }