Browse Source

fix(api): calculate from startDate to endDate

pull/5650/head
KenTandrian 3 weeks ago
parent
commit
c15c3d0fbd
  1. 12
      apps/api/src/app/portfolio/portfolio.service.ts

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

@ -682,7 +682,9 @@ export class PortfolioService {
if (filters?.length === 0 || isFilteredByAccount || isFilteredByCash) { if (filters?.length === 0 || isFilteredByAccount || isFilteredByCash) {
const cashPositions = this.getCashPositions({ const cashPositions = this.getCashPositions({
cashDetails, cashDetails,
endDate,
exchangeRatesByCurrency, exchangeRatesByCurrency,
startDate,
userCurrency, userCurrency,
value: filteredValueInBaseCurrency value: filteredValueInBaseCurrency
}); });
@ -708,7 +710,9 @@ export class PortfolioService {
) { ) {
const emergencyFundCashPositions = this.getCashPositions({ const emergencyFundCashPositions = this.getCashPositions({
cashDetails, cashDetails,
endDate,
exchangeRatesByCurrency, exchangeRatesByCurrency,
startDate,
userCurrency, userCurrency,
value: filteredValueInBaseCurrency value: filteredValueInBaseCurrency
}); });
@ -1644,12 +1648,16 @@ export class PortfolioService {
private getCashPositions({ private getCashPositions({
cashDetails, cashDetails,
endDate,
exchangeRatesByCurrency, exchangeRatesByCurrency,
startDate,
userCurrency, userCurrency,
value value
}: { }: {
cashDetails: CashDetails; cashDetails: CashDetails;
endDate: Date;
exchangeRatesByCurrency: ExchangeRatesByCurrency; exchangeRatesByCurrency: ExchangeRatesByCurrency;
startDate: Date;
userCurrency: string; userCurrency: string;
value: Big; value: Big;
}) { }) {
@ -1676,10 +1684,10 @@ export class PortfolioService {
// Calculate the performance of the cash position including currency effects // Calculate the performance of the cash position including currency effects
const netPerformanceWithCurrencyEffect = new Big(account.balance) const netPerformanceWithCurrencyEffect = new Big(account.balance)
.mul(exchangeRates?.[format(new Date(), DATE_FORMAT)] ?? 1) .mul(exchangeRates?.[format(endDate, DATE_FORMAT)] ?? 1)
.minus( .minus(
new Big(account.balance).mul( new Big(account.balance).mul(
exchangeRates?.[format(account.createdAt, DATE_FORMAT)] ?? 1 exchangeRates?.[format(startDate, DATE_FORMAT)] ?? 1
) )
) )
.toNumber(); .toNumber();

Loading…
Cancel
Save