Fix performance percentage for 1d (#2814)

* Fix performance percentage for 1d

* Improve response of positions endpoint

* Update changelog
pull/2817/head
Thomas Kaul 11 months ago committed by GitHub
parent 0ad734262a
commit 23d323073d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Improved the time-weighted performance calculation for `1D`
- Improved the tabs on iOS (_Add to Home Screen_) - Improved the tabs on iOS (_Add to Home Screen_)
## 2.33.0 - 2023-12-31 ## 2.33.0 - 2023-12-31

@ -1246,7 +1246,7 @@ export class PortfolioCalculator {
if (i > indexOfStartOrder) { if (i > indexOfStartOrder) {
// Only consider periods with an investment for the calculation of // Only consider periods with an investment for the calculation of
// the time weighted investment // the time weighted investment
if (totalInvestmentBeforeTransaction.gt(0)) { if (valueOfInvestmentBeforeTransaction.gt(0)) {
// Calculate the number of days since the previous order // Calculate the number of days since the previous order
const orderDate = new Date(order.date); const orderDate = new Date(order.date);
const previousOrderDate = new Date(orders[i - 1].date); const previousOrderDate = new Date(orders[i - 1].date);
@ -1267,7 +1267,10 @@ export class PortfolioCalculator {
totalInvestmentDays += daysSinceLastOrder; totalInvestmentDays += daysSinceLastOrder;
sumOfTimeWeightedInvestments = sumOfTimeWeightedInvestments.add( sumOfTimeWeightedInvestments = sumOfTimeWeightedInvestments.add(
totalInvestmentBeforeTransaction.mul(daysSinceLastOrder) valueAtStartDate
.minus(investmentAtStartDate)
.plus(totalInvestmentBeforeTransaction)
.mul(daysSinceLastOrder)
); );
} }

@ -1035,25 +1035,44 @@ export class PortfolioService {
return { return {
hasErrors: currentPositions.hasErrors, hasErrors: currentPositions.hasErrors,
positions: positions.map((position) => { positions: positions.map(
return { ({
...position, averagePrice,
assetClass: symbolProfileMap[position.symbol].assetClass, currency,
assetSubClass: symbolProfileMap[position.symbol].assetSubClass, dataSource,
averagePrice: new Big(position.averagePrice).toNumber(), firstBuyDate,
grossPerformance: position.grossPerformance?.toNumber() ?? null, investment,
grossPerformancePercentage: grossPerformance,
position.grossPerformancePercentage?.toNumber() ?? null, grossPerformancePercentage,
investment: new Big(position.investment).toNumber(), netPerformance,
marketState: netPerformancePercentage,
dataProviderResponses[position.symbol]?.marketState ?? 'delayed', quantity,
name: symbolProfileMap[position.symbol].name, symbol,
netPerformance: position.netPerformance?.toNumber() ?? null, transactionCount
netPerformancePercentage: }) => {
position.netPerformancePercentage?.toNumber() ?? null, return {
quantity: new Big(position.quantity).toNumber() currency,
}; dataSource,
}) firstBuyDate,
symbol,
transactionCount,
assetClass: symbolProfileMap[symbol].assetClass,
assetSubClass: symbolProfileMap[symbol].assetSubClass,
averagePrice: averagePrice.toNumber(),
grossPerformance: grossPerformance?.toNumber() ?? null,
grossPerformancePercentage:
grossPerformancePercentage?.toNumber() ?? null,
investment: investment.toNumber(),
marketState:
dataProviderResponses[symbol]?.marketState ?? 'delayed',
name: symbolProfileMap[symbol].name,
netPerformance: netPerformance?.toNumber() ?? null,
netPerformancePercentage:
netPerformancePercentage?.toNumber() ?? null,
quantity: quantity.toNumber()
};
}
)
}; };
} }

Loading…
Cancel
Save