Feature/extend position detail dialog (#54)

* Extend position detail dialog

* Absolute change
* Number of transactions
pull/55/head
Thomas 3 years ago committed by GitHub
parent 40c95a541d
commit a076a1c933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
- Added the absolute change to the position detail dialog
- Added the number of transactions to the position detail dialog
## 0.95.0 - 28.04.2021 ## 0.95.0 - 28.04.2021
### Added ### Added

@ -16,4 +16,5 @@ export interface Position {
investmentInOriginalCurrency?: number; investmentInOriginalCurrency?: number;
marketPrice?: number; marketPrice?: number;
quantity: number; quantity: number;
transactionCount: number;
} }

@ -13,6 +13,7 @@ export interface PortfolioPositionDetail {
minPrice: number; minPrice: number;
quantity: number; quantity: number;
symbol: string; symbol: string;
transactionCount: number;
} }
export interface HistoricalDataItem { export interface HistoricalDataItem {

@ -20,6 +20,7 @@ export interface PortfolioPosition {
sector?: string; sector?: string;
shareCurrent: number; shareCurrent: number;
shareInvestment: number; shareInvestment: number;
transactionCount: number;
symbol: string; symbol: string;
type?: string; type?: string;
url?: string; url?: string;

@ -209,7 +209,8 @@ export class PortfolioService {
firstBuyDate, firstBuyDate,
investment, investment,
marketPrice, marketPrice,
quantity quantity,
transactionCount
} = portfolio.getPositions(new Date())[aSymbol]; } = portfolio.getPositions(new Date())[aSymbol];
const historicalData = await this.dataProviderService.getHistorical( const historicalData = await this.dataProviderService.getHistorical(
@ -262,6 +263,7 @@ export class PortfolioService {
maxPrice, maxPrice,
minPrice, minPrice,
quantity, quantity,
transactionCount,
grossPerformance: this.exchangeRateDataService.toCurrency( grossPerformance: this.exchangeRateDataService.toCurrency(
marketPrice - averagePrice, marketPrice - averagePrice,
currency, currency,
@ -315,7 +317,8 @@ export class PortfolioService {
maxPrice: undefined, maxPrice: undefined,
minPrice: undefined, minPrice: undefined,
quantity: undefined, quantity: undefined,
symbol: aSymbol symbol: aSymbol,
transactionCount: undefined
}; };
} }
@ -331,7 +334,8 @@ export class PortfolioService {
maxPrice: undefined, maxPrice: undefined,
minPrice: undefined, minPrice: undefined,
quantity: undefined, quantity: undefined,
symbol: aSymbol symbol: aSymbol,
transactionCount: undefined
}; };
} }

@ -57,7 +57,7 @@ export class Portfolio implements PortfolioInterface {
public async addCurrentPortfolioItems() { public async addCurrentPortfolioItems() {
const currentData = await this.dataProviderService.get(this.getSymbols()); const currentData = await this.dataProviderService.get(this.getSymbols());
let currentDate = new Date(); const currentDate = new Date();
const year = getYear(currentDate); const year = getYear(currentDate);
const month = getMonth(currentDate); const month = getMonth(currentDate);
@ -82,7 +82,9 @@ export class Portfolio implements PortfolioInterface {
marketPrice: marketPrice:
currentData[symbol]?.marketPrice ?? currentData[symbol]?.marketPrice ??
portfolioItemsYesterday.positions[symbol]?.marketPrice, portfolioItemsYesterday.positions[symbol]?.marketPrice,
quantity: portfolioItemsYesterday?.positions[symbol]?.quantity quantity: portfolioItemsYesterday?.positions[symbol]?.quantity,
transactionCount:
portfolioItemsYesterday?.positions[symbol]?.transactionCount
}; };
}); });
@ -289,7 +291,9 @@ export class Portfolio implements PortfolioInterface {
data[symbol]?.currency, data[symbol]?.currency,
this.user.Settings.currency this.user.Settings.currency
) / value, ) / value,
shareInvestment: portfolioItem.positions[symbol].investment / investment shareInvestment:
portfolioItem.positions[symbol].investment / investment,
transactionCount: portfolioItem.positions[symbol].transactionCount
}; };
}); });
@ -582,7 +586,8 @@ export class Portfolio implements PortfolioInterface {
marketPrice: marketPrice:
historicalData[symbol]?.[format(currentDate, 'yyyy-MM-dd')] historicalData[symbol]?.[format(currentDate, 'yyyy-MM-dd')]
?.marketPrice || 0, ?.marketPrice || 0,
quantity: 0 quantity: 0,
transactionCount: 0
}; };
}); });
@ -623,7 +628,8 @@ export class Portfolio implements PortfolioInterface {
marketPrice: marketPrice:
historicalData[symbol]?.[format(yesterday, 'yyyy-MM-dd')] historicalData[symbol]?.[format(yesterday, 'yyyy-MM-dd')]
?.marketPrice || 0, ?.marketPrice || 0,
quantity: 0 quantity: 0,
transactionCount: 0
}; };
}); });
@ -730,6 +736,10 @@ export class Portfolio implements PortfolioInterface {
order.getSymbol() order.getSymbol()
].currency = order.getCurrency(); ].currency = order.getCurrency();
this.portfolioItems[i].positions[
order.getSymbol()
].transactionCount += 1;
if (order.getType() === 'BUY') { if (order.getType() === 'BUY') {
if ( if (
!this.portfolioItems[i].positions[order.getSymbol()].firstBuyDate !this.portfolioItems[i].positions[order.getSymbol()].firstBuyDate

@ -23,6 +23,7 @@ export class PositionDetailDialog {
public benchmarkDataItems: LineChartItem[]; public benchmarkDataItems: LineChartItem[];
public currency: string; public currency: string;
public firstBuyDate: string; public firstBuyDate: string;
public grossPerformance: number;
public grossPerformancePercent: number; public grossPerformancePercent: number;
public historicalDataItems: LineChartItem[]; public historicalDataItems: LineChartItem[];
public investment: number; public investment: number;
@ -30,6 +31,7 @@ export class PositionDetailDialog {
public maxPrice: number; public maxPrice: number;
public minPrice: number; public minPrice: number;
public quantity: number; public quantity: number;
public transactionCount: number;
public constructor( public constructor(
private cd: ChangeDetectorRef, private cd: ChangeDetectorRef,
@ -44,18 +46,21 @@ export class PositionDetailDialog {
averagePrice, averagePrice,
currency, currency,
firstBuyDate, firstBuyDate,
grossPerformance,
grossPerformancePercent, grossPerformancePercent,
historicalData, historicalData,
investment, investment,
marketPrice, marketPrice,
maxPrice, maxPrice,
minPrice, minPrice,
quantity quantity,
transactionCount
}) => { }) => {
this.averagePrice = averagePrice; this.averagePrice = averagePrice;
this.benchmarkDataItems = []; this.benchmarkDataItems = [];
this.currency = currency; this.currency = currency;
this.firstBuyDate = firstBuyDate; this.firstBuyDate = firstBuyDate;
this.grossPerformance = quantity * grossPerformance;
this.grossPerformancePercent = grossPerformancePercent; this.grossPerformancePercent = grossPerformancePercent;
this.historicalDataItems = historicalData.map( this.historicalDataItems = historicalData.map(
(historicalDataItem) => { (historicalDataItem) => {
@ -75,6 +80,7 @@ export class PositionDetailDialog {
this.maxPrice = maxPrice; this.maxPrice = maxPrice;
this.minPrice = minPrice; this.minPrice = minPrice;
this.quantity = quantity; this.quantity = quantity;
this.transactionCount = transactionCount;
if (isToday(parseISO(this.firstBuyDate))) { if (isToday(parseISO(this.firstBuyDate))) {
// Add average price // Add average price

@ -21,19 +21,22 @@
<div class="row"> <div class="row">
<div class="col-6 mb-3"> <div class="col-6 mb-3">
<gf-value <gf-value
label="Performance" label="Change"
size="medium" size="medium"
[colorizeSign]="true" [colorizeSign]="true"
[isPercent]="true" [currency]="data.baseCurrency"
[locale]="data.locale" [locale]="data.locale"
[value]="grossPerformancePercent" [value]="grossPerformance"
></gf-value> ></gf-value>
</div> </div>
<div class="col-6 mb-3"> <div class="col-6 mb-3">
<gf-value <gf-value
label="First Buy Date" label="Performance"
size="medium" size="medium"
[value]="firstBuyDate" [colorizeSign]="true"
[isPercent]="true"
[locale]="data.locale"
[value]="grossPerformancePercent"
></gf-value> ></gf-value>
</div> </div>
<div class="col-6 mb-3"> <div class="col-6 mb-3">
@ -91,6 +94,22 @@
[value]="investment" [value]="investment"
></gf-value> ></gf-value>
</div> </div>
<div class="col-6 mb-3">
<gf-value
label="First Buy Date"
size="medium"
[value]="firstBuyDate"
></gf-value>
</div>
<div class="col-6 mb-3">
<gf-value
label="Transactions"
size="medium"
[isCurrency]="true"
[locale]="data.locale"
[value]="transactionCount"
></gf-value>
</div>
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save