Browse Source

Various improvements

pull/2400/head
Thomas 2 years ago
parent
commit
d9cb1c124b
  1. 71
      apps/api/src/app/portfolio/portfolio.service.ts
  2. 15
      apps/api/src/models/rules/emergency-fund/emergency-fund-setup.ts
  3. 4
      apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts
  4. 16
      apps/client/src/app/pages/portfolio/fire/fire-page.html

71
apps/api/src/app/portfolio/portfolio.service.ts

@ -1215,12 +1215,6 @@ export class PortfolioService {
userId
});
if (isEmpty(orders)) {
return {
rules: {}
};
}
const portfolioCalculator = new PortfolioCalculator({
currency: userCurrency,
currentRateService: this.currentRateService,
@ -1229,7 +1223,9 @@ export class PortfolioService {
portfolioCalculator.setTransactionPoints(transactionPoints);
const portfolioStart = parseDate(transactionPoints[0].date);
const portfolioStart = parseDate(
transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT)
);
const currentPositions =
await portfolioCalculator.getCurrentPositions(portfolioStart);
@ -1250,37 +1246,48 @@ export class PortfolioService {
userId
});
const userSettings = <UserSettings>this.request.user.Settings.settings;
return {
rules: {
accountClusterRisk: await this.rulesService.evaluate(
[
new AccountClusterRiskCurrentInvestment(
this.exchangeRateDataService,
accounts
accountClusterRisk: isEmpty(orders)
? undefined
: await this.rulesService.evaluate(
[
new AccountClusterRiskCurrentInvestment(
this.exchangeRateDataService,
accounts
),
new AccountClusterRiskSingleAccount(
this.exchangeRateDataService,
accounts
)
],
userSettings
),
new AccountClusterRiskSingleAccount(
this.exchangeRateDataService,
accounts
)
],
<UserSettings>this.request.user.Settings.settings
),
currencyClusterRisk: await this.rulesService.evaluate(
[
new CurrencyClusterRiskBaseCurrencyCurrentInvestment(
this.exchangeRateDataService,
positions
currencyClusterRisk: isEmpty(orders)
? undefined
: await this.rulesService.evaluate(
[
new CurrencyClusterRiskBaseCurrencyCurrentInvestment(
this.exchangeRateDataService,
positions
),
new CurrencyClusterRiskCurrentInvestment(
this.exchangeRateDataService,
positions
)
],
userSettings
),
new CurrencyClusterRiskCurrentInvestment(
emergencyFund: await this.rulesService.evaluate(
[
new EmergencyFundSetup(
this.exchangeRateDataService,
positions
userSettings.emergencyFund
)
],
<UserSettings>this.request.user.Settings.settings
),
emergencyFund: await this.rulesService.evaluate(
[new EmergencyFundSetup(this.exchangeRateDataService)],
<UserSettings>this.request.user.Settings.settings
userSettings
),
fees: await this.rulesService.evaluate(
[
@ -1290,7 +1297,7 @@ export class PortfolioService {
this.getFees({ userCurrency, activities: orders }).toNumber()
)
],
<UserSettings>this.request.user.Settings.settings
userSettings
)
}
};

15
apps/api/src/models/rules/emergency-fund/emergency-fund-setup.ts

@ -4,24 +4,29 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-
import { UserSettings } from '@ghostfolio/common/interfaces';
export class EmergencyFundSetup extends Rule<Settings> {
private emergencyFund: number;
public constructor(
protected exchangeRateDataService: ExchangeRateDataService
protected exchangeRateDataService: ExchangeRateDataService,
emergencyFund: number
) {
super(exchangeRateDataService, {
name: 'Emergency Fund: Set up'
});
this.emergencyFund = emergencyFund;
}
public evaluate(ruleSettings: Settings) {
if (ruleSettings.threshold > 0) {
if (this.emergencyFund > ruleSettings.threshold) {
return {
evaluation: `You have set up an emergency fund`,
evaluation: 'An emergency fund has been set up',
value: true
};
}
return {
evaluation: `You have not set up an emergency fund yet`,
evaluation: 'No emergency fund has been set up',
value: false
};
}
@ -30,7 +35,7 @@ export class EmergencyFundSetup extends Rule<Settings> {
return {
baseCurrency: aUserSettings.baseCurrency,
isActive: true,
threshold: aUserSettings.emergencyFund
threshold: 0
};
}
}

4
apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts

@ -21,7 +21,9 @@ export class FeeRatioInitialInvestment extends Rule<Settings> {
}
public evaluate(ruleSettings: Settings) {
const feeRatio = this.fees / this.totalInvestment;
const feeRatio = this.totalInvestment
? this.fees / this.totalInvestment
: 0;
if (feeRatio > ruleSettings.threshold) {
return {

16
apps/client/src/app/pages/portfolio/fire/fire-page.html

@ -108,7 +108,7 @@
</p>
<div class="mb-4">
<h4 class="align-items-center d-flex m-0">
<span i18n>Currency Cluster Risks</span
<span i18n>Emergency Fund</span
><gf-premium-indicator
*ngIf="user?.subscription?.type === 'Basic'"
class="ml-1"
@ -116,12 +116,12 @@
</h4>
<gf-rules
[hasPermissionToCreateOrder]="hasPermissionToCreateOrder"
[rules]="currencyClusterRiskRules"
[rules]="emergencyFundRules"
></gf-rules>
</div>
<div class="mb-4">
<h4 class="align-items-center d-flex m-0">
<span i18n>Account Cluster Risks</span
<span i18n>Currency Cluster Risks</span
><gf-premium-indicator
*ngIf="user?.subscription?.type === 'Basic'"
class="ml-1"
@ -129,12 +129,12 @@
</h4>
<gf-rules
[hasPermissionToCreateOrder]="hasPermissionToCreateOrder"
[rules]="accountClusterRiskRules"
[rules]="currencyClusterRiskRules"
></gf-rules>
</div>
<div class="mb-4">
<h4 class="align-items-center d-flex m-0">
<span i18n>Fees</span
<span i18n>Account Cluster Risks</span
><gf-premium-indicator
*ngIf="user?.subscription?.type === 'Basic'"
class="ml-1"
@ -142,12 +142,12 @@
</h4>
<gf-rules
[hasPermissionToCreateOrder]="hasPermissionToCreateOrder"
[rules]="feeRules"
[rules]="accountClusterRiskRules"
></gf-rules>
</div>
<div>
<h4 class="align-items-center d-flex m-0">
<span i18n>Emergency Fund</span
<span i18n>Fees</span
><gf-premium-indicator
*ngIf="user?.subscription?.type === 'Basic'"
class="ml-1"
@ -155,7 +155,7 @@
</h4>
<gf-rules
[hasPermissionToCreateOrder]="hasPermissionToCreateOrder"
[rules]="emergencyFundRules"
[rules]="feeRules"
></gf-rules>
</div>
</div>

Loading…
Cancel
Save