Feature/Add static portfolio analysis rule for developed Markets (#3975)
* Add static portfolio analysis rule: Allocation Cluster Risk (Developed Markets) * Update changelog
This commit is contained in:
parent
e25aebf26f
commit
19b8c514f2
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Added
|
||||
|
||||
- Added a new static portfolio analysis rule: Allocation Cluster Risk (Developed Markets)
|
||||
- Added a new static portfolio analysis rule: Allocation Cluster Risk (Emerging Markets)
|
||||
- Added support for mutual funds in the _EOD Historical Data_ service
|
||||
|
||||
|
@ -7,6 +7,7 @@ import { UserService } from '@ghostfolio/api/app/user/user.service';
|
||||
import { getFactor } from '@ghostfolio/api/helper/portfolio.helper';
|
||||
import { AccountClusterRiskCurrentInvestment } from '@ghostfolio/api/models/rules/account-cluster-risk/current-investment';
|
||||
import { AccountClusterRiskSingleAccount } from '@ghostfolio/api/models/rules/account-cluster-risk/single-account';
|
||||
import { AllocationClusterRiskDevelopedMarkets } from '@ghostfolio/api/models/rules/allocation-cluster-risk/developed-markets';
|
||||
import { AllocationClusterRiskEmergingMarkets } from '@ghostfolio/api/models/rules/allocation-cluster-risk/emerging-markets';
|
||||
import { CurrencyClusterRiskBaseCurrencyCurrentInvestment } from '@ghostfolio/api/models/rules/currency-cluster-risk/base-currency-current-investment';
|
||||
import { CurrencyClusterRiskCurrentInvestment } from '@ghostfolio/api/models/rules/currency-cluster-risk/current-investment';
|
||||
@ -1190,6 +1191,11 @@ export class PortfolioService {
|
||||
summary.ordersCount > 0
|
||||
? await this.rulesService.evaluate(
|
||||
[
|
||||
new AllocationClusterRiskDevelopedMarkets(
|
||||
this.exchangeRateDataService,
|
||||
summary.currentValueInBaseCurrency,
|
||||
markets.developedMarkets.valueInBaseCurrency
|
||||
),
|
||||
new AllocationClusterRiskEmergingMarkets(
|
||||
this.exchangeRateDataService,
|
||||
summary.currentValueInBaseCurrency,
|
||||
|
@ -4,6 +4,7 @@ import { environment } from '@ghostfolio/api/environments/environment';
|
||||
import { PortfolioChangedEvent } from '@ghostfolio/api/events/portfolio-changed.event';
|
||||
import { AccountClusterRiskCurrentInvestment } from '@ghostfolio/api/models/rules/account-cluster-risk/current-investment';
|
||||
import { AccountClusterRiskSingleAccount } from '@ghostfolio/api/models/rules/account-cluster-risk/single-account';
|
||||
import { AllocationClusterRiskDevelopedMarkets } from '@ghostfolio/api/models/rules/allocation-cluster-risk/developed-markets';
|
||||
import { AllocationClusterRiskEmergingMarkets } from '@ghostfolio/api/models/rules/allocation-cluster-risk/emerging-markets';
|
||||
import { CurrencyClusterRiskBaseCurrencyCurrentInvestment } from '@ghostfolio/api/models/rules/currency-cluster-risk/base-currency-current-investment';
|
||||
import { CurrencyClusterRiskCurrentInvestment } from '@ghostfolio/api/models/rules/currency-cluster-risk/current-investment';
|
||||
@ -216,6 +217,12 @@ export class UserService {
|
||||
undefined,
|
||||
{}
|
||||
).getSettings(user.Settings.settings),
|
||||
AllocationClusterRiskDevelopedMarkets:
|
||||
new AllocationClusterRiskDevelopedMarkets(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined
|
||||
).getSettings(user.Settings.settings),
|
||||
AllocationClusterRiskEmergingMarkets:
|
||||
new AllocationClusterRiskEmergingMarkets(
|
||||
undefined,
|
||||
|
@ -0,0 +1,84 @@
|
||||
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
|
||||
import { Rule } from '@ghostfolio/api/models/rule';
|
||||
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
|
||||
import { UserSettings } from '@ghostfolio/common/interfaces';
|
||||
|
||||
export class AllocationClusterRiskDevelopedMarkets extends Rule<Settings> {
|
||||
private currentValueInBaseCurrency: number;
|
||||
private developedMarketsValueInBaseCurrency: number;
|
||||
|
||||
public constructor(
|
||||
protected exchangeRateDataService: ExchangeRateDataService,
|
||||
currentValueInBaseCurrency: number,
|
||||
developedMarketsValueInBaseCurrency: number
|
||||
) {
|
||||
super(exchangeRateDataService, {
|
||||
key: AllocationClusterRiskDevelopedMarkets.name,
|
||||
name: 'Developed Markets'
|
||||
});
|
||||
|
||||
this.currentValueInBaseCurrency = currentValueInBaseCurrency;
|
||||
this.developedMarketsValueInBaseCurrency =
|
||||
developedMarketsValueInBaseCurrency;
|
||||
}
|
||||
|
||||
public evaluate(ruleSettings: Settings) {
|
||||
const developedMarketsValueRatio = this.currentValueInBaseCurrency
|
||||
? this.developedMarketsValueInBaseCurrency /
|
||||
this.currentValueInBaseCurrency
|
||||
: 0;
|
||||
|
||||
if (developedMarketsValueRatio > ruleSettings.thresholdMax) {
|
||||
return {
|
||||
evaluation: `The developed markets contribution of your current investment (${(developedMarketsValueRatio * 100).toPrecision(3)}%) exceeds ${(
|
||||
ruleSettings.thresholdMax * 100
|
||||
).toPrecision(3)}%`,
|
||||
value: false
|
||||
};
|
||||
} else if (developedMarketsValueRatio < ruleSettings.thresholdMin) {
|
||||
return {
|
||||
evaluation: `The developed markets contribution of your current investment (${(developedMarketsValueRatio * 100).toPrecision(3)}%) is below ${(
|
||||
ruleSettings.thresholdMin * 100
|
||||
).toPrecision(3)}%`,
|
||||
value: false
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
evaluation: `The developed markets contribution of your current investment (${(developedMarketsValueRatio * 100).toPrecision(3)}%) is within the range of ${(
|
||||
ruleSettings.thresholdMin * 100
|
||||
).toPrecision(
|
||||
3
|
||||
)}% and ${(ruleSettings.thresholdMax * 100).toPrecision(3)}%`,
|
||||
value: true
|
||||
};
|
||||
}
|
||||
|
||||
public getConfiguration() {
|
||||
return {
|
||||
threshold: {
|
||||
max: 1,
|
||||
min: 0,
|
||||
step: 0.01,
|
||||
unit: '%'
|
||||
},
|
||||
thresholdMax: true,
|
||||
thresholdMin: true
|
||||
};
|
||||
}
|
||||
|
||||
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings {
|
||||
return {
|
||||
baseCurrency,
|
||||
isActive: xRayRules?.[this.getKey()]?.isActive ?? true,
|
||||
thresholdMax: xRayRules?.[this.getKey()]?.thresholdMax ?? 0.72,
|
||||
thresholdMin: xRayRules?.[this.getKey()]?.thresholdMin ?? 0.68
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
interface Settings extends RuleSettings {
|
||||
baseCurrency: string;
|
||||
thresholdMin: number;
|
||||
thresholdMax: number;
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
export type XRayRulesSettings = {
|
||||
AccountClusterRiskCurrentInvestment?: RuleSettings;
|
||||
AccountClusterRiskSingleAccount?: RuleSettings;
|
||||
AllocationClusterRiskDevelopedMarkets?: RuleSettings;
|
||||
AllocationClusterRiskEmergingMarkets?: RuleSettings;
|
||||
CurrencyClusterRiskBaseCurrencyCurrentInvestment?: RuleSettings;
|
||||
CurrencyClusterRiskCurrentInvestment?: RuleSettings;
|
||||
|
Loading…
x
Reference in New Issue
Block a user