@decafhub/decaf-client-extras 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/.editorconfig +9 -0
  2. package/.env.example +4 -0
  3. package/.eslintignore +3 -0
  4. package/.eslintrc.js +23 -0
  5. package/.github/workflows/release-please.yml +47 -0
  6. package/.github/workflows/test.yml +29 -0
  7. package/.husky/commit-msg +4 -0
  8. package/.husky/pre-commit +4 -0
  9. package/.release-please-manifest.json +3 -0
  10. package/CHANGELOG.md +13 -0
  11. package/LICENSE +21 -0
  12. package/README.md +10 -0
  13. package/commons/-currency.d.ts +42 -0
  14. package/commons/-currency.js +50 -0
  15. package/commons/-date-type.d.ts +11 -0
  16. package/commons/-date-type.js +10 -0
  17. package/commons/-id.d.ts +58 -0
  18. package/commons/-id.js +2 -0
  19. package/commons/index.d.ts +3 -0
  20. package/commons/index.js +19 -0
  21. package/es/commons/-currency.d.ts +42 -0
  22. package/es/commons/-currency.js +44 -0
  23. package/es/commons/-date-type.d.ts +11 -0
  24. package/es/commons/-date-type.js +7 -0
  25. package/es/commons/-id.d.ts +58 -0
  26. package/es/commons/-id.js +1 -0
  27. package/es/commons/index.d.ts +3 -0
  28. package/es/commons/index.js +3 -0
  29. package/es/index.d.ts +3 -0
  30. package/es/index.js +3 -0
  31. package/es/reports/index.d.ts +1 -0
  32. package/es/reports/index.js +1 -0
  33. package/es/reports/valuation/-remote-valuation-report-consolidated.d.ts +69 -0
  34. package/es/reports/valuation/-remote-valuation-report-consolidated.js +56 -0
  35. package/es/reports/valuation/-remote-valuation-report-portfolio.d.ts +150 -0
  36. package/es/reports/valuation/-remote-valuation-report-portfolio.js +134 -0
  37. package/es/reports/valuation/-remote-valuation-report-shared.d.ts +233 -0
  38. package/es/reports/valuation/-remote-valuation-report-shared.js +127 -0
  39. package/es/reports/valuation/-valuation-report-consolidated.d.ts +35 -0
  40. package/es/reports/valuation/-valuation-report-consolidated.js +1 -0
  41. package/es/reports/valuation/-valuation-report-holdings-tree/-machinery.d.ts +10 -0
  42. package/es/reports/valuation/-valuation-report-holdings-tree/-machinery.js +116 -0
  43. package/es/reports/valuation/-valuation-report-holdings-tree/-types.d.ts +23 -0
  44. package/es/reports/valuation/-valuation-report-holdings-tree/-types.js +1 -0
  45. package/es/reports/valuation/-valuation-report-holdings-tree/-utils.d.ts +1 -0
  46. package/es/reports/valuation/-valuation-report-holdings-tree/-utils.js +12 -0
  47. package/es/reports/valuation/-valuation-report-holdings-tree/index.d.ts +2 -0
  48. package/es/reports/valuation/-valuation-report-holdings-tree/index.js +2 -0
  49. package/es/reports/valuation/-valuation-report-portfolio.d.ts +79 -0
  50. package/es/reports/valuation/-valuation-report-portfolio.js +1 -0
  51. package/es/reports/valuation/-valuation-report-shared.d.ts +189 -0
  52. package/es/reports/valuation/-valuation-report-shared.js +6 -0
  53. package/es/reports/valuation/index.d.ts +8 -0
  54. package/es/reports/valuation/index.js +6 -0
  55. package/index.d.ts +3 -0
  56. package/index.js +32 -0
  57. package/jest.config.js +6 -0
  58. package/package.json +79 -0
  59. package/postinstall.sh +16 -0
  60. package/release-please-config.json +9 -0
  61. package/reports/index.d.ts +1 -0
  62. package/reports/index.js +27 -0
  63. package/reports/valuation/-remote-valuation-report-consolidated.d.ts +69 -0
  64. package/reports/valuation/-remote-valuation-report-consolidated.js +113 -0
  65. package/reports/valuation/-remote-valuation-report-portfolio.d.ts +150 -0
  66. package/reports/valuation/-remote-valuation-report-portfolio.js +191 -0
  67. package/reports/valuation/-remote-valuation-report-shared.d.ts +233 -0
  68. package/reports/valuation/-remote-valuation-report-shared.js +145 -0
  69. package/reports/valuation/-valuation-report-consolidated.d.ts +35 -0
  70. package/reports/valuation/-valuation-report-consolidated.js +2 -0
  71. package/reports/valuation/-valuation-report-holdings-tree/-machinery.d.ts +10 -0
  72. package/reports/valuation/-valuation-report-holdings-tree/-machinery.js +189 -0
  73. package/reports/valuation/-valuation-report-holdings-tree/-types.d.ts +23 -0
  74. package/reports/valuation/-valuation-report-holdings-tree/-types.js +2 -0
  75. package/reports/valuation/-valuation-report-holdings-tree/-utils.d.ts +1 -0
  76. package/reports/valuation/-valuation-report-holdings-tree/-utils.js +16 -0
  77. package/reports/valuation/-valuation-report-holdings-tree/index.d.ts +2 -0
  78. package/reports/valuation/-valuation-report-holdings-tree/index.js +20 -0
  79. package/reports/valuation/-valuation-report-portfolio.d.ts +79 -0
  80. package/reports/valuation/-valuation-report-portfolio.js +2 -0
  81. package/reports/valuation/-valuation-report-shared.d.ts +189 -0
  82. package/reports/valuation/-valuation-report-shared.js +11 -0
  83. package/reports/valuation/index.d.ts +8 -0
  84. package/reports/valuation/index.js +25 -0
  85. package/shell.nix +21 -0
  86. package/src/commons/-currency.ts +55 -0
  87. package/src/commons/-date-type.ts +12 -0
  88. package/src/commons/-id.ts +72 -0
  89. package/src/commons/index.ts +3 -0
  90. package/src/index.test.ts +67 -0
  91. package/src/index.ts +3 -0
  92. package/src/reports/index.ts +1 -0
  93. package/src/reports/valuation/-remote-valuation-report-consolidated.ts +121 -0
  94. package/src/reports/valuation/-remote-valuation-report-portfolio.ts +294 -0
  95. package/src/reports/valuation/-remote-valuation-report-shared.ts +313 -0
  96. package/src/reports/valuation/-valuation-report-consolidated.ts +46 -0
  97. package/src/reports/valuation/-valuation-report-holdings-tree/-machinery.ts +171 -0
  98. package/src/reports/valuation/-valuation-report-holdings-tree/-types.ts +25 -0
  99. package/src/reports/valuation/-valuation-report-holdings-tree/-utils.ts +15 -0
  100. package/src/reports/valuation/-valuation-report-holdings-tree/index.ts +2 -0
  101. package/src/reports/valuation/-valuation-report-portfolio.ts +92 -0
  102. package/src/reports/valuation/-valuation-report-shared.ts +217 -0
  103. package/src/reports/valuation/index.ts +8 -0
  104. package/tsconfig.es.json +13 -0
  105. package/tsconfig.json +36 -0
  106. package/typedoc.json +8 -0
@@ -0,0 +1,121 @@
1
+ import { DecafClient } from '@decafhub/decaf-client';
2
+ import { CustomError, customError, Either, Left, Right, SDate } from '@telostat/prelude';
3
+ import { CurrencyCode, DateType } from '../../commons';
4
+ import { recompileBaseValuationReport, RemoteBaseValuationReport } from './-remote-valuation-report-shared';
5
+ import {
6
+ ConsolidatedValuationReport,
7
+ ConsolidatedValuationReportContainer,
8
+ ConsolidatedValuationReportContainerType,
9
+ } from './-valuation-report-consolidated';
10
+
11
+ /**
12
+ * Remote consolidated valuation report query type.
13
+ */
14
+ export interface ConsolidatedValuationReportQuery {
15
+ /**
16
+ * Date of valuation report.
17
+ */
18
+ date: SDate;
19
+
20
+ /**
21
+ * Date type of the valuation report.
22
+ */
23
+ dateType: DateType;
24
+
25
+ /**
26
+ * Reference currency of the valuation report.
27
+ */
28
+ currency: CurrencyCode;
29
+
30
+ /**
31
+ * Indication if we want to include/exclude sandbox portfolios (defaults to `true`).
32
+ */
33
+ sandbox?: boolean;
34
+
35
+ /**
36
+ * Container type.
37
+ */
38
+ containerType: ConsolidatedValuationReportContainerType;
39
+
40
+ /**
41
+ * Container elements (identifiers).
42
+ */
43
+ containerElements: (number | string)[];
44
+ }
45
+
46
+ /**
47
+ * Type definition for the remote (raw) consolidated valuation report data.
48
+ */
49
+ export interface RemoteConsolidatedValuationReport extends RemoteBaseValuationReport {
50
+ containers: {
51
+ level: ConsolidatedValuationReportContainerType;
52
+ containers: ConsolidatedValuationReportContainer[];
53
+ };
54
+ }
55
+
56
+ /**
57
+ * Attempts to retrieve remote consolidated valuation report.
58
+ *
59
+ * @param client DECAF Barista client.
60
+ * @param query Remote consolidated valuation report endpoint query parameters.
61
+ * @returns Remote (raw) consolidated valuation report data.
62
+ */
63
+ export function fetchRemoteConsolidatedValuationReport(
64
+ client: DecafClient,
65
+ query: ConsolidatedValuationReportQuery
66
+ ): Promise<Either<CustomError, RemoteConsolidatedValuationReport>> {
67
+ return client.barista
68
+ .get<RemoteConsolidatedValuationReport>('/consolidation/', {
69
+ params: {
70
+ ccy: query.currency,
71
+ date: query.date,
72
+ type: query.dateType,
73
+ sandbox: query.sandbox,
74
+ c: query.containerType,
75
+ i: query.containerElements,
76
+ },
77
+ })
78
+ .then((x) => Right(x.data))
79
+ .catch((err) => Left(customError('Error while attempting to fetch remote consolidated valuation report', err)));
80
+ }
81
+
82
+ /**
83
+ * Attempts to re-compile the raw, remote consolidated valuation report and
84
+ * return it.
85
+ *
86
+ * @param x Raw, remote consolidated valuation report.
87
+ * @returns Either of an error message or the re-compiled consolidated valuation
88
+ * report.
89
+ */
90
+ export function recompileConsolidatedValuationReport(
91
+ x: RemoteConsolidatedValuationReport
92
+ ): Either<CustomError, ConsolidatedValuationReport> {
93
+ // Attempt to get the base valuation report:
94
+ const baseReport = recompileBaseValuationReport(x);
95
+
96
+ // Add consolidated valuation report specific fields and return:
97
+ return baseReport.map((report) => ({
98
+ ...report,
99
+ containerType: x.containers.level,
100
+ containers: x.containers.containers,
101
+ }));
102
+ }
103
+
104
+ /**
105
+ * Attempts to retrieve remote consolidated valuation report, compiles it to
106
+ * [[ConsolidatedValuationReport]] and return it.
107
+ *
108
+ * @param client DECAF Barista client.
109
+ * @param query Remote consolidated valuation report endpoint query parameters.
110
+ * @returns Recompiled consolidated valuation report data.
111
+ */
112
+ export async function fetchConsolidatedValuationReport(
113
+ client: DecafClient,
114
+ query: ConsolidatedValuationReportQuery
115
+ ): Promise<Either<CustomError, ConsolidatedValuationReport>> {
116
+ // Attempt to fetch the remote, raw report:
117
+ const rawReport = await fetchRemoteConsolidatedValuationReport(client, query);
118
+
119
+ // Attempt to recompile the report (if any) and return:
120
+ return rawReport.chain(recompileConsolidatedValuationReport);
121
+ }
@@ -0,0 +1,294 @@
1
+ import { DecafClient } from '@decafhub/decaf-client';
2
+ import {
3
+ asDecimal,
4
+ CustomError,
5
+ customError,
6
+ Either,
7
+ Left,
8
+ Maybe,
9
+ maybeDecimal,
10
+ Right,
11
+ sanitizedNonEmptyText,
12
+ SDate,
13
+ SDateTime,
14
+ zero,
15
+ } from '@telostat/prelude';
16
+ import {
17
+ ActionId,
18
+ CurrencyCode,
19
+ DateType,
20
+ ExternalValuationId,
21
+ OhlcSeriesId,
22
+ PortfolioId,
23
+ PrincipalId,
24
+ ShareClassFeeScheduleId,
25
+ ShareClassId,
26
+ } from '../../commons';
27
+ import { recompileBaseValuationReport, RemoteBaseValuationReport } from './-remote-valuation-report-shared';
28
+ import { PortfolioValuationReport, PortfolioValuationReportShareClassValue } from './-valuation-report-portfolio';
29
+ import { ValuationReportPortfolio } from './-valuation-report-shared';
30
+
31
+ /**
32
+ * Remote portfolio valuation report query type.
33
+ */
34
+ export interface PortfolioValuationReportQuery {
35
+ /**
36
+ * Date of valuation report.
37
+ */
38
+ date: SDate;
39
+
40
+ /**
41
+ * Date type of the valuation report.
42
+ */
43
+ dateType: DateType;
44
+
45
+ /**
46
+ * Reference currency of the valuation report.
47
+ */
48
+ currency: CurrencyCode;
49
+
50
+ /**
51
+ * Portfolio the valuation report is requested for.
52
+ */
53
+ portfolio: PortfolioId;
54
+ }
55
+
56
+ /**
57
+ * Type definition for the remote (raw) portfolio valuation report data.
58
+ */
59
+ export interface RemotePortfolioValuationReport extends RemoteBaseValuationReport {
60
+ portfolio: ValuationReportPortfolio;
61
+ scvals: RemoteValuationShareClassValue[];
62
+ subscriptions?: number;
63
+ }
64
+
65
+ /**
66
+ * Type definition for share class valuation on the remote portfolio valuation
67
+ * report.
68
+ */
69
+ export interface RemoteValuationShareClassValue {
70
+ shareclass: RemoteValuationShareClass;
71
+ external?: RemoteValuationExternalValue;
72
+ nav: number;
73
+ nav_adjusted: number;
74
+ nav_adjusted_total: number;
75
+ coefficient: number;
76
+ gav_refccy: number;
77
+ gav_clsccy: number;
78
+ sharecount_prev: number;
79
+ sharecount_curr: number;
80
+ sharecount_diff: number;
81
+ px_refccy: number;
82
+ px_clsccy: number;
83
+ ytdext?: number;
84
+ ytdint?: number;
85
+ }
86
+
87
+ /**
88
+ * Type definition for share class on the remote portfolio valuation report.
89
+ */
90
+ export interface RemoteValuationShareClass {
91
+ id: ShareClassId;
92
+ created: SDateTime;
93
+ creator: PrincipalId;
94
+ updated: SDateTime;
95
+ updater: PrincipalId;
96
+ guid: string;
97
+ portfolio: PortfolioId;
98
+ name: string;
99
+ currency: CurrencyCode;
100
+ isin?: string;
101
+ bbgticker?: string;
102
+ liquidity?: string;
103
+ jurisdiction?: string;
104
+ administrator?: string;
105
+ mininvestment?: string;
106
+ subredperiod?: string;
107
+ freqmngt?: number;
108
+ freqperf?: number;
109
+ benchmark?: OhlcSeriesId;
110
+ description?: string;
111
+ feeschedules: ShareClassFeeScheduleId[];
112
+ effectivefeeschedule?: ShareClassFeeScheduleId;
113
+ subscriptions: ActionId[];
114
+ outstanding?: number;
115
+ }
116
+
117
+ /**
118
+ * Type definition for external valuation on the remote portfolio valuation
119
+ * report.
120
+ */
121
+ export interface RemoteValuationExternalValue {
122
+ id: ExternalValuationId;
123
+ created: SDateTime;
124
+ creator: PrincipalId;
125
+ updated: SDateTime;
126
+ updater: PrincipalId;
127
+ guid: string;
128
+ portfolio: PortfolioId;
129
+ shareclass?: ShareClassId;
130
+ date: SDate;
131
+ ccy: CurrencyCode;
132
+ shares?: number;
133
+ price?: number;
134
+ nav?: number;
135
+ aum?: number;
136
+ hedgepnl?: number;
137
+ feemngt?: number;
138
+ feeperf?: number;
139
+ otheraccrued?: number;
140
+ totalaccrued?: number;
141
+ subred?: number;
142
+ perfdaily?: number;
143
+ perfweekly?: number;
144
+ perfmonthly?: number;
145
+ perfytd?: number;
146
+ perfstart?: number;
147
+ coefficient?: number;
148
+ }
149
+
150
+ /**
151
+ * Attempts to retrieve remote portfolio valuation report.
152
+ *
153
+ * @param client DECAF Barista client.
154
+ * @param query Remote portfolio valuation report endpoint query parameters.
155
+ * @returns Remote (raw) portfolio valuation report data.
156
+ */
157
+ export function fetchRemotePortfolioValuationReport(
158
+ client: DecafClient,
159
+ query: PortfolioValuationReportQuery
160
+ ): Promise<Either<CustomError, RemotePortfolioValuationReport>> {
161
+ return client.barista
162
+ .get<RemotePortfolioValuationReport>('/portfolioreport/', {
163
+ params: {
164
+ ccy: query.currency,
165
+ date: query.date,
166
+ type: query.dateType,
167
+ portfolio: `${query.portfolio}`,
168
+ },
169
+ })
170
+ .then((x) => Right(x.data))
171
+ .catch((err) => Left(customError('Error while attempting to fetch remote portfolio valuation report', err)));
172
+ }
173
+
174
+ /**
175
+ * Attempts to recompile remote valuation report share class value.
176
+ *
177
+ * @param x remote valuation report share class value object.
178
+ * @return Recompiled valuation report share class value object.
179
+ */
180
+ export function toShareClassValue(x: RemoteValuationShareClassValue): PortfolioValuationReportShareClassValue {
181
+ return {
182
+ shareclass: {
183
+ id: x.shareclass.id,
184
+ created: x.shareclass.created,
185
+ creator: Maybe.fromNullable(x.shareclass.creator),
186
+ updated: x.shareclass.updated,
187
+ updater: Maybe.fromNullable(x.shareclass.updater),
188
+ guid: x.shareclass.guid,
189
+ portfolio: x.shareclass.portfolio,
190
+ name: x.shareclass.name,
191
+ currency: x.shareclass.currency,
192
+ isin: sanitizedNonEmptyText(x.shareclass.isin),
193
+ bbgticker: sanitizedNonEmptyText(x.shareclass.bbgticker),
194
+ liquidity: sanitizedNonEmptyText(x.shareclass.liquidity),
195
+ jurisdiction: sanitizedNonEmptyText(x.shareclass.jurisdiction),
196
+ administrator: sanitizedNonEmptyText(x.shareclass.administrator),
197
+ minimumInvestment: sanitizedNonEmptyText(x.shareclass.mininvestment),
198
+ subscriptionRedemptionPeriod: sanitizedNonEmptyText(x.shareclass.subredperiod),
199
+ managementFeeFrequency: Maybe.fromNullable(x.shareclass.freqmngt),
200
+ performanceFeeFrequency: Maybe.fromNullable(x.shareclass.freqperf),
201
+ benchmark: Maybe.fromNullable(x.shareclass.benchmark),
202
+ description: sanitizedNonEmptyText(x.shareclass.description),
203
+ feeScheduleIds: x.shareclass.feeschedules,
204
+ effectiveFeeScheduleId: Maybe.fromNullable(x.shareclass.effectivefeeschedule),
205
+ subscriptionIds: x.shareclass.subscriptions,
206
+ outstanding: maybeDecimal(x.shareclass.outstanding),
207
+ },
208
+ external: Maybe.fromNullable(x.external).map((ev) => ({
209
+ id: ev.id,
210
+ created: ev.created,
211
+ creator: Maybe.fromNullable(ev.updater),
212
+ updated: ev.updated,
213
+ updater: Maybe.fromNullable(ev.updater),
214
+ guid: ev.guid,
215
+ portfolio: ev.portfolio,
216
+ shareclass: Maybe.fromNullable(ev.shareclass),
217
+ date: ev.date,
218
+ ccy: ev.ccy,
219
+ shares: maybeDecimal(ev.shares),
220
+ price: maybeDecimal(ev.price),
221
+ nav: maybeDecimal(ev.nav),
222
+ aum: maybeDecimal(ev.aum),
223
+ hedgepnl: maybeDecimal(ev.hedgepnl),
224
+ feemngt: maybeDecimal(ev.feemngt),
225
+ feeperf: maybeDecimal(ev.feeperf),
226
+ otheraccrued: maybeDecimal(ev.otheraccrued),
227
+ totalaccrued: maybeDecimal(ev.totalaccrued),
228
+ subred: maybeDecimal(ev.subred),
229
+ perfdaily: maybeDecimal(ev.perfdaily),
230
+ perfweekly: maybeDecimal(ev.perfweekly),
231
+ perfmonthly: maybeDecimal(ev.perfmonthly),
232
+ perfytd: maybeDecimal(ev.perfytd),
233
+ perfstart: maybeDecimal(ev.perfstart),
234
+ coefficient: maybeDecimal(ev.coefficient),
235
+ })),
236
+ nav: asDecimal(x.nav),
237
+ navAdjusted: asDecimal(x.nav_adjusted),
238
+ navAdjustedTotal: asDecimal(x.nav_adjusted_total),
239
+ coefficient: asDecimal(x.coefficient),
240
+ gavRefccy: asDecimal(x.gav_refccy),
241
+ gavClsccy: asDecimal(x.gav_clsccy),
242
+ sharecountPrev: asDecimal(x.sharecount_prev),
243
+ sharecountCurr: asDecimal(x.sharecount_curr),
244
+ sharecountDiff: asDecimal(x.sharecount_diff),
245
+ pxRefCcy: asDecimal(x.px_refccy),
246
+ pxClsCcy: asDecimal(x.px_clsccy),
247
+ ytdExt: maybeDecimal(x.ytdext),
248
+ ytdInt: maybeDecimal(x.ytdint),
249
+ };
250
+ }
251
+
252
+ /**
253
+ * Attempts to re-compile the raw, remote portfolio valuation report and
254
+ * return it.
255
+ *
256
+ * @param x Raw, remote portfolio valuation report.
257
+ * @returns Either of an error message or the re-compiled portfolio valuation
258
+ * report.
259
+ */
260
+ export function recompilePortfolioValuationReport(
261
+ x: RemotePortfolioValuationReport
262
+ ): Either<CustomError, PortfolioValuationReport> {
263
+ // Attempt to get the base valuation report:
264
+ const baseReport = recompileBaseValuationReport(x);
265
+
266
+ // Add consolidated valuation report specific fields and return:
267
+ return baseReport.map((report) => {
268
+ return {
269
+ ...report,
270
+ portfolio: x.portfolio,
271
+ subscriptions: maybeDecimal(x.subscriptions).orDefault(zero),
272
+ shareClassValues: x.scvals.map(toShareClassValue),
273
+ };
274
+ });
275
+ }
276
+
277
+ /**
278
+ * Attempts to retrieve remote portfolio valuation report, compiles it to
279
+ * [[PortfolioValuationReport]] and return it.
280
+ *
281
+ * @param client DECAF Barista client.
282
+ * @param query Remote portolio valuation report endpoint query parameters.
283
+ * @returns Recompiled portolio valuation report data.
284
+ */
285
+ export async function fetchPortfolioValuationReport(
286
+ client: DecafClient,
287
+ query: PortfolioValuationReportQuery
288
+ ): Promise<Either<CustomError, PortfolioValuationReport>> {
289
+ // Attempt to fetch the remote, raw report:
290
+ const rawReport = await fetchRemotePortfolioValuationReport(client, query);
291
+
292
+ // Attempt to recompile the report (if any) and return:
293
+ return rawReport.chain(recompilePortfolioValuationReport);
294
+ }