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 16 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
1 change: 1 addition & 0 deletions demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h1>Morningstar Connectors Demos</h1>
<li><a href="stock-timeseries/demo.html">Highcharts Stock + Morningstar TimeSeries</a></li>
<li><a href="stock-ohlcv/demo.html">Highcharts Stock + Morningstar OHLCV TimeSeries</a></li>
<li><a href="stock-securitydetails/demo.html">Highcharts Stock + Morningstar Security Details</a></li>
<li><a href="stock-securitydetails-asset-allocations/demo.html">Morningstar Security Details Asset Allocations</a></li>
<li><a href="dashboards-risk-score/demo.html">Highcharts Dashboards + Morningstar Risk Score</a></li>
<li><a href="dashboards-investment-screener/demo.html">Highcharts Dashboards + Morningstar Investment Screener</a></li>
<li><a href="manual-fetch/demo.html">Using fetch without connectors</a></li>
Expand Down
23 changes: 23 additions & 0 deletions demos/stock-securitydetails-asset-allocations/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script src="https://code.highcharts.com/stock/highstock.src.js"></script>
<script src="https://code.highcharts.com/connectors/morningstar/connectors-morningstar.src.js"></script>
<title>Morningstar Security Details Asset Allocations</title>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<h1>Morningstar Security Details Asset Allocations</h1>
<p>
Add your Postman environment file from Morningstar to start the demo:
<input type="file" id="postman-json" accept=".json,application/json" />
</p>
<div id="container"></div>
<script src="./demo.js"></script>
</body>
</html>
73 changes: 73 additions & 0 deletions demos/stock-securitydetails-asset-allocations/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
async function displayAssetAllocations (postmanJSON) {
const securityId = 'US4642898674';

const connector = new HighchartsConnectors.Morningstar.SecurityDetailsConnector({
postman: {
environmentJSON: postmanJSON
},
security: {
id: securityId,
idType: 'ISIN'
},
type: 'AssetAllocations'
pawelfus marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong API option, demo doesn't work

});

await connector.load();

const typeMapping = {
'1': 'Stocks',
'2': 'Bonds',
'3': 'Cash',
'4': 'Other Instruments',
'99': 'Unclassified'
};

const chartData = connector.table.getRowObjects().map(item => ({
name: typeMapping[item.AssetAllocations_Type],
y: item.AssetAllocations_MorningstarEUR3_N
}));

Highcharts.chart('container', {
title: {
text: 'iShares Core Growth Allocation ETF (AOR) Asset Allocation'
},
subtitle: {
text: 'Type: MorningstarEUR3 | Sale Position: Net (N)'
},
series: [{
type: 'pie',
name: 'VTI Asset Allocation',
data: chartData
}]
});
}

async function handleSelectEnvironment (evt) {
const target = evt.target;
const postmanJSON = await getPostmanJSON(target);

target.parentNode.style.display = 'none';

displayAssetAllocations(postmanJSON);
}

document.getElementById('postman-json')
.addEventListener('change', handleSelectEnvironment);

async function getPostmanJSON (htmlInputFile) {
let file;
let fileJSON;

for (file of htmlInputFile.files) {
try {
fileJSON = JSON.parse(await file.text());
if (HighchartsConnectors.Morningstar.isPostmanEnvironmentJSON(fileJSON)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong path. Should be HighchartsConnectors.Morningstar.Shared.isPostmanEnvironmentJSON

break;
}
} catch (error) {
// fail silently
}
}

return fileJSON;
}
25 changes: 25 additions & 0 deletions docs/connectors/morningstar/security-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,31 @@ Supported id-types are: `CUSIP`, `FundCode`, `ISIN`, `MSID`, `PerformanceId`, `S

If any securities are invalid, the connector will still yield results. The invalid securities will appear in the connector's `metadata` after load.

#### Security Details Types

You can specify the type of data to retrieve by using the `type` option in the connector. The following types are available:

- **TrailingPerformance** (default)
- **AssetAllocations**
- **RegionalExposure**
- **GlobalStockSectorBreakdown**
- **CountryExposure**

Example usage:

```js
const securityDetailsConnector = new HighchartsConnectors.Morningstar.SecurityDetailsConnector({
postman: {
environmentJSON: postmanJSON
},
security: {
id: 'F0GBR050DD',
idType: 'MSID'
},
type: 'AssetAllocations' // Specify the type of data to retrieve
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong API option

});
```

For more details, see [Morningstar’s Security Details API].

### Security Details with Morningstar standalone for Highcharts:
Expand Down
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;
Loading
Loading