Browse Source

Bugfix/empty historical market data in asset profile dialog for asset profiles without activities (#7623)

* Fix empty historical market data for asset profiles without activities

* Update changelog
pull/7628/head
Thomas Kaul 4 days ago
committed by GitHub
parent
commit
4926d59d4d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 114
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts

1
CHANGELOG.md

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed the cash balance update related to activities in a custom currency - Fixed the cash balance update related to activities in a custom currency
- Fixed the empty historical market data of the asset profile dialog of the admin control panel for asset profiles without activities
- Fixed the missing mapping for Czech Republic in the country weightings of the _Financial Modeling Prep_ service - Fixed the missing mapping for Czech Republic in the country weightings of the _Financial Modeling Prep_ service
- Fixed the missing mapping for Macau in the data enhancer for asset profile data via _Yahoo Finance_ - Fixed the missing mapping for Macau in the data enhancer for asset profile data via _Yahoo Finance_
- Fixed the outdated exchange rates of currency pairs which are calculated indirectly via the base currency - Fixed the outdated exchange rates of currency pairs which are calculated indirectly via the base currency

114
libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts

@ -41,7 +41,6 @@ import {
parse, parse,
parseISO parseISO
} from 'date-fns'; } from 'date-fns';
import { first, last } from 'lodash';
import ms from 'ms'; import ms from 'ms';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { parse as csvToJson } from 'papaparse'; import { parse as csvToJson } from 'papaparse';
@ -123,75 +122,78 @@ export class GfHistoricalMarketDataEditorComponent
} }
public ngOnChanges() { public ngOnChanges() {
if (this.dateOfFirstActivity) { const startDate = this.dateOfFirstActivity ?? this.marketData()[0]?.date;
let date = this.dateOfFirstActivity;
if (!startDate) {
const missingMarketData: { date: Date; marketPrice?: number }[] = []; return;
}
if (this.historicalDataItems()?.[0]?.date) {
while ( let date = startDate;
isBefore(
date, const missingMarketData: { date: Date; marketPrice?: number }[] = [];
parse(this.historicalDataItems()[0].date, DATE_FORMAT, new Date())
)
) {
missingMarketData.push({
date,
marketPrice: undefined
});
date = addDays(date, 1);
}
}
const marketDataItems = [...missingMarketData, ...this.marketData()]; if (this.historicalDataItems()?.[0]?.date) {
while (
isBefore(
date,
parse(this.historicalDataItems()[0].date, DATE_FORMAT, new Date())
)
) {
missingMarketData.push({
date,
marketPrice: undefined
});
const lastDate = last(marketDataItems)?.date; date = addDays(date, 1);
if (!lastDate || !isToday(lastDate)) {
marketDataItems.push({ date: new Date() });
} }
}
this.marketDataByMonth = {}; const marketDataItems = [...missingMarketData, ...this.marketData()];
for (const marketDataItem of marketDataItems) { const lastDate = marketDataItems.at(-1)?.date;
const currentDay = parseInt(format(marketDataItem.date, 'd'), 10); if (!lastDate || !isToday(lastDate)) {
const key = format(marketDataItem.date, 'yyyy-MM'); marketDataItems.push({ date: new Date() });
}
if (!this.marketDataByMonth[key]) { this.marketDataByMonth = {};
this.marketDataByMonth[key] = {};
} for (const marketDataItem of marketDataItems) {
const currentDay = parseInt(format(marketDataItem.date, 'd'), 10);
const key = format(marketDataItem.date, 'yyyy-MM');
this.marketDataByMonth[key][ if (!this.marketDataByMonth[key]) {
currentDay < 10 ? `0${currentDay}` : currentDay this.marketDataByMonth[key] = {};
] = {
date: marketDataItem.date,
day: currentDay,
marketPrice: marketDataItem.marketPrice
};
} }
// Fill up missing months this.marketDataByMonth[key][
const dates = Object.keys(this.marketDataByMonth).sort(); currentDay < 10 ? `0${currentDay}` : currentDay
const startDateString = first(dates); ] = {
const startDate = min([ date: marketDataItem.date,
this.dateOfFirstActivity, day: currentDay,
...(startDateString ? [parseISO(startDateString)] : []) marketPrice: marketDataItem.marketPrice
]); };
const endDateString = last(dates); }
if (endDateString) { // Fill up missing months
const endDate = parseISO(endDateString); const dates = Object.keys(this.marketDataByMonth).sort();
const startDateString = dates[0];
const endDateString = dates.at(-1);
let currentDate = startDate; if (endDateString) {
const endDate = parseISO(endDateString);
while (isBefore(currentDate, endDate)) { let currentDate = min([
const key = format(currentDate, 'yyyy-MM'); startDate,
if (!this.marketDataByMonth[key]) { ...(startDateString ? [parseISO(startDateString)] : [])
this.marketDataByMonth[key] = {}; ]);
}
currentDate = addMonths(currentDate, 1); while (isBefore(currentDate, endDate)) {
const key = format(currentDate, 'yyyy-MM');
if (!this.marketDataByMonth[key]) {
this.marketDataByMonth[key] = {};
} }
currentDate = addMonths(currentDate, 1);
} }
} }
} }

Loading…
Cancel
Save