Skip to content

Commit

Permalink
Improved TimeSeries options.
Browse files Browse the repository at this point in the history
  • Loading branch information
bre1470 committed Jul 23, 2024
1 parent 681084d commit ca85cec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/TimeSeries/Converters/TimeSeriesDividendConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class TimeSeriesDividendConverter extends MorningstarConverter {
...this.options,
...options
};
const includeCurrency = userOptions.includeCurrency;
const json = userOptions.json;

// Validate JSON
Expand Down Expand Up @@ -141,7 +142,9 @@ export class TimeSeriesDividendConverter extends MorningstarConverter {

for (const securityId of securityIds) {
table.setColumn(securityId);
table.setColumn(`${securityId}_CID`);
if (includeCurrency) {
table.setColumn(`${securityId}_Currency`);
}
}

// Add dividends to table
Expand All @@ -155,7 +158,9 @@ export class TimeSeriesDividendConverter extends MorningstarConverter {
table.setCell('Date', ++currentTableIndex, currentTableDate);
}
table.setCell(dividend.Id, currentTableIndex, dividend.Value);
table.setCell(`${dividend.Id}_CID`, currentTableIndex, dividend.CurrencyId);
if (includeCurrency) {
table.setCell(`${dividend.Id}_Currency`, currentTableIndex, dividend.CurrencyId);
}
}

}
Expand Down
16 changes: 12 additions & 4 deletions src/TimeSeries/TimeSeriesConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,19 @@ class TimeSeriesConnector extends MorningstarConnector {

public override async load(): Promise<this> {
const options = this.options;
const url = new MorningstarURL('timeseries/cumulativereturn');
const api = new MorningstarAPI(options.api);
const securities = options.securities;
const tax = options.tax;

if (options.securities) {
url.searchParams.setSecurityOptions(options.securities);
if (securities) {
const url = new MorningstarURL('timeseries/cumulativereturn');
const searchParams = url.searchParams;
const api = new MorningstarAPI(options.api);

searchParams.setSecurityOptions(securities);

if (tax) {
searchParams.set('tax', tax);
}

const response = await api.fetch(url);
const json = await response.json() as unknown;
Expand Down
13 changes: 11 additions & 2 deletions src/TimeSeries/TimeSeriesOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export interface TimeSeriesCumulativeReturnOptions extends TimeSeriesConverterOp

export interface TimeSeriesDividendOptions extends TimeSeriesConverterOptions {

/**
* Whether to include currency information as an additional column for each
* security (`true`), or not (`false`). The name of the additional column
* has the format `[SID]_Currency`, e.g. `F0GBR04S23_Currency`.
*
* @default false
*/
includeCurrency?: boolean;

/**
* Series type to retrieve.
*/
Expand Down Expand Up @@ -114,12 +123,12 @@ export interface TimeSeriesOptions extends MorningstarOptions {
/**
* Type-based series options.
*/
series: TimeSeriesType;
series?: TimeSeriesType;

/**
* Tax option.
*/
tax: ('pretax'|'posttax');
tax?: ('pretax'|'posttax');

}

Expand Down

0 comments on commit ca85cec

Please sign in to comment.