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

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

@ -1171,9 +1171,9 @@ export class PortfolioService {
totalInvestment, totalInvestment,
currentNetWorth: netWorth, currentNetWorth: netWorth,
currentValueInBaseCurrency: valueWithCurrencyEffect, currentValueInBaseCurrency: valueWithCurrencyEffect,
netPerformancePercentage: netPerformanceInPercentage / 100, // TODO netPerformancePercentage: netPerformanceInPercentage,
netPerformancePercentageWithCurrencyEffect: 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})`, borderColor: `rgb(${primaryColorRgb.r}, ${primaryColorRgb.g}, ${primaryColorRgb.b})`,
borderWidth: 2, borderWidth: 2,
data: this.performanceDataItems.map(({ date, value }) => { data: this.performanceDataItems.map(({ date, value }) => {
return { x: parseDate(date).getTime(), y: value }; return { x: parseDate(date).getTime(), y: value * 100 };
}), }),
label: $localize`Portfolio` 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="row">
<div class="col-6 mb-3"> <div class="col-6 mb-3">
@if ( <gf-value
SymbolProfile?.currency && i18n
data.baseCurrency !== SymbolProfile?.currency size="medium"
) { [colorizeSign]="true"
<gf-value [isCurrency]="true"
i18n [locale]="data.locale"
size="medium" [precision]="netPerformanceWithCurrencyEffectPrecision"
[colorizeSign]="true" [unit]="data.baseCurrency"
[isCurrency]="true" [value]="netPerformanceWithCurrencyEffect"
[locale]="data.locale" >
[precision]="netPerformanceWithCurrencyEffectPrecision" @if (
[unit]="data.baseCurrency" SymbolProfile?.currency &&
[value]="netPerformanceWithCurrencyEffect" data.baseCurrency !== SymbolProfile?.currency
>Change with currency effect</gf-value ) {
> Change with currency effect
} @else { } @else {
<gf-value Change
i18n }
size="medium" </gf-value>
[colorizeSign]="true"
[isCurrency]="true"
[locale]="data.locale"
[precision]="netPerformancePrecision"
[unit]="data.baseCurrency"
[value]="netPerformance"
>Change</gf-value
>
}
</div> </div>
<div class="col-6 mb-3"> <div class="col-6 mb-3">
@if ( <gf-value
SymbolProfile?.currency && i18n
data.baseCurrency !== SymbolProfile?.currency size="medium"
) { [colorizeSign]="true"
<gf-value [isPercent]="true"
i18n [locale]="data.locale"
size="medium" [value]="netPerformancePercentWithCurrencyEffect"
[colorizeSign]="true" >
[isPercent]="true" @if (
[locale]="data.locale" SymbolProfile?.currency &&
[value]="netPerformancePercentWithCurrencyEffect" data.baseCurrency !== SymbolProfile?.currency
>Performance with currency effect</gf-value ) {
> Performance with currency effect
} @else { } @else {
<gf-value Performance
i18n }
size="medium" </gf-value>
[colorizeSign]="true"
[isPercent]="true"
[locale]="data.locale"
[value]="netPerformancePercent"
>Performance</gf-value
>
}
</div> </div>
<div class="col-6 mb-3"> <div class="col-6 mb-3">
<gf-value <gf-value

Loading…
Cancel
Save