Skip to content

Commit

Permalink
Added support for in XRay.
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-musialowski committed Dec 9, 2024
1 parent 974e406 commit 122730e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
32 changes: 24 additions & 8 deletions src/XRay/XRayConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])]);
}
}
}

Expand All @@ -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 (
Expand Down
22 changes: 21 additions & 1 deletion src/XRay/XRayJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace XRayJSON {
export interface Breakdowns {
assetAllocation: Array<AssetAllocation>;
regionalExposure?: Array<RegionalExposure>;
globalStockSector?: Array<GlobalStockSector>;
}


Expand All @@ -72,6 +73,11 @@ namespace XRayJSON {
values: Record<number, number>;
}

export interface GlobalStockSector {
salePosition: string;
values: Record<number, number>;
}


export interface Response {
XRay: Array<XRayResponse>;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
)
);
}
Expand Down

0 comments on commit 122730e

Please sign in to comment.