Browse Source

Add Performance Log and Correct var assignement

pull/5027/head
Daniel Devaud 1 year ago
parent
commit
35237ecf95
  1. 13
      apps/api/src/app/portfolio/calculator/constantPortfolioReturn/portfolio-calculator.ts

13
apps/api/src/app/portfolio/calculator/constantPortfolioReturn/portfolio-calculator.ts

@ -1,3 +1,4 @@
import { LogPerformance } from '@ghostfolio/api/aop/logging.interceptor';
import { import {
getFactor, getFactor,
getInterval getInterval
@ -17,6 +18,7 @@ export class CPRPortfolioCalculator extends TWRPortfolioCalculator {
private holdings: { [date: string]: { [symbol: string]: Big } } = {}; private holdings: { [date: string]: { [symbol: string]: Big } } = {};
private holdingCurrencies: { [symbol: string]: string } = {}; private holdingCurrencies: { [symbol: string]: string } = {};
@LogPerformance
public async getChart({ public async getChart({
dateRange = 'max', dateRange = 'max',
withDataDecimation = true, withDataDecimation = true,
@ -57,9 +59,9 @@ export class CPRPortfolioCalculator extends TWRPortfolioCalculator {
); );
if (timeWeightedItem) { if (timeWeightedItem) {
item.timeWeightedPerformance = item.timeWeightedPerformance =
timeWeightedItem.timeWeightedPerformance; timeWeightedItem.netPerformanceInPercentage;
item.timeWeightedPerformanceWithCurrencyEffect = item.timeWeightedPerformanceWithCurrencyEffect =
timeWeightedItem.timeWeightedPerformanceWithCurrencyEffect; timeWeightedItem.netPerformanceInPercentageWithCurrencyEffect;
} }
return item; return item;
@ -70,6 +72,7 @@ export class CPRPortfolioCalculator extends TWRPortfolioCalculator {
return item; return item;
} }
@LogPerformance
private async getTimeWeightedChartData({ private async getTimeWeightedChartData({
end = new Date(Date.now()), end = new Date(Date.now()),
start, start,
@ -165,6 +168,7 @@ export class CPRPortfolioCalculator extends TWRPortfolioCalculator {
return data; return data;
} }
@LogPerformance
private async handleSingleHolding( private async handleSingleHolding(
previousDate: string, previousDate: string,
holding: string, holding: string,
@ -219,6 +223,7 @@ export class CPRPortfolioCalculator extends TWRPortfolioCalculator {
}; };
} }
@LogPerformance
private getCurrency(symbol: string) { private getCurrency(symbol: string) {
if (!this.holdingCurrencies[symbol]) { if (!this.holdingCurrencies[symbol]) {
this.holdingCurrencies[symbol] = this.activities.find( this.holdingCurrencies[symbol] = this.activities.find(
@ -229,6 +234,7 @@ export class CPRPortfolioCalculator extends TWRPortfolioCalculator {
return this.holdingCurrencies[symbol]; return this.holdingCurrencies[symbol];
} }
@LogPerformance
private getHoldings(start: Date, end: Date) { private getHoldings(start: Date, end: Date) {
if ( if (
this.holdings && this.holdings &&
@ -242,6 +248,7 @@ export class CPRPortfolioCalculator extends TWRPortfolioCalculator {
return this.holdings; return this.holdings;
} }
@LogPerformance
private computeHoldings(start: Date, end: Date) { private computeHoldings(start: Date, end: Date) {
const investmentByDate = this.getInvestmentByDate(); const investmentByDate = this.getInvestmentByDate();
const transactionDates = Object.keys(investmentByDate).sort(); const transactionDates = Object.keys(investmentByDate).sort();
@ -274,6 +281,7 @@ export class CPRPortfolioCalculator extends TWRPortfolioCalculator {
this.holdings = currentHoldings; this.holdings = currentHoldings;
} }
@LogPerformance
private calculateInitialHoldings( private calculateInitialHoldings(
investmentByDate: { [date: string]: PortfolioOrder[] }, investmentByDate: { [date: string]: PortfolioOrder[] },
start: Date, start: Date,
@ -304,6 +312,7 @@ export class CPRPortfolioCalculator extends TWRPortfolioCalculator {
} }
} }
@LogPerformance
private getInvestmentByDate(): { [date: string]: PortfolioOrder[] } { private getInvestmentByDate(): { [date: string]: PortfolioOrder[] } {
return this.activities.reduce((groupedByDate, order) => { return this.activities.reduce((groupedByDate, order) => {
if (!groupedByDate[order.date]) { if (!groupedByDate[order.date]) {

Loading…
Cancel
Save