Browse Source

Add allocations by market

pull/767/head
Thomas 3 years ago
parent
commit
0d41064170
  1. 27
      apps/api/src/app/portfolio/portfolio.service-new.ts
  2. 36
      apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts
  3. 36
      apps/client/src/app/pages/portfolio/allocations/allocations-page.html
  4. 1
      libs/common/src/lib/interfaces/portfolio-position.interface.ts

27
apps/api/src/app/portfolio/portfolio.service-new.ts

@ -71,6 +71,9 @@ import {
import { PortfolioCalculatorNew } from './portfolio-calculator-new'; import { PortfolioCalculatorNew } from './portfolio-calculator-new';
import { RulesService } from './rules.service'; import { RulesService } from './rules.service';
const developedMarkets = require('../../assets/countries/developed-markets.json');
const emergingMarkets = require('../../assets/countries/emerging-markets.json');
@Injectable() @Injectable()
export class PortfolioServiceNew { export class PortfolioServiceNew {
public constructor( public constructor(
@ -380,7 +383,31 @@ export class PortfolioServiceNew {
const value = item.quantity.mul(item.marketPrice); const value = item.quantity.mul(item.marketPrice);
const symbolProfile = symbolProfileMap[item.symbol]; const symbolProfile = symbolProfileMap[item.symbol];
const dataProviderResponse = dataProviderResponses[item.symbol]; const dataProviderResponse = dataProviderResponses[item.symbol];
const markets = {
DEVELOPED_MARKETS: 0,
EMERGING_MARKETS: 0,
OTHER_MARKETS: 0
};
for (const country of symbolProfile.countries) {
if (developedMarkets.includes(country.code)) {
markets.DEVELOPED_MARKETS = new Big(markets.DEVELOPED_MARKETS)
.plus(country.weight)
.toNumber();
} else if (emergingMarkets.includes(country.code)) {
markets.EMERGING_MARKETS = new Big(markets.EMERGING_MARKETS)
.plus(country.weight)
.toNumber();
} else {
markets.OTHER_MARKETS = new Big(markets.OTHER_MARKETS)
.plus(country.weight)
.toNumber();
}
}
holdings[item.symbol] = { holdings[item.symbol] = {
markets,
allocationCurrent: value.div(totalValue).toNumber(), allocationCurrent: value.div(totalValue).toNumber(),
allocationInvestment: item.investment.div(totalInvestment).toNumber(), allocationInvestment: item.investment.div(totalInvestment).toNumber(),
assetClass: symbolProfile.assetClass, assetClass: symbolProfile.assetClass,

36
apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts

@ -42,6 +42,9 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
public deviceType: string; public deviceType: string;
public hasImpersonationId: boolean; public hasImpersonationId: boolean;
public hasPermissionToCreateOrder: boolean; public hasPermissionToCreateOrder: boolean;
public markets: {
[market: string]: { name: string; value: number };
};
public period = 'current'; public period = 'current';
public periodOptions: ToggleOption[] = [ public periodOptions: ToggleOption[] = [
{ label: 'Initial', value: 'original' }, { label: 'Initial', value: 'original' },
@ -160,6 +163,20 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
value: 0 value: 0
} }
}; };
this.markets = {
DEVELOPED_MARKETS: {
name: 'DEVELOPED_MARKETS',
value: 0
},
EMERGING_MARKETS: {
name: 'EMERGING_MARKETS',
value: 0
},
OTHER_MARKETS: {
name: 'OTHER_MARKETS',
value: 0
}
};
this.positions = {}; this.positions = {};
this.positionsArray = []; this.positionsArray = [];
this.sectors = { this.sectors = {
@ -219,6 +236,13 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
// Prepare analysis data by continents, countries and sectors except for cash // Prepare analysis data by continents, countries and sectors except for cash
if (position.countries.length > 0) { if (position.countries.length > 0) {
this.markets['DEVELOPED_MARKETS'].value +=
position.markets['DEVELOPED_MARKETS'] * position.value;
this.markets['EMERGING_MARKETS'].value +=
position.markets['EMERGING_MARKETS'] * position.value;
this.markets['OTHER_MARKETS'].value +=
position.markets['OTHER_MARKETS'] * position.value;
for (const country of position.countries) { for (const country of position.countries) {
const { code, continent, name, weight } = country; const { code, continent, name, weight } = country;
@ -294,6 +318,18 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
}; };
} }
} }
const marketsTotal =
this.markets['DEVELOPED_MARKETS'].value +
this.markets['EMERGING_MARKETS'].value +
this.markets['OTHER_MARKETS'].value;
this.markets['DEVELOPED_MARKETS'].value =
this.markets['DEVELOPED_MARKETS'].value / marketsTotal;
this.markets['EMERGING_MARKETS'].value =
this.markets['EMERGING_MARKETS'].value / marketsTotal;
this.markets['OTHER_MARKETS'].value =
this.markets['OTHER_MARKETS'].value / marketsTotal;
} }
public onChangePeriod(aValue: string) { public onChangePeriod(aValue: string) {

36
apps/client/src/app/pages/portfolio/allocations/allocations-page.html

@ -172,6 +172,42 @@
</mat-card> </mat-card>
</div> </div>
</div> </div>
<div class="row">
<div class="col-lg">
<mat-card class="mb-3">
<mat-card-content>
<div class="row">
<div class="col-xs-12 col-md-4 my-2">
<h3 class="mb-0">
{{ (markets?.DEVELOPED_MARKETS?.value | percent: '1.2-2') || '-'
}}
</h3>
<div class="h6 mb-0">
<span i18n>Developed Markets</span>
</div>
</div>
<div class="col-xs-12 col-md-4 my-2">
<h3 class="mb-0">
{{ (markets?.EMERGING_MARKETS?.value | percent: '1.2-2') || '-'
}}
</h3>
<div class="h6 mb-0">
<span i18n>Emerging Markets</span>
</div>
</div>
<div class="col-xs-12 col-md-4 my-2">
<h3 class="mb-0">
{{ (markets?.OTHER_MARKETS?.value | percent: '1.2-2') || '-' }}
</h3>
<div class="h6 mb-0">
<span i18n>Other Markets</span>
</div>
</div>
</div>
</mat-card-content>
</mat-card>
</div>
</div>
<div class="row world-map-chart"> <div class="row world-map-chart">
<div class="col-lg"> <div class="col-lg">
<mat-card class="mb-3"> <mat-card class="mb-3">

1
libs/common/src/lib/interfaces/portfolio-position.interface.ts

@ -19,6 +19,7 @@ export interface PortfolioPosition {
marketChange?: number; marketChange?: number;
marketChangePercent?: number; marketChangePercent?: number;
marketPrice: number; marketPrice: number;
markets?: { [market: string]: number };
marketState: MarketState; marketState: MarketState;
name: string; name: string;
netPerformance: number; netPerformance: number;

Loading…
Cancel
Save