Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security Details Portfolios data #55

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions src/SecurityDetails/Converters/AssetAllocationsConverter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/* *
*
* (c) 2009-2024 Highsoft AS
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* Authors:
* - Sophie Bremer
* - Pawel Lysy
* - Askel Eirik Johansson
*
* */


'use strict';


/* *
*
* Imports
*
* */


import {
SecurityDetailsConverterOptions,
SecurityDetailsMetadata
} from '../SecurityDetailsOptions';
import SecurityDetailsJSON from '../SecurityDetailsJSON';
import SecurityDetailsConverter from '../SecurityDetailsConverter';

/* *
*
* Class
*
* */


export class AssetAllocationsConverter extends SecurityDetailsConverter {


/* *
*
* Constructor
*
* */


public constructor (
options?: SecurityDetailsConverterOptions
) {
super(options);

this.metadata = {
columns: {}
};
}


/* *
*
* Properties
*
* */


public readonly metadata: SecurityDetailsMetadata;


/* *
*
* Functions
*
* */


public override parse (
options: SecurityDetailsConverterOptions
): void {
const metadata = this.metadata;
const table = this.table;
const userOptions = {
...this.options,
...options
};
const json = userOptions.json;

// Validate JSON

if (!SecurityDetailsJSON.isSecurityDetailsResponse(json)) {
throw new Error('Invalid data');
}

// Prepare table

table.deleteColumns();
table.setColumn('AssetAllocations_Type');

// Add asset allocations to table

if (json.length) {

// Update table

const securityDetails = json[0];
const assetAllocations = securityDetails.Portfolios[0].AssetAllocations;

table.setColumn('AssetAllocations_Type');

for (let i = 0; i < assetAllocations.length; i++) {
const asset = assetAllocations[i];

table.setColumn(`AssetAllocations_${asset.Type}_${asset.SalePosition}`);

for (let j = 0; j < asset.BreakdownValues.length; j++) {
table.setCell(
`AssetAllocations_${asset.Type}_${asset.SalePosition}`,
j,
asset.BreakdownValues[j].Value
);

table.setCell(
'AssetAllocations_Type',
j,
asset.BreakdownValues[j].Type
);
}
}

// Update meta data

metadata.id = securityDetails.Id;
metadata.isin = securityDetails.Isin;
}

}


}


/* *
*
* Default Export
*
* */


export default AssetAllocationsConverter;
151 changes: 151 additions & 0 deletions src/SecurityDetails/Converters/CountryExposureConverter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/* *
*
* (c) 2009-2024 Highsoft AS
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* Authors:
* - Sophie Bremer
* - Pawel Lysy
* - Askel Eirik Johansson
*
* */


'use strict';


/* *
*
* Imports
*
* */


import {
SecurityDetailsConverterOptions,
SecurityDetailsMetadata
} from '../SecurityDetailsOptions';
import SecurityDetailsJSON from '../SecurityDetailsJSON';
import SecurityDetailsConverter from '../SecurityDetailsConverter';

/* *
*
* Class
*
* */


export class CountryExposureConverter extends SecurityDetailsConverter {


/* *
*
* Constructor
*
* */


public constructor (
options?: SecurityDetailsConverterOptions
) {
super(options);

this.metadata = {
columns: {}
};
}


/* *
*
* Properties
*
* */


public readonly metadata: SecurityDetailsMetadata;


/* *
*
* Functions
*
* */


public override parse (
options: SecurityDetailsConverterOptions
): void {
const metadata = this.metadata;
const table = this.table;
const userOptions = {
...this.options,
...options
};
const json = userOptions.json;

// Validate JSON

if (!SecurityDetailsJSON.isSecurityDetailsResponse(json)) {
throw new Error('Invalid data');
}

// Prepare table

table.deleteColumns();
table.setColumn('CountryExposure_Type');

// Add country exposure to table

if (json.length) {

// Update table

const securityDetails = json[0];
const CountryExposure = securityDetails.Portfolios[0].CountryExposure;

table.setColumn('CountryExposure_Type');

for (let i = 0; i < CountryExposure.length; i++) {
const asset = CountryExposure[i];

table.setColumn(`CountryExposure_${asset.Type}_${asset.SalePosition}_${asset.NotClassified}`);

for (let j = 0; j < asset.BreakdownValues.length; j++) {
table.setCell(
`CountryExposure_${asset.Type}_${asset.SalePosition}_${asset.NotClassified}`,
j,
asset.BreakdownValues[j].Value
);

table.setCell(
'CountryExposure_Type',
j,
asset.BreakdownValues[j].Type
);
}
}

// Update meta data

metadata.id = securityDetails.Id;
metadata.isin = securityDetails.Isin;
}

}


}


/* *
*
* Default Export
*
* */


export default CountryExposureConverter;
Loading