|
@ -266,8 +266,7 @@ export class PortfolioService { |
|
|
}): Promise<PortfolioInvestments> { |
|
|
}): Promise<PortfolioInvestments> { |
|
|
const userId = await this.getUserId(impersonationId, this.request.user.id); |
|
|
const userId = await this.getUserId(impersonationId, this.request.user.id); |
|
|
|
|
|
|
|
|
const { portfolioOrders, transactionPoints } = |
|
|
const { activities, transactionPoints } = await this.getTransactionPoints({ |
|
|
await this.getTransactionPoints({ |
|
|
|
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userId, |
|
|
includeDrafts: true, |
|
|
includeDrafts: true, |
|
@ -282,11 +281,10 @@ export class PortfolioService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
transactionPoints, |
|
|
activities, |
|
|
currency: this.request.user.Settings.settings.baseCurrency, |
|
|
currency: this.request.user.Settings.settings.baseCurrency, |
|
|
currentRateService: this.currentRateService, |
|
|
currentRateService: this.currentRateService, |
|
|
exchangeRateDataService: this.exchangeRateDataService, |
|
|
exchangeRateDataService: this.exchangeRateDataService |
|
|
orders: portfolioOrders |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const { items } = await this.getChart({ |
|
|
const { items } = await this.getChart({ |
|
@ -364,8 +362,7 @@ export class PortfolioService { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const { activities, portfolioOrders, transactionPoints } = |
|
|
const { activities, transactionPoints } = await this.getTransactionPoints({ |
|
|
await this.getTransactionPoints({ |
|
|
|
|
|
filters, |
|
|
filters, |
|
|
types, |
|
|
types, |
|
|
userId, |
|
|
userId, |
|
@ -373,11 +370,10 @@ export class PortfolioService { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
transactionPoints, |
|
|
activities, |
|
|
currency: userCurrency, |
|
|
currency: userCurrency, |
|
|
currentRateService: this.currentRateService, |
|
|
currentRateService: this.currentRateService, |
|
|
exchangeRateDataService: this.exchangeRateDataService, |
|
|
exchangeRateDataService: this.exchangeRateDataService |
|
|
orders: portfolioOrders |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const portfolioStart = parseDate( |
|
|
const portfolioStart = parseDate( |
|
@ -737,35 +733,19 @@ export class PortfolioService { |
|
|
{ dataSource: aDataSource, symbol: aSymbol } |
|
|
{ dataSource: aDataSource, symbol: aSymbol } |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
const portfolioOrders: PortfolioOrder[] = orders |
|
|
|
|
|
.filter((order) => { |
|
|
|
|
|
tags = tags.concat(order.tags); |
|
|
|
|
|
|
|
|
|
|
|
return ['BUY', 'DIVIDEND', 'ITEM', 'SELL'].includes(order.type); |
|
|
|
|
|
}) |
|
|
|
|
|
.map((order) => ({ |
|
|
|
|
|
currency: order.SymbolProfile.currency, |
|
|
|
|
|
dataSource: order.SymbolProfile.dataSource, |
|
|
|
|
|
date: format(order.date, DATE_FORMAT), |
|
|
|
|
|
fee: new Big(order.fee), |
|
|
|
|
|
name: order.SymbolProfile?.name, |
|
|
|
|
|
quantity: new Big(order.quantity), |
|
|
|
|
|
symbol: order.SymbolProfile.symbol, |
|
|
|
|
|
tags: order.tags, |
|
|
|
|
|
type: order.type, |
|
|
|
|
|
unitPrice: new Big(order.unitPrice) |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
tags = uniqBy(tags, 'id'); |
|
|
tags = uniqBy(tags, 'id'); |
|
|
|
|
|
|
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
|
|
|
activities: orders.filter((order) => { |
|
|
|
|
|
tags = tags.concat(order.tags); |
|
|
|
|
|
|
|
|
|
|
|
return ['BUY', 'DIVIDEND', 'ITEM', 'SELL'].includes(order.type); |
|
|
|
|
|
}), |
|
|
currency: userCurrency, |
|
|
currency: userCurrency, |
|
|
currentRateService: this.currentRateService, |
|
|
currentRateService: this.currentRateService, |
|
|
exchangeRateDataService: this.exchangeRateDataService, |
|
|
exchangeRateDataService: this.exchangeRateDataService |
|
|
orders: portfolioOrders |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
portfolioCalculator.computeTransactionPoints(); |
|
|
|
|
|
const transactionPoints = portfolioCalculator.getTransactionPoints(); |
|
|
const transactionPoints = portfolioCalculator.getTransactionPoints(); |
|
|
|
|
|
|
|
|
const portfolioStart = parseDate(transactionPoints[0].date); |
|
|
const portfolioStart = parseDate(transactionPoints[0].date); |
|
@ -982,8 +962,7 @@ export class PortfolioService { |
|
|
const userId = await this.getUserId(impersonationId, this.request.user.id); |
|
|
const userId = await this.getUserId(impersonationId, this.request.user.id); |
|
|
const user = await this.userService.user({ id: userId }); |
|
|
const user = await this.userService.user({ id: userId }); |
|
|
|
|
|
|
|
|
const { portfolioOrders, transactionPoints } = |
|
|
const { activities, transactionPoints } = await this.getTransactionPoints({ |
|
|
await this.getTransactionPoints({ |
|
|
|
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userId, |
|
|
types: ['BUY', 'SELL'] |
|
|
types: ['BUY', 'SELL'] |
|
@ -997,11 +976,10 @@ export class PortfolioService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
transactionPoints, |
|
|
activities, |
|
|
currency: this.request.user.Settings.settings.baseCurrency, |
|
|
currency: this.request.user.Settings.settings.baseCurrency, |
|
|
currentRateService: this.currentRateService, |
|
|
currentRateService: this.currentRateService, |
|
|
exchangeRateDataService: this.exchangeRateDataService, |
|
|
exchangeRateDataService: this.exchangeRateDataService |
|
|
orders: portfolioOrders |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const portfolioStart = parseDate(transactionPoints[0].date); |
|
|
const portfolioStart = parseDate(transactionPoints[0].date); |
|
@ -1154,8 +1132,7 @@ export class PortfolioService { |
|
|
) |
|
|
) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
const { portfolioOrders, transactionPoints } = |
|
|
const { activities, transactionPoints } = await this.getTransactionPoints({ |
|
|
await this.getTransactionPoints({ |
|
|
|
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userId, |
|
|
withExcludedAccounts, |
|
|
withExcludedAccounts, |
|
@ -1184,11 +1161,10 @@ export class PortfolioService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
transactionPoints, |
|
|
activities, |
|
|
currency: userCurrency, |
|
|
currency: userCurrency, |
|
|
currentRateService: this.currentRateService, |
|
|
currentRateService: this.currentRateService, |
|
|
exchangeRateDataService: this.exchangeRateDataService, |
|
|
exchangeRateDataService: this.exchangeRateDataService |
|
|
orders: portfolioOrders |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const portfolioStart = min( |
|
|
const portfolioStart = min( |
|
@ -1307,18 +1283,16 @@ export class PortfolioService { |
|
|
const user = await this.userService.user({ id: userId }); |
|
|
const user = await this.userService.user({ id: userId }); |
|
|
const userCurrency = this.getUserCurrency(user); |
|
|
const userCurrency = this.getUserCurrency(user); |
|
|
|
|
|
|
|
|
const { activities, portfolioOrders, transactionPoints } = |
|
|
const { activities, transactionPoints } = await this.getTransactionPoints({ |
|
|
await this.getTransactionPoints({ |
|
|
|
|
|
userId, |
|
|
userId, |
|
|
types: ['BUY', 'SELL'] |
|
|
types: ['BUY', 'SELL'] |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
transactionPoints, |
|
|
activities, |
|
|
currency: userCurrency, |
|
|
currency: userCurrency, |
|
|
currentRateService: this.currentRateService, |
|
|
currentRateService: this.currentRateService, |
|
|
exchangeRateDataService: this.exchangeRateDataService, |
|
|
exchangeRateDataService: this.exchangeRateDataService |
|
|
orders: portfolioOrders |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const portfolioStart = parseDate( |
|
|
const portfolioStart = parseDate( |
|
@ -1865,10 +1839,10 @@ export class PortfolioService { |
|
|
const daysInMarket = differenceInDays(new Date(), firstOrderDate); |
|
|
const daysInMarket = differenceInDays(new Date(), firstOrderDate); |
|
|
|
|
|
|
|
|
const annualizedPerformancePercent = new PortfolioCalculator({ |
|
|
const annualizedPerformancePercent = new PortfolioCalculator({ |
|
|
|
|
|
activities: [], |
|
|
currency: userCurrency, |
|
|
currency: userCurrency, |
|
|
currentRateService: this.currentRateService, |
|
|
currentRateService: this.currentRateService, |
|
|
exchangeRateDataService: this.exchangeRateDataService, |
|
|
exchangeRateDataService: this.exchangeRateDataService |
|
|
orders: [] |
|
|
|
|
|
}) |
|
|
}) |
|
|
.getAnnualizedPerformancePercent({ |
|
|
.getAnnualizedPerformancePercent({ |
|
|
daysInMarket, |
|
|
daysInMarket, |
|
@ -1880,10 +1854,10 @@ export class PortfolioService { |
|
|
|
|
|
|
|
|
const annualizedPerformancePercentWithCurrencyEffect = |
|
|
const annualizedPerformancePercentWithCurrencyEffect = |
|
|
new PortfolioCalculator({ |
|
|
new PortfolioCalculator({ |
|
|
|
|
|
activities: [], |
|
|
currency: userCurrency, |
|
|
currency: userCurrency, |
|
|
currentRateService: this.currentRateService, |
|
|
currentRateService: this.currentRateService, |
|
|
exchangeRateDataService: this.exchangeRateDataService, |
|
|
exchangeRateDataService: this.exchangeRateDataService |
|
|
orders: [] |
|
|
|
|
|
}) |
|
|
}) |
|
|
.getAnnualizedPerformancePercent({ |
|
|
.getAnnualizedPerformancePercent({ |
|
|
daysInMarket, |
|
|
daysInMarket, |
|
@ -1955,6 +1929,7 @@ export class PortfolioService { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Eliminate
|
|
|
private async getTransactionPoints({ |
|
|
private async getTransactionPoints({ |
|
|
filters, |
|
|
filters, |
|
|
includeDrafts = false, |
|
|
includeDrafts = false, |
|
@ -1989,27 +1964,26 @@ export class PortfolioService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const portfolioOrders: PortfolioOrder[] = activities.map((order) => ({ |
|
|
const portfolioOrders: PortfolioOrder[] = activities.map((order) => ({ |
|
|
currency: order.SymbolProfile.currency, |
|
|
// currency: order.SymbolProfile.currency,
|
|
|
dataSource: order.SymbolProfile.dataSource, |
|
|
// dataSource: order.SymbolProfile.dataSource,
|
|
|
date: format(order.date, DATE_FORMAT), |
|
|
date: format(order.date, DATE_FORMAT), |
|
|
fee: new Big(order.fee), |
|
|
fee: new Big(order.fee), |
|
|
name: order.SymbolProfile?.name, |
|
|
// name: order.SymbolProfile?.name,
|
|
|
quantity: new Big(order.quantity), |
|
|
quantity: new Big(order.quantity), |
|
|
symbol: order.SymbolProfile.symbol, |
|
|
// symbol: order.SymbolProfile.symbol,
|
|
|
tags: order.tags, |
|
|
SymbolProfile: order.SymbolProfile, |
|
|
|
|
|
// tags: order.tags,
|
|
|
type: order.type, |
|
|
type: order.type, |
|
|
unitPrice: new Big(order.unitPrice) |
|
|
unitPrice: new Big(order.unitPrice) |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
const portfolioCalculator = new PortfolioCalculator({ |
|
|
|
|
|
activities, |
|
|
currency: userCurrency, |
|
|
currency: userCurrency, |
|
|
currentRateService: this.currentRateService, |
|
|
currentRateService: this.currentRateService, |
|
|
exchangeRateDataService: this.exchangeRateDataService, |
|
|
exchangeRateDataService: this.exchangeRateDataService |
|
|
orders: portfolioOrders |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
portfolioCalculator.computeTransactionPoints(); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
activities, |
|
|
activities, |
|
|
portfolioOrders, |
|
|
portfolioOrders, |
|
|