|
|
@ -487,6 +487,7 @@ export class PortfolioService { |
|
|
(user.settings?.settings as UserSettings)?.emergencyFund ?? 0 |
|
|
(user.settings?.settings as UserSettings)?.emergencyFund ?? 0 |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Activities for non-cash assets
|
|
|
const { activities } = |
|
|
const { activities } = |
|
|
await this.orderService.getOrdersForPortfolioCalculator({ |
|
|
await this.orderService.getOrdersForPortfolioCalculator({ |
|
|
filters, |
|
|
filters, |
|
|
@ -494,6 +495,13 @@ export class PortfolioService { |
|
|
userId |
|
|
userId |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Synthetic activities for cash
|
|
|
|
|
|
const cashDetails = await this.accountService.getCashDetails({ |
|
|
|
|
|
filters, |
|
|
|
|
|
userId, |
|
|
|
|
|
currency: userCurrency |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const portfolioCalculator = this.calculatorFactory.createCalculator({ |
|
|
const portfolioCalculator = this.calculatorFactory.createCalculator({ |
|
|
activities, |
|
|
activities, |
|
|
filters, |
|
|
filters, |
|
|
@ -505,12 +513,6 @@ export class PortfolioService { |
|
|
const { createdAt, currentValueInBaseCurrency, hasErrors, positions } = |
|
|
const { createdAt, currentValueInBaseCurrency, hasErrors, positions } = |
|
|
await portfolioCalculator.getSnapshot(); |
|
|
await portfolioCalculator.getSnapshot(); |
|
|
|
|
|
|
|
|
const cashDetails = await this.accountService.getCashDetails({ |
|
|
|
|
|
filters, |
|
|
|
|
|
userId, |
|
|
|
|
|
currency: userCurrency |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const holdings: PortfolioDetails['holdings'] = {}; |
|
|
const holdings: PortfolioDetails['holdings'] = {}; |
|
|
|
|
|
|
|
|
const totalValueInBaseCurrency = currentValueInBaseCurrency.plus( |
|
|
const totalValueInBaseCurrency = currentValueInBaseCurrency.plus( |
|
|
@ -522,10 +524,6 @@ export class PortfolioService { |
|
|
return type === 'ACCOUNT'; |
|
|
return type === 'ACCOUNT'; |
|
|
}) ?? false; |
|
|
}) ?? false; |
|
|
|
|
|
|
|
|
const isFilteredByCash = filters?.some(({ id, type }) => { |
|
|
|
|
|
return id === AssetClass.LIQUIDITY && type === 'ASSET_CLASS'; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const isFilteredByClosedHoldings = |
|
|
const isFilteredByClosedHoldings = |
|
|
filters?.some(({ id, type }) => { |
|
|
filters?.some(({ id, type }) => { |
|
|
return id === 'CLOSED' && type === 'HOLDING_TYPE'; |
|
|
return id === 'CLOSED' && type === 'HOLDING_TYPE'; |
|
|
@ -621,10 +619,10 @@ export class PortfolioService { |
|
|
allocationInPercentage: filteredValueInBaseCurrency.eq(0) |
|
|
allocationInPercentage: filteredValueInBaseCurrency.eq(0) |
|
|
? 0 |
|
|
? 0 |
|
|
: valueInBaseCurrency.div(filteredValueInBaseCurrency).toNumber(), |
|
|
: valueInBaseCurrency.div(filteredValueInBaseCurrency).toNumber(), |
|
|
assetClass: assetProfile.assetClass, |
|
|
assetClass: assetProfile?.assetClass, |
|
|
assetSubClass: assetProfile.assetSubClass, |
|
|
assetSubClass: assetProfile?.assetSubClass, |
|
|
countries: assetProfile.countries, |
|
|
countries: assetProfile?.countries, |
|
|
dataSource: assetProfile.dataSource, |
|
|
dataSource: assetProfile?.dataSource, |
|
|
dateOfFirstActivity: parseDate(firstBuyDate), |
|
|
dateOfFirstActivity: parseDate(firstBuyDate), |
|
|
dividend: dividend?.toNumber() ?? 0, |
|
|
dividend: dividend?.toNumber() ?? 0, |
|
|
grossPerformance: grossPerformance?.toNumber() ?? 0, |
|
|
grossPerformance: grossPerformance?.toNumber() ?? 0, |
|
|
@ -633,8 +631,8 @@ export class PortfolioService { |
|
|
grossPerformancePercentageWithCurrencyEffect?.toNumber() ?? 0, |
|
|
grossPerformancePercentageWithCurrencyEffect?.toNumber() ?? 0, |
|
|
grossPerformanceWithCurrencyEffect: |
|
|
grossPerformanceWithCurrencyEffect: |
|
|
grossPerformanceWithCurrencyEffect?.toNumber() ?? 0, |
|
|
grossPerformanceWithCurrencyEffect?.toNumber() ?? 0, |
|
|
holdings: assetProfile.holdings.map( |
|
|
holdings: |
|
|
({ allocationInPercentage, name }) => { |
|
|
assetProfile?.holdings.map(({ allocationInPercentage, name }) => { |
|
|
return { |
|
|
return { |
|
|
allocationInPercentage, |
|
|
allocationInPercentage, |
|
|
name, |
|
|
name, |
|
|
@ -642,10 +640,9 @@ export class PortfolioService { |
|
|
.mul(allocationInPercentage) |
|
|
.mul(allocationInPercentage) |
|
|
.toNumber() |
|
|
.toNumber() |
|
|
}; |
|
|
}; |
|
|
} |
|
|
}) ?? [], |
|
|
), |
|
|
|
|
|
investment: investment.toNumber(), |
|
|
investment: investment.toNumber(), |
|
|
name: assetProfile.name, |
|
|
name: assetProfile?.name, |
|
|
netPerformance: netPerformance?.toNumber() ?? 0, |
|
|
netPerformance: netPerformance?.toNumber() ?? 0, |
|
|
netPerformancePercent: netPerformancePercentage?.toNumber() ?? 0, |
|
|
netPerformancePercent: netPerformancePercentage?.toNumber() ?? 0, |
|
|
netPerformancePercentWithCurrencyEffect: |
|
|
netPerformancePercentWithCurrencyEffect: |
|
|
@ -655,24 +652,12 @@ export class PortfolioService { |
|
|
netPerformanceWithCurrencyEffect: |
|
|
netPerformanceWithCurrencyEffect: |
|
|
netPerformanceWithCurrencyEffectMap?.[dateRange]?.toNumber() ?? 0, |
|
|
netPerformanceWithCurrencyEffectMap?.[dateRange]?.toNumber() ?? 0, |
|
|
quantity: quantity.toNumber(), |
|
|
quantity: quantity.toNumber(), |
|
|
sectors: assetProfile.sectors, |
|
|
sectors: assetProfile?.sectors, |
|
|
url: assetProfile.url, |
|
|
url: assetProfile?.url, |
|
|
valueInBaseCurrency: valueInBaseCurrency.toNumber() |
|
|
valueInBaseCurrency: valueInBaseCurrency.toNumber() |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (filters?.length === 0 || isFilteredByAccount || isFilteredByCash) { |
|
|
|
|
|
const cashPositions = this.getCashPositions({ |
|
|
|
|
|
cashDetails, |
|
|
|
|
|
userCurrency, |
|
|
|
|
|
value: filteredValueInBaseCurrency |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
for (const symbol of Object.keys(cashPositions)) { |
|
|
|
|
|
holdings[symbol] = cashPositions[symbol]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const { accounts, platforms } = await this.getValueOfAccountsAndPlatforms({ |
|
|
const { accounts, platforms } = await this.getValueOfAccountsAndPlatforms({ |
|
|
activities, |
|
|
activities, |
|
|
filters, |
|
|
filters, |
|
|
@ -2157,7 +2142,7 @@ export class PortfolioService { |
|
|
accounts[account?.id || UNKNOWN_KEY] = { |
|
|
accounts[account?.id || UNKNOWN_KEY] = { |
|
|
balance: 0, |
|
|
balance: 0, |
|
|
currency: account?.currency, |
|
|
currency: account?.currency, |
|
|
name: account.name, |
|
|
name: account?.name, |
|
|
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency |
|
|
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
@ -2171,7 +2156,7 @@ export class PortfolioService { |
|
|
platforms[account?.platformId || UNKNOWN_KEY] = { |
|
|
platforms[account?.platformId || UNKNOWN_KEY] = { |
|
|
balance: 0, |
|
|
balance: 0, |
|
|
currency: account?.currency, |
|
|
currency: account?.currency, |
|
|
name: account.platform?.name, |
|
|
name: account?.platform?.name, |
|
|
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency |
|
|
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|