Browse Source

Improvements

pull/3393/head
Reto Kaul 1 year ago
parent
commit
35a591f6fe
  1. 29
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  2. 4
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 2
      apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts
  4. 88
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html

29
apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

@ -10,7 +10,12 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-
import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces';
import { getIntervalFromDateRange } from '@ghostfolio/common/calculation-helper';
import { MAX_CHART_ITEMS } from '@ghostfolio/common/config';
import { DATE_FORMAT, getSum, parseDate } from '@ghostfolio/common/helper';
import {
DATE_FORMAT,
getSum,
parseDate,
resetHours
} from '@ghostfolio/common/helper';
import {
AssetProfileIdentifier,
DataProviderInfo,
@ -32,7 +37,6 @@ import {
format,
isAfter,
isBefore,
max,
min,
subDays
} from 'date-fns';
@ -398,7 +402,7 @@ export abstract class PortfolioCalculator {
? (netPerformancePercentage ?? null)
: null,
netPerformancePercentageWithCurrencyEffect: !hasErrors
? (netPerformancePercentageWithCurrencyEffect ?? null)
? (netPerformancePercentageWithCurrencyEffectMap['max'] ?? null)
: null,
netPerformancePercentageWithCurrencyEffectMap: !hasErrors
? (netPerformancePercentageWithCurrencyEffectMap ?? null)
@ -554,7 +558,6 @@ export abstract class PortfolioCalculator {
? 0
: totalNetPerformanceValue
.div(totalTimeWeightedInvestmentValue)
.mul(100)
.toNumber();
const netPerformanceInPercentageWithCurrencyEffect =
@ -562,7 +565,6 @@ export abstract class PortfolioCalculator {
? 0
: totalNetPerformanceValueWithCurrencyEffect
.div(totalTimeWeightedInvestmentValueWithCurrencyEffect)
.mul(100)
.toNumber();
return {
@ -692,10 +694,9 @@ export abstract class PortfolioCalculator {
let totalInvestmentValuesWithCurrencyEffect: number[] = [];
for (let historicalDataItem of historicalData) {
if (
!isBefore(parseDate(historicalDataItem.date), subDays(start, 1)) &&
!isAfter(parseDate(historicalDataItem.date), end)
) {
const date = resetHours(parseDate(historicalDataItem.date));
if (!isBefore(date, start) && !isAfter(date, end)) {
if (!isNumber(netPerformanceAtStartDate)) {
netPerformanceAtStartDate = historicalDataItem.netPerformance;
@ -706,6 +707,9 @@ export abstract class PortfolioCalculator {
historicalDataItem.netPerformanceInPercentageWithCurrencyEffect;
}
const netPerformanceSinceStartDate =
historicalDataItem.netPerformance - netPerformanceAtStartDate;
const netPerformanceWithCurrencyEffectSinceStartDate =
historicalDataItem.netPerformanceWithCurrencyEffect -
netPerformanceWithCurrencyEffectAtStartDate;
@ -730,10 +734,11 @@ export abstract class PortfolioCalculator {
historicalDataItem.netPerformance - netPerformanceAtStartDate,
netPerformanceWithCurrencyEffect:
netPerformanceWithCurrencyEffectSinceStartDate,
netPerformanceInPercentage:
netPerformanceSinceStartDate / timeWeightedInvestmentValue,
netPerformanceInPercentageWithCurrencyEffect:
(netPerformanceWithCurrencyEffectSinceStartDate /
timeWeightedInvestmentValue) *
100,
netPerformanceWithCurrencyEffectSinceStartDate /
timeWeightedInvestmentValue,
// TODO: Add net worth with valuables
// netWorth: totalCurrentValueWithCurrencyEffect
// .plus(totalAccountBalanceWithCurrencyEffect)

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

@ -1171,9 +1171,9 @@ export class PortfolioService {
totalInvestment,
currentNetWorth: netWorth,
currentValueInBaseCurrency: valueWithCurrencyEffect,
netPerformancePercentage: netPerformanceInPercentage / 100, // TODO
netPerformancePercentage: netPerformanceInPercentage,
netPerformancePercentageWithCurrencyEffect:
netPerformanceInPercentageWithCurrencyEffect / 100 // TODO
netPerformanceInPercentageWithCurrencyEffect
}
};
}

2
apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts

@ -111,7 +111,7 @@ export class BenchmarkComparatorComponent implements OnChanges, OnDestroy {
borderColor: `rgb(${primaryColorRgb.r}, ${primaryColorRgb.g}, ${primaryColorRgb.b})`,
borderWidth: 2,
data: this.performanceDataItems.map(({ date, value }) => {
return { x: parseDate(date).getTime(), y: value };
return { x: parseDate(date).getTime(), y: value * 100 };
}),
label: $localize`Portfolio`
},

88
apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html

@ -37,60 +37,44 @@
<div class="row">
<div class="col-6 mb-3">
@if (
SymbolProfile?.currency &&
data.baseCurrency !== SymbolProfile?.currency
) {
<gf-value
i18n
size="medium"
[colorizeSign]="true"
[isCurrency]="true"
[locale]="data.locale"
[precision]="netPerformanceWithCurrencyEffectPrecision"
[unit]="data.baseCurrency"
[value]="netPerformanceWithCurrencyEffect"
>Change with currency effect</gf-value
>
} @else {
<gf-value
i18n
size="medium"
[colorizeSign]="true"
[isCurrency]="true"
[locale]="data.locale"
[precision]="netPerformancePrecision"
[unit]="data.baseCurrency"
[value]="netPerformance"
>Change</gf-value
>
}
<gf-value
i18n
size="medium"
[colorizeSign]="true"
[isCurrency]="true"
[locale]="data.locale"
[precision]="netPerformanceWithCurrencyEffectPrecision"
[unit]="data.baseCurrency"
[value]="netPerformanceWithCurrencyEffect"
>
@if (
SymbolProfile?.currency &&
data.baseCurrency !== SymbolProfile?.currency
) {
Change with currency effect
} @else {
Change
}
</gf-value>
</div>
<div class="col-6 mb-3">
@if (
SymbolProfile?.currency &&
data.baseCurrency !== SymbolProfile?.currency
) {
<gf-value
i18n
size="medium"
[colorizeSign]="true"
[isPercent]="true"
[locale]="data.locale"
[value]="netPerformancePercentWithCurrencyEffect"
>Performance with currency effect</gf-value
>
} @else {
<gf-value
i18n
size="medium"
[colorizeSign]="true"
[isPercent]="true"
[locale]="data.locale"
[value]="netPerformancePercent"
>Performance</gf-value
>
}
<gf-value
i18n
size="medium"
[colorizeSign]="true"
[isPercent]="true"
[locale]="data.locale"
[value]="netPerformancePercentWithCurrencyEffect"
>
@if (
SymbolProfile?.currency &&
data.baseCurrency !== SymbolProfile?.currency
) {
Performance with currency effect
} @else {
Performance
}
</gf-value>
</div>
<div class="col-6 mb-3">
<gf-value

Loading…
Cancel
Save