fix: mark unpriced positions as partial return (#138)
This commit is contained in:
@@ -111,15 +111,17 @@ describe('saved brokerage account projection', () => {
|
|||||||
{ type: 'FUND', quantity: '3', averagePurchasePrice: { currency: 'USD', value: '2.5' }, absoluteReturn: null },
|
{ type: 'FUND', quantity: '3', averagePurchasePrice: { currency: 'USD', value: '2.5' }, absoluteReturn: null },
|
||||||
{ type: 'STOCK', quantity: '4', averagePurchasePrice: { currency: 'USD', value: '0' }, absoluteReturn: { currency: 'USD', value: '2.5' } },
|
{ type: 'STOCK', quantity: '4', averagePurchasePrice: { currency: 'USD', value: '0' }, absoluteReturn: { currency: 'USD', value: '2.5' } },
|
||||||
{ type: 'CURRENCY', quantity: '100', averagePurchasePrice: { currency: 'EUR', value: '1' }, absoluteReturn: { currency: 'EUR', value: '5' } },
|
{ type: 'CURRENCY', quantity: '100', averagePurchasePrice: { currency: 'EUR', value: '1' }, absoluteReturn: { currency: 'EUR', value: '5' } },
|
||||||
|
{ type: 'BOND', quantity: '1', currentValue: { currency: 'CNY', value: '7' }, averagePurchasePrice: null, absoluteReturn: null },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect((await service.list('owner')).data?.[0].portfolioSummary).toMatchObject({
|
expect((await service.list('owner')).data?.[0].portfolioSummary).toMatchObject({
|
||||||
stockPositionCount: 2, bondPositionCount: 1,
|
stockPositionCount: 2, bondPositionCount: 2,
|
||||||
fundPositionCount: 1, totalPositionCount: 5,
|
fundPositionCount: 1, totalPositionCount: 6,
|
||||||
unrealizedReturnByCurrency: [
|
unrealizedReturnByCurrency: [
|
||||||
|
{ currency: 'CNY', absolute: '0', costBasis: '0', percent: null, partial: true },
|
||||||
{ currency: 'RUB', absolute: '1.250000003', costBasis: '30.000000002', percent: '4.17', partial: false },
|
{ currency: 'RUB', absolute: '1.250000003', costBasis: '30.000000002', percent: '4.17', partial: false },
|
||||||
{ currency: 'USD', absolute: '2.5', costBasis: '0', percent: null, partial: true },
|
{ currency: 'USD', absolute: '2.5', costBasis: '0', percent: null, partial: true },
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -40,11 +40,12 @@ function unrealizedReturns(positions: PortfolioPositionDto[]): UnrealizedReturnD
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
const partial = new Set(
|
const partial = new Set(
|
||||||
investments.flatMap((position) =>
|
investments.flatMap((position) => {
|
||||||
!position.absoluteReturn && position.averagePurchasePrice
|
const money = position.absoluteReturn
|
||||||
? [position.averagePurchasePrice.currency]
|
? null
|
||||||
: [],
|
: position.averagePurchasePrice ?? position.currentValue;
|
||||||
),
|
return money ? [money.currency] : [];
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
const currencies = new Set([...absolute, ...costs].map((money) => money.currency));
|
const currencies = new Set([...absolute, ...costs].map((money) => money.currency));
|
||||||
return [...new Set([...currencies, ...partial])]
|
return [...new Set([...currencies, ...partial])]
|
||||||
|
|||||||
Reference in New Issue
Block a user