|
|
|
@ -88,7 +88,6 @@ import { |
|
|
|
parseISO, |
|
|
|
set |
|
|
|
} from 'date-fns'; |
|
|
|
import { isEmpty } from 'lodash'; |
|
|
|
|
|
|
|
import { PortfolioCalculator } from './calculator/portfolio-calculator'; |
|
|
|
import { PortfolioCalculatorFactory } from './calculator/portfolio-calculator.factory'; |
|
|
|
@ -776,35 +775,7 @@ export class PortfolioService { |
|
|
|
}); |
|
|
|
|
|
|
|
if (activities.length === 0) { |
|
|
|
return { |
|
|
|
activities: [], |
|
|
|
activitiesCount: 0, |
|
|
|
averagePrice: undefined, |
|
|
|
dataProviderInfo: undefined, |
|
|
|
dividendInBaseCurrency: undefined, |
|
|
|
dividendYieldPercent: undefined, |
|
|
|
dividendYieldPercentWithCurrencyEffect: undefined, |
|
|
|
feeInBaseCurrency: undefined, |
|
|
|
firstBuyDate: undefined, |
|
|
|
grossPerformance: undefined, |
|
|
|
grossPerformancePercent: undefined, |
|
|
|
grossPerformancePercentWithCurrencyEffect: undefined, |
|
|
|
grossPerformanceWithCurrencyEffect: undefined, |
|
|
|
historicalData: [], |
|
|
|
investmentInBaseCurrencyWithCurrencyEffect: undefined, |
|
|
|
marketPrice: undefined, |
|
|
|
marketPriceMax: undefined, |
|
|
|
marketPriceMin: undefined, |
|
|
|
netPerformance: undefined, |
|
|
|
netPerformancePercent: undefined, |
|
|
|
netPerformancePercentWithCurrencyEffect: undefined, |
|
|
|
netPerformanceWithCurrencyEffect: undefined, |
|
|
|
performances: undefined, |
|
|
|
quantity: undefined, |
|
|
|
SymbolProfile: undefined, |
|
|
|
tags: [], |
|
|
|
value: undefined |
|
|
|
}; |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
|
|
|
|
const [SymbolProfile] = await this.symbolProfileService.getSymbolProfiles([ |
|
|
|
@ -818,7 +789,6 @@ export class PortfolioService { |
|
|
|
currency: userCurrency |
|
|
|
}); |
|
|
|
|
|
|
|
const portfolioStart = portfolioCalculator.getStartDate(); |
|
|
|
const transactionPoints = portfolioCalculator.getTransactionPoints(); |
|
|
|
|
|
|
|
const { positions } = await portfolioCalculator.getSnapshot(); |
|
|
|
@ -827,7 +797,10 @@ export class PortfolioService { |
|
|
|
return position.dataSource === dataSource && position.symbol === symbol; |
|
|
|
}); |
|
|
|
|
|
|
|
if (holding) { |
|
|
|
if (!holding) { |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
|
|
|
|
const { |
|
|
|
averagePrice, |
|
|
|
currency, |
|
|
|
@ -868,13 +841,9 @@ export class PortfolioService { |
|
|
|
const dividendYieldPercentWithCurrencyEffect = |
|
|
|
getAnnualizedPerformancePercent({ |
|
|
|
daysInMarket: differenceInDays(new Date(), parseDate(firstBuyDate)), |
|
|
|
netPerformancePercentage: timeWeightedInvestmentWithCurrencyEffect.eq( |
|
|
|
0 |
|
|
|
) |
|
|
|
netPerformancePercentage: timeWeightedInvestmentWithCurrencyEffect.eq(0) |
|
|
|
? new Big(0) |
|
|
|
: dividendInBaseCurrency.div( |
|
|
|
timeWeightedInvestmentWithCurrencyEffect |
|
|
|
) |
|
|
|
: dividendInBaseCurrency.div(timeWeightedInvestmentWithCurrencyEffect) |
|
|
|
}); |
|
|
|
|
|
|
|
const historicalData = await this.dataProviderService.getHistorical( |
|
|
|
@ -928,9 +897,7 @@ export class PortfolioService { |
|
|
|
date, |
|
|
|
averagePrice: currentAveragePrice, |
|
|
|
marketPrice: |
|
|
|
historicalDataArray.length > 0 |
|
|
|
? marketPrice |
|
|
|
: currentAveragePrice, |
|
|
|
historicalDataArray.length > 0 ? marketPrice : currentAveragePrice, |
|
|
|
quantity: currentQuantity |
|
|
|
}); |
|
|
|
|
|
|
|
@ -1007,98 +974,6 @@ export class PortfolioService { |
|
|
|
userCurrency |
|
|
|
) |
|
|
|
}; |
|
|
|
} else { |
|
|
|
const currentData = await this.dataProviderService.getQuotes({ |
|
|
|
user, |
|
|
|
items: [{ symbol, dataSource: DataSource.YAHOO }] |
|
|
|
}); |
|
|
|
const marketPrice = currentData[symbol]?.marketPrice; |
|
|
|
|
|
|
|
let historicalData = await this.dataProviderService.getHistorical( |
|
|
|
[{ symbol, dataSource: DataSource.YAHOO }], |
|
|
|
'day', |
|
|
|
portfolioStart, |
|
|
|
new Date() |
|
|
|
); |
|
|
|
|
|
|
|
if (isEmpty(historicalData)) { |
|
|
|
try { |
|
|
|
historicalData = await this.dataProviderService.getHistoricalRaw({ |
|
|
|
assetProfileIdentifiers: [{ symbol, dataSource: DataSource.YAHOO }], |
|
|
|
from: portfolioStart, |
|
|
|
to: new Date() |
|
|
|
}); |
|
|
|
} catch { |
|
|
|
historicalData = { |
|
|
|
[symbol]: {} |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const historicalDataArray: HistoricalDataItem[] = []; |
|
|
|
let marketPriceMax = marketPrice; |
|
|
|
let marketPriceMaxDate = new Date(); |
|
|
|
let marketPriceMin = marketPrice; |
|
|
|
|
|
|
|
for (const [date, { marketPrice }] of Object.entries( |
|
|
|
historicalData[symbol] |
|
|
|
)) { |
|
|
|
historicalDataArray.push({ |
|
|
|
date, |
|
|
|
value: marketPrice |
|
|
|
}); |
|
|
|
|
|
|
|
if (marketPrice > marketPriceMax) { |
|
|
|
marketPriceMax = marketPrice; |
|
|
|
marketPriceMaxDate = parseISO(date); |
|
|
|
} |
|
|
|
marketPriceMin = Math.min( |
|
|
|
marketPrice ?? Number.MAX_SAFE_INTEGER, |
|
|
|
marketPriceMin |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
const performancePercent = |
|
|
|
this.benchmarkService.calculateChangeInPercentage( |
|
|
|
marketPriceMax, |
|
|
|
marketPrice |
|
|
|
); |
|
|
|
|
|
|
|
return { |
|
|
|
marketPrice, |
|
|
|
marketPriceMax, |
|
|
|
marketPriceMin, |
|
|
|
SymbolProfile, |
|
|
|
activities: [], |
|
|
|
activitiesCount: 0, |
|
|
|
averagePrice: 0, |
|
|
|
dataProviderInfo: undefined, |
|
|
|
dividendInBaseCurrency: 0, |
|
|
|
dividendYieldPercent: 0, |
|
|
|
dividendYieldPercentWithCurrencyEffect: 0, |
|
|
|
feeInBaseCurrency: 0, |
|
|
|
firstBuyDate: undefined, |
|
|
|
grossPerformance: undefined, |
|
|
|
grossPerformancePercent: undefined, |
|
|
|
grossPerformancePercentWithCurrencyEffect: undefined, |
|
|
|
grossPerformanceWithCurrencyEffect: undefined, |
|
|
|
historicalData: historicalDataArray, |
|
|
|
investmentInBaseCurrencyWithCurrencyEffect: 0, |
|
|
|
netPerformance: undefined, |
|
|
|
netPerformancePercent: undefined, |
|
|
|
netPerformancePercentWithCurrencyEffect: undefined, |
|
|
|
netPerformanceWithCurrencyEffect: undefined, |
|
|
|
performances: { |
|
|
|
allTimeHigh: { |
|
|
|
performancePercent, |
|
|
|
date: marketPriceMaxDate |
|
|
|
} |
|
|
|
}, |
|
|
|
quantity: 0, |
|
|
|
tags: [], |
|
|
|
value: 0 |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public async getPerformance({ |
|
|
|
|