|
|
@ -235,7 +235,7 @@ export class PortfolioCalculator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const netPerformanceValuesBySymbol: {
|
|
|
|
const currentValuesBySymbol: {
|
|
|
|
[symbol: string]: { [date: string]: Big };
|
|
|
|
[symbol: string]: { [date: string]: Big };
|
|
|
|
} = {};
|
|
|
|
} = {};
|
|
|
|
|
|
|
|
|
|
|
@ -247,21 +247,31 @@ export class PortfolioCalculator {
|
|
|
|
[symbol: string]: { [date: string]: Big };
|
|
|
|
[symbol: string]: { [date: string]: Big };
|
|
|
|
} = {};
|
|
|
|
} = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const netPerformanceValuesBySymbol: {
|
|
|
|
|
|
|
|
[symbol: string]: { [date: string]: Big };
|
|
|
|
|
|
|
|
} = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const totalCurrentValues: { [date: string]: Big } = {};
|
|
|
|
const totalNetPerformanceValues: { [date: string]: Big } = {};
|
|
|
|
const totalNetPerformanceValues: { [date: string]: Big } = {};
|
|
|
|
const totalInvestmentValues: { [date: string]: Big } = {};
|
|
|
|
const totalInvestmentValues: { [date: string]: Big } = {};
|
|
|
|
const maxTotalInvestmentValues: { [date: string]: Big } = {};
|
|
|
|
const maxTotalInvestmentValues: { [date: string]: Big } = {};
|
|
|
|
|
|
|
|
|
|
|
|
for (const symbol of Object.keys(symbols)) {
|
|
|
|
for (const symbol of Object.keys(symbols)) {
|
|
|
|
const { investmentValues, maxInvestmentValues, netPerformanceValues } =
|
|
|
|
const {
|
|
|
|
this.getSymbolMetrics({
|
|
|
|
currentValues,
|
|
|
|
end,
|
|
|
|
investmentValues,
|
|
|
|
marketSymbolMap,
|
|
|
|
maxInvestmentValues,
|
|
|
|
start,
|
|
|
|
netPerformanceValues
|
|
|
|
step,
|
|
|
|
} = this.getSymbolMetrics({
|
|
|
|
symbol,
|
|
|
|
end,
|
|
|
|
isChartMode: true
|
|
|
|
marketSymbolMap,
|
|
|
|
});
|
|
|
|
start,
|
|
|
|
|
|
|
|
step,
|
|
|
|
|
|
|
|
symbol,
|
|
|
|
|
|
|
|
isChartMode: true
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentValuesBySymbol[symbol] = currentValues;
|
|
|
|
netPerformanceValuesBySymbol[symbol] = netPerformanceValues;
|
|
|
|
netPerformanceValuesBySymbol[symbol] = netPerformanceValues;
|
|
|
|
investmentValuesBySymbol[symbol] = investmentValues;
|
|
|
|
investmentValuesBySymbol[symbol] = investmentValues;
|
|
|
|
maxInvestmentValuesBySymbol[symbol] = maxInvestmentValues;
|
|
|
|
maxInvestmentValuesBySymbol[symbol] = maxInvestmentValues;
|
|
|
@ -271,6 +281,15 @@ export class PortfolioCalculator {
|
|
|
|
const dateString = format(currentDate, DATE_FORMAT);
|
|
|
|
const dateString = format(currentDate, DATE_FORMAT);
|
|
|
|
|
|
|
|
|
|
|
|
for (const symbol of Object.keys(netPerformanceValuesBySymbol)) {
|
|
|
|
for (const symbol of Object.keys(netPerformanceValuesBySymbol)) {
|
|
|
|
|
|
|
|
totalCurrentValues[dateString] =
|
|
|
|
|
|
|
|
totalCurrentValues[dateString] ?? new Big(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentValuesBySymbol[symbol]?.[dateString]) {
|
|
|
|
|
|
|
|
totalCurrentValues[dateString] = totalCurrentValues[dateString].add(
|
|
|
|
|
|
|
|
currentValuesBySymbol[symbol][dateString]
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
totalNetPerformanceValues[dateString] =
|
|
|
|
totalNetPerformanceValues[dateString] =
|
|
|
|
totalNetPerformanceValues[dateString] ?? new Big(0);
|
|
|
|
totalNetPerformanceValues[dateString] ?? new Big(0);
|
|
|
|
|
|
|
|
|
|
|
@ -283,15 +302,15 @@ export class PortfolioCalculator {
|
|
|
|
totalInvestmentValues[dateString] =
|
|
|
|
totalInvestmentValues[dateString] =
|
|
|
|
totalInvestmentValues[dateString] ?? new Big(0);
|
|
|
|
totalInvestmentValues[dateString] ?? new Big(0);
|
|
|
|
|
|
|
|
|
|
|
|
maxTotalInvestmentValues[dateString] =
|
|
|
|
|
|
|
|
maxTotalInvestmentValues[dateString] ?? new Big(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (investmentValuesBySymbol[symbol]?.[dateString]) {
|
|
|
|
if (investmentValuesBySymbol[symbol]?.[dateString]) {
|
|
|
|
totalInvestmentValues[dateString] = totalInvestmentValues[
|
|
|
|
totalInvestmentValues[dateString] = totalInvestmentValues[
|
|
|
|
dateString
|
|
|
|
dateString
|
|
|
|
].add(investmentValuesBySymbol[symbol][dateString]);
|
|
|
|
].add(investmentValuesBySymbol[symbol][dateString]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
maxTotalInvestmentValues[dateString] =
|
|
|
|
|
|
|
|
maxTotalInvestmentValues[dateString] ?? new Big(0);
|
|
|
|
|
|
|
|
|
|
|
|
if (maxInvestmentValuesBySymbol[symbol]?.[dateString]) {
|
|
|
|
if (maxInvestmentValuesBySymbol[symbol]?.[dateString]) {
|
|
|
|
maxTotalInvestmentValues[dateString] = maxTotalInvestmentValues[
|
|
|
|
maxTotalInvestmentValues[dateString] = maxTotalInvestmentValues[
|
|
|
|
dateString
|
|
|
|
dateString
|
|
|
@ -313,9 +332,7 @@ export class PortfolioCalculator {
|
|
|
|
netPerformanceInPercentage,
|
|
|
|
netPerformanceInPercentage,
|
|
|
|
netPerformance: totalNetPerformanceValues[date].toNumber(),
|
|
|
|
netPerformance: totalNetPerformanceValues[date].toNumber(),
|
|
|
|
totalInvestment: totalInvestmentValues[date].toNumber(),
|
|
|
|
totalInvestment: totalInvestmentValues[date].toNumber(),
|
|
|
|
value: totalInvestmentValues[date]
|
|
|
|
value: totalCurrentValues[date].toNumber()
|
|
|
|
.plus(totalNetPerformanceValues[date])
|
|
|
|
|
|
|
|
.toNumber()
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -906,12 +923,16 @@ export class PortfolioCalculator {
|
|
|
|
|
|
|
|
|
|
|
|
if (orders.length <= 0) {
|
|
|
|
if (orders.length <= 0) {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
|
|
|
|
currentValues: {},
|
|
|
|
|
|
|
|
grossPerformance: new Big(0),
|
|
|
|
|
|
|
|
grossPerformancePercentage: new Big(0),
|
|
|
|
hasErrors: false,
|
|
|
|
hasErrors: false,
|
|
|
|
initialValue: new Big(0),
|
|
|
|
initialValue: new Big(0),
|
|
|
|
|
|
|
|
investmentValues: {},
|
|
|
|
|
|
|
|
maxInvestmentValues: {},
|
|
|
|
netPerformance: new Big(0),
|
|
|
|
netPerformance: new Big(0),
|
|
|
|
netPerformancePercentage: new Big(0),
|
|
|
|
netPerformancePercentage: new Big(0),
|
|
|
|
grossPerformance: new Big(0),
|
|
|
|
netPerformanceValues: {}
|
|
|
|
grossPerformancePercentage: new Big(0)
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -946,6 +967,7 @@ export class PortfolioCalculator {
|
|
|
|
let grossPerformanceFromSells = new Big(0);
|
|
|
|
let grossPerformanceFromSells = new Big(0);
|
|
|
|
let initialValue: Big;
|
|
|
|
let initialValue: Big;
|
|
|
|
let investmentAtStartDate: Big;
|
|
|
|
let investmentAtStartDate: Big;
|
|
|
|
|
|
|
|
const currentValues: { [date: string]: Big } = {};
|
|
|
|
const investmentValues: { [date: string]: Big } = {};
|
|
|
|
const investmentValues: { [date: string]: Big } = {};
|
|
|
|
const maxInvestmentValues: { [date: string]: Big } = {};
|
|
|
|
const maxInvestmentValues: { [date: string]: Big } = {};
|
|
|
|
let lastAveragePrice = new Big(0);
|
|
|
|
let lastAveragePrice = new Big(0);
|
|
|
@ -1164,6 +1186,7 @@ export class PortfolioCalculator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isChartMode && i > indexOfStartOrder) {
|
|
|
|
if (isChartMode && i > indexOfStartOrder) {
|
|
|
|
|
|
|
|
currentValues[order.date] = valueOfInvestment;
|
|
|
|
netPerformanceValues[order.date] = grossPerformance
|
|
|
|
netPerformanceValues[order.date] = grossPerformance
|
|
|
|
.minus(grossPerformanceAtStartDate)
|
|
|
|
.minus(grossPerformanceAtStartDate)
|
|
|
|
.minus(fees.minus(feesAtStartDate));
|
|
|
|
.minus(fees.minus(feesAtStartDate));
|
|
|
@ -1261,15 +1284,16 @@ export class PortfolioCalculator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
initialValue,
|
|
|
|
currentValues,
|
|
|
|
grossPerformancePercentage,
|
|
|
|
grossPerformancePercentage,
|
|
|
|
|
|
|
|
initialValue,
|
|
|
|
investmentValues,
|
|
|
|
investmentValues,
|
|
|
|
maxInvestmentValues,
|
|
|
|
maxInvestmentValues,
|
|
|
|
netPerformancePercentage,
|
|
|
|
netPerformancePercentage,
|
|
|
|
netPerformanceValues,
|
|
|
|
netPerformanceValues,
|
|
|
|
|
|
|
|
grossPerformance: totalGrossPerformance,
|
|
|
|
hasErrors: totalUnits.gt(0) && (!initialValue || !unitPriceAtEndDate),
|
|
|
|
hasErrors: totalUnits.gt(0) && (!initialValue || !unitPriceAtEndDate),
|
|
|
|
netPerformance: totalNetPerformance,
|
|
|
|
netPerformance: totalNetPerformance
|
|
|
|
grossPerformance: totalGrossPerformance
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|