diff --git a/src/XRay/XRayConverter.ts b/src/XRay/XRayConverter.ts index 7fc1d7f..0a157b4 100644 --- a/src/XRay/XRayConverter.ts +++ b/src/XRay/XRayConverter.ts @@ -127,16 +127,18 @@ export class XRayConverter extends MorningstarConverter { table.setColumn(`${benchmarkId}_Values`); - for (const asset of json.assetAllocation) { - const columnName = `${benchmarkId}_${asset.type}_${asset.salePosition}`; - table.setColumn(columnName); - const values = asset.values; + if (json.assetAllocation) { + for (const asset of json.assetAllocation) { + const columnName = `${benchmarkId}_${asset.type}_${asset.salePosition}`; + table.setColumn(columnName); + const values = asset.values; - const valueIndex = Object.keys(values); + const valueIndex = Object.keys(values); - for (let i = 0; i < valueIndex.length; i++) { - table.setCell(`${benchmarkId}_Values`, i, valueIndex[i]); - table.setCell(columnName, i, values[parseInt(valueIndex[i])]); + for (let i = 0; i < valueIndex.length; i++) { + table.setCell(`${benchmarkId}_Values`, i, valueIndex[i]); + table.setCell(columnName, i, values[parseInt(valueIndex[i])]); + } } } @@ -154,6 +156,20 @@ export class XRayConverter extends MorningstarConverter { } } + if (json.globalStockSector) { + for (const sector of json.globalStockSector) { + const columnName = `${benchmarkId}_GlobalStockSector_${sector.salePosition}`; + table.setColumn(columnName); + const values = sector.values; + const valueIndex = Object.keys(values); + + for (let i = 0; i < valueIndex.length; i++) { + table.setCell(`${benchmarkId}_Values`, i, valueIndex[i]); + table.setCell(columnName, i, values[parseInt(valueIndex[i])]); + } + } + } + } protected parseHistoricalPerformance ( diff --git a/src/XRay/XRayJSON.ts b/src/XRay/XRayJSON.ts index f3d4d65..45eed62 100644 --- a/src/XRay/XRayJSON.ts +++ b/src/XRay/XRayJSON.ts @@ -49,6 +49,7 @@ namespace XRayJSON { export interface Breakdowns { assetAllocation: Array; regionalExposure?: Array; + globalStockSector?: Array; } @@ -72,6 +73,11 @@ namespace XRayJSON { values: Record; } + export interface GlobalStockSector { + salePosition: string; + values: Record; + } + export interface Response { XRay: Array; @@ -127,6 +133,17 @@ namespace XRayJSON { ); } + function isGlobalStockSector ( + json?: unknown + ): json is GlobalStockSector { + return ( + !!json && + typeof json === 'object' && + typeof (json as GlobalStockSector).salePosition === 'string' && + typeof (json as GlobalStockSector).values === 'object' + ); + } + function isBenchmark ( json?: unknown @@ -176,9 +193,12 @@ namespace XRayJSON { ( (json as Breakdowns).assetAllocation.length === 0 || isAssetAllocation((json as Breakdowns).assetAllocation[0]) - ) && ( + ) || ( !(json as Breakdowns).regionalExposure || checkRegionalExposure((json as Breakdowns).regionalExposure) + ) || ( + !(json as Breakdowns).globalStockSector || + isGlobalStockSector((json as Breakdowns).globalStockSector?.[0]) ) ); }