Feature/add regional market cluster risk for Japan (#4309)
* Add regional market cluster risk for Japan * Update changelog
This commit is contained in:
parent
f92c877769
commit
b616274380
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Added a new static portfolio analysis rule: _Regional Market Cluster Risk_ (Japan)
|
||||||
- Extended the tags selector component by a `readonly` attribute
|
- Extended the tags selector component by a `readonly` attribute
|
||||||
- Extended the tags selector component to support creating custom tags
|
- Extended the tags selector component to support creating custom tags
|
||||||
- Added global styles to the _Storybook_ setup
|
- Added global styles to the _Storybook_ setup
|
||||||
|
@ -17,6 +17,7 @@ import { EmergencyFundSetup } from '@ghostfolio/api/models/rules/emergency-fund/
|
|||||||
import { FeeRatioInitialInvestment } from '@ghostfolio/api/models/rules/fees/fee-ratio-initial-investment';
|
import { FeeRatioInitialInvestment } from '@ghostfolio/api/models/rules/fees/fee-ratio-initial-investment';
|
||||||
import { RegionalMarketClusterRiskEmergingMarkets } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/emerging-markets';
|
import { RegionalMarketClusterRiskEmergingMarkets } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/emerging-markets';
|
||||||
import { RegionalMarketClusterRiskEurope } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/europe';
|
import { RegionalMarketClusterRiskEurope } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/europe';
|
||||||
|
import { RegionalMarketClusterRiskJapan } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/japan';
|
||||||
import { RegionalMarketClusterRiskNorthAmerica } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/north-america';
|
import { RegionalMarketClusterRiskNorthAmerica } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/north-america';
|
||||||
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service';
|
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service';
|
||||||
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
|
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
|
||||||
@ -1290,6 +1291,11 @@ export class PortfolioService {
|
|||||||
marketsAdvancedTotalInBaseCurrency,
|
marketsAdvancedTotalInBaseCurrency,
|
||||||
marketsAdvanced.europe.valueInBaseCurrency
|
marketsAdvanced.europe.valueInBaseCurrency
|
||||||
),
|
),
|
||||||
|
new RegionalMarketClusterRiskJapan(
|
||||||
|
this.exchangeRateDataService,
|
||||||
|
marketsAdvancedTotalInBaseCurrency,
|
||||||
|
marketsAdvanced.japan.valueInBaseCurrency
|
||||||
|
),
|
||||||
new RegionalMarketClusterRiskNorthAmerica(
|
new RegionalMarketClusterRiskNorthAmerica(
|
||||||
this.exchangeRateDataService,
|
this.exchangeRateDataService,
|
||||||
marketsAdvancedTotalInBaseCurrency,
|
marketsAdvancedTotalInBaseCurrency,
|
||||||
|
@ -15,6 +15,7 @@ import { EmergencyFundSetup } from '@ghostfolio/api/models/rules/emergency-fund/
|
|||||||
import { FeeRatioInitialInvestment } from '@ghostfolio/api/models/rules/fees/fee-ratio-initial-investment';
|
import { FeeRatioInitialInvestment } from '@ghostfolio/api/models/rules/fees/fee-ratio-initial-investment';
|
||||||
import { RegionalMarketClusterRiskEmergingMarkets } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/emerging-markets';
|
import { RegionalMarketClusterRiskEmergingMarkets } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/emerging-markets';
|
||||||
import { RegionalMarketClusterRiskEurope } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/europe';
|
import { RegionalMarketClusterRiskEurope } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/europe';
|
||||||
|
import { RegionalMarketClusterRiskJapan } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/japan';
|
||||||
import { RegionalMarketClusterRiskNorthAmerica } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/north-america';
|
import { RegionalMarketClusterRiskNorthAmerica } from '@ghostfolio/api/models/rules/regional-market-cluster-risk/north-america';
|
||||||
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
|
||||||
import { I18nService } from '@ghostfolio/api/services/i18n/i18n.service';
|
import { I18nService } from '@ghostfolio/api/services/i18n/i18n.service';
|
||||||
@ -283,6 +284,11 @@ export class UserService {
|
|||||||
undefined,
|
undefined,
|
||||||
undefined
|
undefined
|
||||||
).getSettings(user.Settings.settings),
|
).getSettings(user.Settings.settings),
|
||||||
|
RegionalMarketClusterRiskJapan: new RegionalMarketClusterRiskJapan(
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined
|
||||||
|
).getSettings(user.Settings.settings),
|
||||||
RegionalMarketClusterRiskNorthAmerica:
|
RegionalMarketClusterRiskNorthAmerica:
|
||||||
new RegionalMarketClusterRiskNorthAmerica(
|
new RegionalMarketClusterRiskNorthAmerica(
|
||||||
undefined,
|
undefined,
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
import { Settings } from './interfaces/rule-settings.interface';
|
||||||
|
|
||||||
|
export class RegionalMarketClusterRiskJapan extends Rule<Settings> {
|
||||||
|
private currentValueInBaseCurrency: number;
|
||||||
|
private japanValueInBaseCurrency: number;
|
||||||
|
|
||||||
|
public constructor(
|
||||||
|
protected exchangeRateDataService: ExchangeRateDataService,
|
||||||
|
currentValueInBaseCurrency: number,
|
||||||
|
japanValueInBaseCurrency: number
|
||||||
|
) {
|
||||||
|
super(exchangeRateDataService, {
|
||||||
|
key: RegionalMarketClusterRiskJapan.name,
|
||||||
|
name: 'Japan'
|
||||||
|
});
|
||||||
|
|
||||||
|
this.currentValueInBaseCurrency = currentValueInBaseCurrency;
|
||||||
|
this.japanValueInBaseCurrency = japanValueInBaseCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public evaluate(ruleSettings: Settings) {
|
||||||
|
const japanMarketValueRatio = this.currentValueInBaseCurrency
|
||||||
|
? this.japanValueInBaseCurrency / this.currentValueInBaseCurrency
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
if (japanMarketValueRatio > ruleSettings.thresholdMax) {
|
||||||
|
return {
|
||||||
|
evaluation: `The Japan market contribution of your current investment (${(japanMarketValueRatio * 100).toPrecision(3)}%) exceeds ${(
|
||||||
|
ruleSettings.thresholdMax * 100
|
||||||
|
).toPrecision(3)}%`,
|
||||||
|
value: false
|
||||||
|
};
|
||||||
|
} else if (japanMarketValueRatio < ruleSettings.thresholdMin) {
|
||||||
|
return {
|
||||||
|
evaluation: `The Japan market contribution of your current investment (${(japanMarketValueRatio * 100).toPrecision(3)}%) is below ${(
|
||||||
|
ruleSettings.thresholdMin * 100
|
||||||
|
).toPrecision(3)}%`,
|
||||||
|
value: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
evaluation: `The Japan market contribution of your current investment (${(japanMarketValueRatio * 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.06,
|
||||||
|
thresholdMin: xRayRules?.[this.getKey()]?.thresholdMin ?? 0.04
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ export interface XRayRulesSettings {
|
|||||||
FeeRatioInitialInvestment?: RuleSettings;
|
FeeRatioInitialInvestment?: RuleSettings;
|
||||||
RegionalMarketClusterRiskEmergingMarkets?: RuleSettings;
|
RegionalMarketClusterRiskEmergingMarkets?: RuleSettings;
|
||||||
RegionalMarketClusterRiskEurope?: RuleSettings;
|
RegionalMarketClusterRiskEurope?: RuleSettings;
|
||||||
|
RegionalMarketClusterRiskJapan?: RuleSettings;
|
||||||
RegionalMarketClusterRiskNorthAmerica?: RuleSettings;
|
RegionalMarketClusterRiskNorthAmerica?: RuleSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user