Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/refactor thresholds of x ray rules (#3545)

Thomas Kaulffc630985099
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c9d7f731e9..886e5f9272 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 a9a60f912b..3b1433da02 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<Settings> {
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<Settings> {
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<Settings> {
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 8ebb24ac0c..fa2a8e529a 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<Settings> {
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<Settings> {
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<Settings> {
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 20e9502bfc..0f56e6e384 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<Settings> {
}
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<Settings> {
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 69db9634dc..ba487f8191 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<Settings> {
? 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<Settings> {
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<Settings> {
return {
baseCurrency: aUserSettings.baseCurrency,
isActive: true,
- threshold: 0.01
+ thresholdMax: 0.01
};
}
}
interface Settings extends RuleSettings {
baseCurrency: string;
- threshold: number;
+ thresholdMax: number;
}