|
|
@ -888,6 +888,7 @@ export class PortfolioService { |
|
|
userCurrency, |
|
|
userCurrency, |
|
|
userId, |
|
|
userId, |
|
|
balanceInBaseCurrency: cashDetails.balanceInBaseCurrency, |
|
|
balanceInBaseCurrency: cashDetails.balanceInBaseCurrency, |
|
|
|
|
|
filters: portfolioSnapshotFilters, |
|
|
emergencyFundHoldingsValueInBaseCurrency: |
|
|
emergencyFundHoldingsValueInBaseCurrency: |
|
|
this.getEmergencyFundHoldingsValueInBaseCurrency({ |
|
|
this.getEmergencyFundHoldingsValueInBaseCurrency({ |
|
|
holdings |
|
|
holdings |
|
|
@ -2153,6 +2154,7 @@ export class PortfolioService { |
|
|
balanceInBaseCurrency, |
|
|
balanceInBaseCurrency, |
|
|
emergencyFundHoldingsValueInBaseCurrency, |
|
|
emergencyFundHoldingsValueInBaseCurrency, |
|
|
filteredValueInBaseCurrency, |
|
|
filteredValueInBaseCurrency, |
|
|
|
|
|
filters, |
|
|
portfolioCalculator, |
|
|
portfolioCalculator, |
|
|
userCurrency, |
|
|
userCurrency, |
|
|
userId |
|
|
userId |
|
|
@ -2160,6 +2162,7 @@ export class PortfolioService { |
|
|
balanceInBaseCurrency: number; |
|
|
balanceInBaseCurrency: number; |
|
|
emergencyFundHoldingsValueInBaseCurrency: number; |
|
|
emergencyFundHoldingsValueInBaseCurrency: number; |
|
|
filteredValueInBaseCurrency: Big; |
|
|
filteredValueInBaseCurrency: Big; |
|
|
|
|
|
filters?: Filter[]; |
|
|
portfolioCalculator: PortfolioCalculator; |
|
|
portfolioCalculator: PortfolioCalculator; |
|
|
userCurrency: string; |
|
|
userCurrency: string; |
|
|
userId: string; |
|
|
userId: string; |
|
|
@ -2271,6 +2274,22 @@ export class PortfolioService { |
|
|
.minus(liabilities) |
|
|
.minus(liabilities) |
|
|
.toNumber(); |
|
|
.toNumber(); |
|
|
|
|
|
|
|
|
|
|
|
// The filtered value is put in relation to the whole portfolio. Neither
|
|
|
|
|
|
// the filters nor the liabilities apply, so it is 100% without a filter.
|
|
|
|
|
|
const valueOfUnfilteredPortfolioInBaseCurrency = |
|
|
|
|
|
filters?.length > 0 |
|
|
|
|
|
? await this.getValueOfUnfilteredPortfolioInBaseCurrency({ |
|
|
|
|
|
user, |
|
|
|
|
|
userCurrency, |
|
|
|
|
|
userId, |
|
|
|
|
|
valueOfExcludedActivitiesInBaseCurrency, |
|
|
|
|
|
withExcludedAccountsBalanceInBaseCurrency: |
|
|
|
|
|
cashDetailsWithExcludedAccounts.balanceInBaseCurrency |
|
|
|
|
|
}) |
|
|
|
|
|
: new Big(totalAssetsInBaseCurrency).plus( |
|
|
|
|
|
excludedAccountsAndActivities |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
const daysInMarket = dateOfFirstActivity |
|
|
const daysInMarket = dateOfFirstActivity |
|
|
? differenceInDays(new Date(), dateOfFirstActivity) |
|
|
? differenceInDays(new Date(), dateOfFirstActivity) |
|
|
: 0; |
|
|
: 0; |
|
|
@ -2318,9 +2337,11 @@ export class PortfolioService { |
|
|
}, |
|
|
}, |
|
|
fees: fees.toNumber(), |
|
|
fees: fees.toNumber(), |
|
|
filteredValueInBaseCurrency: filteredValueInBaseCurrency.toNumber(), |
|
|
filteredValueInBaseCurrency: filteredValueInBaseCurrency.toNumber(), |
|
|
filteredValueInPercentage: netWorth |
|
|
filteredValueInPercentage: valueOfUnfilteredPortfolioInBaseCurrency.eq(0) |
|
|
? filteredValueInBaseCurrency.div(netWorth).toNumber() |
|
|
? undefined |
|
|
: undefined, |
|
|
: filteredValueInBaseCurrency |
|
|
|
|
|
.div(valueOfUnfilteredPortfolioInBaseCurrency) |
|
|
|
|
|
.toNumber(), |
|
|
fireWealth: { |
|
|
fireWealth: { |
|
|
today: { |
|
|
today: { |
|
|
valueInBaseCurrency: fireWealthInBaseCurrency.gt(0) |
|
|
valueInBaseCurrency: fireWealthInBaseCurrency.gt(0) |
|
|
@ -2666,6 +2687,52 @@ export class PortfolioService { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Returns the value of the portfolio without filters: the holdings and the |
|
|
|
|
|
* cash of all accounts that are not excluded, plus the excluded accounts and |
|
|
|
|
|
* activities |
|
|
|
|
|
*/ |
|
|
|
|
|
private async getValueOfUnfilteredPortfolioInBaseCurrency({ |
|
|
|
|
|
user, |
|
|
|
|
|
userCurrency, |
|
|
|
|
|
userId, |
|
|
|
|
|
valueOfExcludedActivitiesInBaseCurrency, |
|
|
|
|
|
withExcludedAccountsBalanceInBaseCurrency |
|
|
|
|
|
}: { |
|
|
|
|
|
user: UserWithSettings; |
|
|
|
|
|
userCurrency: string; |
|
|
|
|
|
userId: string; |
|
|
|
|
|
valueOfExcludedActivitiesInBaseCurrency: Big; |
|
|
|
|
|
withExcludedAccountsBalanceInBaseCurrency: number; |
|
|
|
|
|
}) { |
|
|
|
|
|
const [{ activities }, { balanceInBaseCurrency }] = await Promise.all([ |
|
|
|
|
|
this.activitiesService.getActivitiesForPortfolioCalculator({ |
|
|
|
|
|
userCurrency, |
|
|
|
|
|
userId |
|
|
|
|
|
}), |
|
|
|
|
|
this.accountService.getCashDetails({ |
|
|
|
|
|
userId, |
|
|
|
|
|
currency: userCurrency |
|
|
|
|
|
}) |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
const portfolioCalculator = this.calculatorFactory.createCalculator({ |
|
|
|
|
|
activities, |
|
|
|
|
|
userId, |
|
|
|
|
|
calculationType: this.getUserPerformanceCalculationType(user), |
|
|
|
|
|
currency: userCurrency, |
|
|
|
|
|
subscriptionType: user.subscription?.type |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const { currentValueInBaseCurrency } = |
|
|
|
|
|
await portfolioCalculator.getSnapshot(); |
|
|
|
|
|
|
|
|
|
|
|
return new Big(currentValueInBaseCurrency) |
|
|
|
|
|
.plus(withExcludedAccountsBalanceInBaseCurrency) |
|
|
|
|
|
.minus(balanceInBaseCurrency) |
|
|
|
|
|
.plus(valueOfExcludedActivitiesInBaseCurrency); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private isExcludedFromAnalysis(activity: Activity) { |
|
|
private isExcludedFromAnalysis(activity: Activity) { |
|
|
return ( |
|
|
return ( |
|
|
isAccountExcluded(activity.account) || |
|
|
isAccountExcluded(activity.account) || |
|
|
|