Browse Source

Various improvements

pull/2400/head
Thomas 2 years ago
parent
commit
d9cb1c124b
  1. 35
      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

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

@ -1215,12 +1215,6 @@ export class PortfolioService {
userId userId
}); });
if (isEmpty(orders)) {
return {
rules: {}
};
}
const portfolioCalculator = new PortfolioCalculator({ const portfolioCalculator = new PortfolioCalculator({
currency: userCurrency, currency: userCurrency,
currentRateService: this.currentRateService, currentRateService: this.currentRateService,
@ -1229,7 +1223,9 @@ export class PortfolioService {
portfolioCalculator.setTransactionPoints(transactionPoints); portfolioCalculator.setTransactionPoints(transactionPoints);
const portfolioStart = parseDate(transactionPoints[0].date); const portfolioStart = parseDate(
transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT)
);
const currentPositions = const currentPositions =
await portfolioCalculator.getCurrentPositions(portfolioStart); await portfolioCalculator.getCurrentPositions(portfolioStart);
@ -1250,9 +1246,13 @@ export class PortfolioService {
userId userId
}); });
const userSettings = <UserSettings>this.request.user.Settings.settings;
return { return {
rules: { rules: {
accountClusterRisk: await this.rulesService.evaluate( accountClusterRisk: isEmpty(orders)
? undefined
: await this.rulesService.evaluate(
[ [
new AccountClusterRiskCurrentInvestment( new AccountClusterRiskCurrentInvestment(
this.exchangeRateDataService, this.exchangeRateDataService,
@ -1263,9 +1263,11 @@ export class PortfolioService {
accounts accounts
) )
], ],
<UserSettings>this.request.user.Settings.settings userSettings
), ),
currencyClusterRisk: await this.rulesService.evaluate( currencyClusterRisk: isEmpty(orders)
? undefined
: await this.rulesService.evaluate(
[ [
new CurrencyClusterRiskBaseCurrencyCurrentInvestment( new CurrencyClusterRiskBaseCurrencyCurrentInvestment(
this.exchangeRateDataService, this.exchangeRateDataService,
@ -1276,11 +1278,16 @@ export class PortfolioService {
positions positions
) )
], ],
<UserSettings>this.request.user.Settings.settings userSettings
), ),
emergencyFund: await this.rulesService.evaluate( emergencyFund: await this.rulesService.evaluate(
[new EmergencyFundSetup(this.exchangeRateDataService)], [
<UserSettings>this.request.user.Settings.settings new EmergencyFundSetup(
this.exchangeRateDataService,
userSettings.emergencyFund
)
],
userSettings
), ),
fees: await this.rulesService.evaluate( fees: await this.rulesService.evaluate(
[ [
@ -1290,7 +1297,7 @@ export class PortfolioService {
this.getFees({ userCurrency, activities: orders }).toNumber() 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'; import { UserSettings } from '@ghostfolio/common/interfaces';
export class EmergencyFundSetup extends Rule<Settings> { export class EmergencyFundSetup extends Rule<Settings> {
private emergencyFund: number;
public constructor( public constructor(
protected exchangeRateDataService: ExchangeRateDataService protected exchangeRateDataService: ExchangeRateDataService,
emergencyFund: number
) { ) {
super(exchangeRateDataService, { super(exchangeRateDataService, {
name: 'Emergency Fund: Set up' name: 'Emergency Fund: Set up'
}); });
this.emergencyFund = emergencyFund;
} }
public evaluate(ruleSettings: Settings) { public evaluate(ruleSettings: Settings) {
if (ruleSettings.threshold > 0) { if (this.emergencyFund > ruleSettings.threshold) {
return { return {
evaluation: `You have set up an emergency fund`, evaluation: 'An emergency fund has been set up',
value: true value: true
}; };
} }
return { return {
evaluation: `You have not set up an emergency fund yet`, evaluation: 'No emergency fund has been set up',
value: false value: false
}; };
} }
@ -30,7 +35,7 @@ export class EmergencyFundSetup extends Rule<Settings> {
return { return {
baseCurrency: aUserSettings.baseCurrency, baseCurrency: aUserSettings.baseCurrency,
isActive: true, 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) { public evaluate(ruleSettings: Settings) {
const feeRatio = this.fees / this.totalInvestment; const feeRatio = this.totalInvestment
? this.fees / this.totalInvestment
: 0;
if (feeRatio > ruleSettings.threshold) { if (feeRatio > ruleSettings.threshold) {
return { return {

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

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

Loading…
Cancel
Save