@ -1,6 +1,7 @@
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface' ;
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface' ;
import { Rule } from '@ghostfolio/api/models/rule' ;
import { Rule } from '@ghostfolio/api/models/rule' ;
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' ;
import { I18nService } from '@ghostfolio/api/services/i18n/i18n.service' ;
import { UserSettings } from '@ghostfolio/common/interfaces' ;
import { UserSettings } from '@ghostfolio/common/interfaces' ;
export class EconomicMarketClusterRiskDevelopedMarkets extends Rule < Settings > {
export class EconomicMarketClusterRiskDevelopedMarkets extends Rule < Settings > {
@ -9,10 +10,13 @@ export class EconomicMarketClusterRiskDevelopedMarkets extends Rule<Settings> {
public constructor (
public constructor (
protected exchangeRateDataService : ExchangeRateDataService ,
protected exchangeRateDataService : ExchangeRateDataService ,
private i18nService : I18nService ,
currentValueInBaseCurrency : number ,
currentValueInBaseCurrency : number ,
developedMarketsValueInBaseCurrency : number
developedMarketsValueInBaseCurrency : number ,
languageCode : string
) {
) {
super ( exchangeRateDataService , {
super ( exchangeRateDataService , {
languageCode ,
key : EconomicMarketClusterRiskDevelopedMarkets.name
key : EconomicMarketClusterRiskDevelopedMarkets.name
} ) ;
} ) ;
@ -29,32 +33,55 @@ export class EconomicMarketClusterRiskDevelopedMarkets extends Rule<Settings> {
if ( developedMarketsValueRatio > ruleSettings . thresholdMax ) {
if ( developedMarketsValueRatio > ruleSettings . thresholdMax ) {
return {
return {
evaluation : ` The developed markets contribution of your current investment ( ${ ( developedMarketsValueRatio * 100 ) . toPrecision ( 3 ) } %) exceeds ${ (
evaluation : this.i18nService.getTranslation ( {
ruleSettings . thresholdMax * 100
id : 'rule.economicMarketClusterRiskDevelopedMarkets.false.max' ,
) . toPrecision ( 3 ) } % ` ,
languageCode : this.getLanguageCode ( ) ,
placeholders : {
developedMarketsValueRatio : (
developedMarketsValueRatio * 100
) . toPrecision ( 3 ) ,
thresholdMax : ( ruleSettings . thresholdMax * 100 ) . toPrecision ( 3 )
}
} ) ,
value : false
value : false
} ;
} ;
} else if ( developedMarketsValueRatio < ruleSettings . thresholdMin ) {
} else if ( developedMarketsValueRatio < ruleSettings . thresholdMin ) {
return {
return {
evaluation : ` The developed markets contribution of your current investment ( ${ ( developedMarketsValueRatio * 100 ) . toPrecision ( 3 ) } %) is below ${ (
evaluation : this.i18nService.getTranslation ( {
ruleSettings . thresholdMin * 100
id : 'rule.economicMarketClusterRiskDevelopedMarkets.false.min' ,
) . toPrecision ( 3 ) } % ` ,
languageCode : this.getLanguageCode ( ) ,
placeholders : {
developedMarketsValueRatio : (
developedMarketsValueRatio * 100
) . toPrecision ( 3 ) ,
thresholdMin : ( ruleSettings . thresholdMin * 100 ) . toPrecision ( 3 )
}
} ) ,
value : false
value : false
} ;
} ;
}
}
return {
return {
evaluation : ` The developed markets contribution of your current investment ( ${ ( developedMarketsValueRatio * 100 ) . toPrecision ( 3 ) } %) is within the range of ${ (
evaluation : this.i18nService.getTranslation ( {
ruleSettings . thresholdMin * 100
id : 'rule.economicMarketClusterRiskDevelopedMarkets.true' ,
) . toPrecision (
languageCode : this.getLanguageCode ( ) ,
3
placeholders : {
) } % and $ { ( ruleSettings . thresholdMax * 100 ) . toPrecision ( 3 ) } % ` ,
developedMarketsValueRatio : (
developedMarketsValueRatio * 100
) . toPrecision ( 3 ) ,
thresholdMin : ( ruleSettings . thresholdMin * 100 ) . toPrecision ( 3 ) ,
thresholdMax : ( ruleSettings . thresholdMax * 100 ) . toPrecision ( 3 )
}
} ) ,
value : true
value : true
} ;
} ;
}
}
public getCategoryName() {
public getCategoryName() {
return 'Economic Market Cluster Risk' ; // TODO: Replace hardcoded text with i18n translation
return this . i18nService . getTranslation ( {
id : 'rule.economicMarketClusterRisk.category' ,
languageCode : this.getLanguageCode ( )
} ) ;
}
}
public getConfiguration() {
public getConfiguration() {
@ -71,7 +98,10 @@ export class EconomicMarketClusterRiskDevelopedMarkets extends Rule<Settings> {
}
}
public getName() {
public getName() {
return 'Developed Markets' ;
return this . i18nService . getTranslation ( {
id : 'rule.economicMarketClusterRiskDevelopedMarkets' ,
languageCode : this.getLanguageCode ( )
} ) ;
}
}
public getSettings ( { baseCurrency , xRayRules } : UserSettings ) : Settings {
public getSettings ( { baseCurrency , xRayRules } : UserSettings ) : Settings {