Refactor value to valueInBaseCurrency (#2160)
This commit is contained in:
parent
9c0f46b587
commit
455a2d2e92
@ -134,7 +134,7 @@ export class PortfolioController {
|
||||
portfolioPosition.netPerformance = null;
|
||||
portfolioPosition.quantity = null;
|
||||
portfolioPosition.valueInPercentage =
|
||||
portfolioPosition.value / totalValue;
|
||||
portfolioPosition.valueInBaseCurrency / totalValue;
|
||||
}
|
||||
|
||||
for (const [name, { valueInBaseCurrency }] of Object.entries(accounts)) {
|
||||
@ -445,7 +445,8 @@ export class PortfolioController {
|
||||
|
||||
for (const [symbol, portfolioPosition] of Object.entries(holdings)) {
|
||||
portfolioPublicDetails.holdings[symbol] = {
|
||||
allocationInPercentage: portfolioPosition.value / totalValue,
|
||||
allocationInPercentage:
|
||||
portfolioPosition.valueInBaseCurrency / totalValue,
|
||||
countries: hasDetails ? portfolioPosition.countries : [],
|
||||
currency: hasDetails ? portfolioPosition.currency : undefined,
|
||||
dataSource: portfolioPosition.dataSource,
|
||||
@ -456,7 +457,7 @@ export class PortfolioController {
|
||||
sectors: hasDetails ? portfolioPosition.sectors : [],
|
||||
symbol: portfolioPosition.symbol,
|
||||
url: portfolioPosition.url,
|
||||
valueInPercentage: portfolioPosition.value / totalValue
|
||||
valueInPercentage: portfolioPosition.valueInBaseCurrency / totalValue
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -585,7 +585,7 @@ export class PortfolioService {
|
||||
symbol: item.symbol,
|
||||
transactionCount: item.transactionCount,
|
||||
url: symbolProfile.url,
|
||||
value: value.toNumber()
|
||||
valueInBaseCurrency: value.toNumber()
|
||||
};
|
||||
}
|
||||
|
||||
@ -645,7 +645,7 @@ export class PortfolioService {
|
||||
holdings[userCurrency] = {
|
||||
...emergencyFundCashPositions[userCurrency],
|
||||
investment: emergencyFundInCash,
|
||||
value: emergencyFundInCash
|
||||
valueInBaseCurrency: emergencyFundInCash
|
||||
};
|
||||
}
|
||||
|
||||
@ -1278,7 +1278,7 @@ export class PortfolioService {
|
||||
|
||||
if (cashPositions[account.currency]) {
|
||||
cashPositions[account.currency].investment += convertedBalance;
|
||||
cashPositions[account.currency].value += convertedBalance;
|
||||
cashPositions[account.currency].valueInBaseCurrency += convertedBalance;
|
||||
} else {
|
||||
cashPositions[account.currency] = this.getInitialCashPosition({
|
||||
balance: convertedBalance,
|
||||
@ -1290,7 +1290,9 @@ export class PortfolioService {
|
||||
for (const symbol of Object.keys(cashPositions)) {
|
||||
// Calculate allocations for each currency
|
||||
cashPositions[symbol].allocationInPercentage = value.gt(0)
|
||||
? new Big(cashPositions[symbol].value).div(value).toNumber()
|
||||
? new Big(cashPositions[symbol].valueInBaseCurrency)
|
||||
.div(value)
|
||||
.toNumber()
|
||||
: 0;
|
||||
}
|
||||
|
||||
@ -1475,7 +1477,7 @@ export class PortfolioService {
|
||||
sectors: [],
|
||||
symbol: currency,
|
||||
transactionCount: 0,
|
||||
value: balance
|
||||
valueInBaseCurrency: balance
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
|
||||
| 'currency'
|
||||
| 'exchange'
|
||||
| 'name'
|
||||
| 'value'
|
||||
| 'valueInBaseCurrency'
|
||||
> & { etfProvider: string };
|
||||
};
|
||||
public sectors: {
|
||||
@ -292,11 +292,11 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
|
||||
if (this.hasImpersonationId) {
|
||||
value = position.allocationInPercentage;
|
||||
} else {
|
||||
value = position.value;
|
||||
value = position.valueInBaseCurrency;
|
||||
}
|
||||
|
||||
this.positions[symbol] = {
|
||||
value,
|
||||
valueInBaseCurrency: value,
|
||||
assetClass: position.assetClass,
|
||||
assetSubClass: position.assetSubClass,
|
||||
currency: position.currency,
|
||||
@ -323,39 +323,45 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
|
||||
}
|
||||
|
||||
this.markets.developedMarkets.value +=
|
||||
position.markets.developedMarkets * position.value;
|
||||
position.markets.developedMarkets * position.valueInBaseCurrency;
|
||||
this.markets.emergingMarkets.value +=
|
||||
position.markets.emergingMarkets * position.value;
|
||||
position.markets.emergingMarkets * position.valueInBaseCurrency;
|
||||
this.markets.otherMarkets.value +=
|
||||
position.markets.otherMarkets * position.value;
|
||||
position.markets.otherMarkets * position.valueInBaseCurrency;
|
||||
|
||||
for (const country of position.countries) {
|
||||
const { code, continent, name, weight } = country;
|
||||
|
||||
if (this.continents[continent]?.value) {
|
||||
this.continents[continent].value += weight * position.value;
|
||||
this.continents[continent].value +=
|
||||
weight * position.valueInBaseCurrency;
|
||||
} else {
|
||||
this.continents[continent] = {
|
||||
name: continent,
|
||||
value: weight * this.portfolioDetails.holdings[symbol].value
|
||||
value:
|
||||
weight *
|
||||
this.portfolioDetails.holdings[symbol].valueInBaseCurrency
|
||||
};
|
||||
}
|
||||
|
||||
if (this.countries[code]?.value) {
|
||||
this.countries[code].value += weight * position.value;
|
||||
this.countries[code].value +=
|
||||
weight * position.valueInBaseCurrency;
|
||||
} else {
|
||||
this.countries[code] = {
|
||||
name,
|
||||
value: weight * this.portfolioDetails.holdings[symbol].value
|
||||
value:
|
||||
weight *
|
||||
this.portfolioDetails.holdings[symbol].valueInBaseCurrency
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.continents[UNKNOWN_KEY].value +=
|
||||
this.portfolioDetails.holdings[symbol].value;
|
||||
this.portfolioDetails.holdings[symbol].valueInBaseCurrency;
|
||||
|
||||
this.countries[UNKNOWN_KEY].value +=
|
||||
this.portfolioDetails.holdings[symbol].value;
|
||||
this.portfolioDetails.holdings[symbol].valueInBaseCurrency;
|
||||
}
|
||||
|
||||
if (position.sectors.length > 0) {
|
||||
@ -363,17 +369,19 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
|
||||
const { name, weight } = sector;
|
||||
|
||||
if (this.sectors[name]?.value) {
|
||||
this.sectors[name].value += weight * position.value;
|
||||
this.sectors[name].value += weight * position.valueInBaseCurrency;
|
||||
} else {
|
||||
this.sectors[name] = {
|
||||
name,
|
||||
value: weight * this.portfolioDetails.holdings[symbol].value
|
||||
value:
|
||||
weight *
|
||||
this.portfolioDetails.holdings[symbol].valueInBaseCurrency
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.sectors[UNKNOWN_KEY].value +=
|
||||
this.portfolioDetails.holdings[symbol].value;
|
||||
this.portfolioDetails.holdings[symbol].valueInBaseCurrency;
|
||||
}
|
||||
}
|
||||
|
||||
@ -381,8 +389,8 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
|
||||
dataSource: position.dataSource,
|
||||
name: position.name,
|
||||
symbol: prettifySymbol(symbol),
|
||||
value: isNumber(position.value)
|
||||
? position.value
|
||||
value: isNumber(position.valueInBaseCurrency)
|
||||
? position.valueInBaseCurrency
|
||||
: position.valueInPercentage
|
||||
};
|
||||
}
|
||||
|
@ -33,11 +33,18 @@ export class PublicPageComponent implements OnInit {
|
||||
};
|
||||
public portfolioPublicDetails: PortfolioPublicDetails;
|
||||
public positions: {
|
||||
[symbol: string]: Pick<PortfolioPosition, 'currency' | 'name' | 'value'>;
|
||||
[symbol: string]: Pick<
|
||||
PortfolioPosition,
|
||||
'currency' | 'name' | 'valueInBaseCurrency'
|
||||
>;
|
||||
};
|
||||
public positionsArray: Pick<
|
||||
PortfolioPosition,
|
||||
'currency' | 'name' | 'netPerformancePercent' | 'symbol' | 'value'
|
||||
| 'currency'
|
||||
| 'name'
|
||||
| 'netPerformancePercent'
|
||||
| 'symbol'
|
||||
| 'valueInBaseCurrency'
|
||||
>[];
|
||||
public sectors: {
|
||||
[name: string]: { name: string; value: number };
|
||||
@ -135,7 +142,7 @@ export class PublicPageComponent implements OnInit {
|
||||
const value = position.allocationInPercentage;
|
||||
|
||||
this.positions[symbol] = {
|
||||
value,
|
||||
valueInBaseCurrency: value,
|
||||
currency: position.currency,
|
||||
name: position.name
|
||||
};
|
||||
@ -143,39 +150,44 @@ export class PublicPageComponent implements OnInit {
|
||||
|
||||
if (position.countries.length > 0) {
|
||||
this.markets.developedMarkets.value +=
|
||||
position.markets.developedMarkets * position.value;
|
||||
position.markets.developedMarkets * position.valueInBaseCurrency;
|
||||
this.markets.emergingMarkets.value +=
|
||||
position.markets.emergingMarkets * position.value;
|
||||
position.markets.emergingMarkets * position.valueInBaseCurrency;
|
||||
this.markets.otherMarkets.value +=
|
||||
position.markets.otherMarkets * position.value;
|
||||
position.markets.otherMarkets * position.valueInBaseCurrency;
|
||||
|
||||
for (const country of position.countries) {
|
||||
const { code, continent, name, weight } = country;
|
||||
|
||||
if (this.continents[continent]?.value) {
|
||||
this.continents[continent].value += weight * position.value;
|
||||
this.continents[continent].value +=
|
||||
weight * position.valueInBaseCurrency;
|
||||
} else {
|
||||
this.continents[continent] = {
|
||||
name: continent,
|
||||
value: weight * this.portfolioPublicDetails.holdings[symbol].value
|
||||
value:
|
||||
weight *
|
||||
this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency
|
||||
};
|
||||
}
|
||||
|
||||
if (this.countries[code]?.value) {
|
||||
this.countries[code].value += weight * position.value;
|
||||
this.countries[code].value += weight * position.valueInBaseCurrency;
|
||||
} else {
|
||||
this.countries[code] = {
|
||||
name,
|
||||
value: weight * this.portfolioPublicDetails.holdings[symbol].value
|
||||
value:
|
||||
weight *
|
||||
this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.continents[UNKNOWN_KEY].value +=
|
||||
this.portfolioPublicDetails.holdings[symbol].value;
|
||||
this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency;
|
||||
|
||||
this.countries[UNKNOWN_KEY].value +=
|
||||
this.portfolioPublicDetails.holdings[symbol].value;
|
||||
this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency;
|
||||
}
|
||||
|
||||
if (position.sectors.length > 0) {
|
||||
@ -183,24 +195,26 @@ export class PublicPageComponent implements OnInit {
|
||||
const { name, weight } = sector;
|
||||
|
||||
if (this.sectors[name]?.value) {
|
||||
this.sectors[name].value += weight * position.value;
|
||||
this.sectors[name].value += weight * position.valueInBaseCurrency;
|
||||
} else {
|
||||
this.sectors[name] = {
|
||||
name,
|
||||
value: weight * this.portfolioPublicDetails.holdings[symbol].value
|
||||
value:
|
||||
weight *
|
||||
this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.sectors[UNKNOWN_KEY].value +=
|
||||
this.portfolioPublicDetails.holdings[symbol].value;
|
||||
this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency;
|
||||
}
|
||||
|
||||
this.symbols[prettifySymbol(symbol)] = {
|
||||
name: position.name,
|
||||
symbol: prettifySymbol(symbol),
|
||||
value: isNumber(position.value)
|
||||
? position.value
|
||||
value: isNumber(position.valueInBaseCurrency)
|
||||
? position.valueInBaseCurrency
|
||||
: position.valueInPercentage
|
||||
};
|
||||
}
|
||||
|
@ -415,10 +415,10 @@ export class DataService {
|
||||
map((response) => {
|
||||
if (response.holdings) {
|
||||
for (const symbol of Object.keys(response.holdings)) {
|
||||
response.holdings[symbol].value = isNumber(
|
||||
response.holdings[symbol].value
|
||||
response.holdings[symbol].valueInBaseCurrency = isNumber(
|
||||
response.holdings[symbol].valueInBaseCurrency
|
||||
)
|
||||
? response.holdings[symbol].value
|
||||
? response.holdings[symbol].valueInBaseCurrency
|
||||
: response.holdings[symbol].valueInPercentage;
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,6 @@ export interface PortfolioPosition {
|
||||
symbol: string;
|
||||
type?: string;
|
||||
url?: string;
|
||||
value?: number;
|
||||
valueInBaseCurrency?: number;
|
||||
valueInPercentage?: number;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ export interface PortfolioPublicDetails {
|
||||
| 'sectors'
|
||||
| 'symbol'
|
||||
| 'url'
|
||||
| 'value'
|
||||
| 'valueInBaseCurrency'
|
||||
| 'valueInPercentage'
|
||||
>;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user