Browse Source

Refactoring

pull/2948/head
Thomas Kaul 2 years ago
parent
commit
29f72a93f2
  1. 51
      apps/api/src/app/portfolio/portfolio-calculator.ts
  2. 4
      libs/common/src/lib/interfaces/symbol-metrics.interface.ts

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

@ -258,8 +258,8 @@ export class PortfolioCalculator {
[symbol: string]: { [symbol: string]: {
currentValues: { [date: string]: Big }; currentValues: { [date: string]: Big };
currentValuesWithCurrencyEffect: { [date: string]: Big }; currentValuesWithCurrencyEffect: { [date: string]: Big };
investmentValues: { [date: string]: Big }; investmentValuesAccumulated: { [date: string]: Big };
investmentValuesWithCurrencyEffect: { [date: string]: Big }; investmentValuesAccumulatedWithCurrencyEffect: { [date: string]: Big };
netPerformanceValues: { [date: string]: Big }; netPerformanceValues: { [date: string]: Big };
netPerformanceValuesWithCurrencyEffect: { [date: string]: Big }; netPerformanceValuesWithCurrencyEffect: { [date: string]: Big };
timeWeightedInvestmentValues: { [date: string]: Big }; timeWeightedInvestmentValues: { [date: string]: Big };
@ -272,8 +272,8 @@ export class PortfolioCalculator {
const { const {
currentValues, currentValues,
currentValuesWithCurrencyEffect, currentValuesWithCurrencyEffect,
investmentValues, investmentValuesAccumulated,
investmentValuesWithCurrencyEffect, investmentValuesAccumulatedWithCurrencyEffect,
netPerformanceValues, netPerformanceValues,
netPerformanceValuesWithCurrencyEffect, netPerformanceValuesWithCurrencyEffect,
timeWeightedInvestmentValues, timeWeightedInvestmentValues,
@ -290,11 +290,21 @@ export class PortfolioCalculator {
isChartMode: true isChartMode: true
}); });
console.log(symbol);
for (const date of Object.keys(investmentValuesAccumulated)) {
console.log(date, investmentValuesAccumulated[date].toNumber());
}
console.log('---');
for (const date of Object.keys(transactionValues)) {
console.log(date, transactionValues[date].toNumber());
}
console.log('===');
valuesBySymbol[symbol] = { valuesBySymbol[symbol] = {
currentValues, currentValues,
currentValuesWithCurrencyEffect, currentValuesWithCurrencyEffect,
investmentValues, investmentValuesAccumulated,
investmentValuesWithCurrencyEffect, investmentValuesAccumulatedWithCurrencyEffect,
netPerformanceValues, netPerformanceValues,
netPerformanceValuesWithCurrencyEffect, netPerformanceValuesWithCurrencyEffect,
timeWeightedInvestmentValues, timeWeightedInvestmentValues,
@ -317,14 +327,15 @@ export class PortfolioCalculator {
new Big(0); new Big(0);
const investmentValue = const investmentValue =
symbolValues.investmentValues?.[dateString] ?? new Big(0); symbolValues.investmentValuesAccumulated?.[dateString] ?? new Big(0);
const transactionValue = const transactionValue =
symbolValues.transactionValues?.[dateString] ?? new Big(0); symbolValues.transactionValues?.[dateString] ?? new Big(0);
const investmentValueWithCurrencyEffect = const investmentValueWithCurrencyEffect =
symbolValues.investmentValuesWithCurrencyEffect?.[dateString] ?? symbolValues.investmentValuesAccumulatedWithCurrencyEffect?.[
new Big(0); dateString
] ?? new Big(0);
const netPerformanceValue = const netPerformanceValue =
symbolValues.netPerformanceValues?.[dateString] ?? new Big(0); symbolValues.netPerformanceValues?.[dateString] ?? new Big(0);
@ -928,8 +939,10 @@ export class PortfolioCalculator {
let initialValueWithCurrencyEffect: Big; let initialValueWithCurrencyEffect: Big;
let investmentAtStartDate: Big; let investmentAtStartDate: Big;
let investmentAtStartDateWithCurrencyEffect: Big; let investmentAtStartDateWithCurrencyEffect: Big;
const investmentValues: { [date: string]: Big } = {}; const investmentValuesAccumulated: { [date: string]: Big } = {};
const investmentValuesWithCurrencyEffect: { [date: string]: Big } = {}; const investmentValuesAccumulatedWithCurrencyEffect: {
[date: string]: Big;
} = {};
let lastAveragePrice = new Big(0); let lastAveragePrice = new Big(0);
let lastAveragePriceWithCurrencyEffect = new Big(0); let lastAveragePriceWithCurrencyEffect = new Big(0);
const netPerformanceValues: { [date: string]: Big } = {}; const netPerformanceValues: { [date: string]: Big } = {};
@ -971,8 +984,8 @@ export class PortfolioCalculator {
hasErrors: false, hasErrors: false,
initialValue: new Big(0), initialValue: new Big(0),
initialValueWithCurrencyEffect: new Big(0), initialValueWithCurrencyEffect: new Big(0),
investmentValues: {}, investmentValuesAccumulated: {},
investmentValuesWithCurrencyEffect: {}, investmentValuesAccumulatedWithCurrencyEffect: {},
netPerformance: new Big(0), netPerformance: new Big(0),
netPerformancePercentage: new Big(0), netPerformancePercentage: new Big(0),
netPerformancePercentageWithCurrencyEffect: new Big(0), netPerformancePercentageWithCurrencyEffect: new Big(0),
@ -1011,8 +1024,8 @@ export class PortfolioCalculator {
hasErrors: true, hasErrors: true,
initialValue: new Big(0), initialValue: new Big(0),
initialValueWithCurrencyEffect: new Big(0), initialValueWithCurrencyEffect: new Big(0),
investmentValues: {}, investmentValuesAccumulated: {},
investmentValuesWithCurrencyEffect: {}, investmentValuesAccumulatedWithCurrencyEffect: {},
netPerformance: new Big(0), netPerformance: new Big(0),
netPerformancePercentage: new Big(0), netPerformancePercentage: new Big(0),
netPerformancePercentageWithCurrencyEffect: new Big(0), netPerformancePercentageWithCurrencyEffect: new Big(0),
@ -1405,9 +1418,9 @@ export class PortfolioCalculator {
feesWithCurrencyEffect.minus(feesAtStartDateWithCurrencyEffect) feesWithCurrencyEffect.minus(feesAtStartDateWithCurrencyEffect)
); );
investmentValues[order.date] = totalInvestment; investmentValuesAccumulated[order.date] = totalInvestment;
investmentValuesWithCurrencyEffect[order.date] = investmentValuesAccumulatedWithCurrencyEffect[order.date] =
totalInvestmentWithCurrencyEffect; totalInvestmentWithCurrencyEffect;
timeWeightedInvestmentValues[order.date] = timeWeightedInvestmentValues[order.date] =
@ -1571,8 +1584,8 @@ export class PortfolioCalculator {
grossPerformancePercentageWithCurrencyEffect, grossPerformancePercentageWithCurrencyEffect,
initialValue, initialValue,
initialValueWithCurrencyEffect, initialValueWithCurrencyEffect,
investmentValues, investmentValuesAccumulated,
investmentValuesWithCurrencyEffect, investmentValuesAccumulatedWithCurrencyEffect,
netPerformancePercentage, netPerformancePercentage,
netPerformancePercentageWithCurrencyEffect, netPerformancePercentageWithCurrencyEffect,
netPerformanceValues, netPerformanceValues,

4
libs/common/src/lib/interfaces/symbol-metrics.interface.ts

@ -14,10 +14,10 @@ export interface SymbolMetrics {
hasErrors: boolean; hasErrors: boolean;
initialValue: Big; initialValue: Big;
initialValueWithCurrencyEffect: Big; initialValueWithCurrencyEffect: Big;
investmentValues: { investmentValuesAccumulated: {
[date: string]: Big; [date: string]: Big;
}; };
investmentValuesWithCurrencyEffect: { investmentValuesAccumulatedWithCurrencyEffect: {
[date: string]: Big; [date: string]: Big;
}; };
netPerformance: Big; netPerformance: Big;

Loading…
Cancel
Save