@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,56 @@
1
+ import { customError, Left, Right } from '@telostat/prelude';
2
+ import { recompileBaseValuationReport } from './-remote-valuation-report-shared';
3
+ /**
4
+ * Attempts to retrieve remote consolidated valuation report.
5
+ *
6
+ * @param client DECAF Barista client.
7
+ * @param query Remote consolidated valuation report endpoint query parameters.
8
+ * @returns Remote (raw) consolidated valuation report data.
9
+ */
10
+ export function fetchRemoteConsolidatedValuationReport(client, query) {
11
+ return client.barista
12
+ .get('/consolidation/', {
13
+ params: {
14
+ ccy: query.currency,
15
+ date: query.date,
16
+ type: query.dateType,
17
+ sandbox: query.sandbox,
18
+ c: query.containerType,
19
+ i: query.containerElements,
20
+ },
21
+ })
22
+ .then((x) => Right(x.data))
23
+ .catch((err) => Left(customError('Error while attempting to fetch remote consolidated valuation report', err)));
24
+ }
25
+ /**
26
+ * Attempts to re-compile the raw, remote consolidated valuation report and
27
+ * return it.
28
+ *
29
+ * @param x Raw, remote consolidated valuation report.
30
+ * @returns Either of an error message or the re-compiled consolidated valuation
31
+ * report.
32
+ */
33
+ export function recompileConsolidatedValuationReport(x) {
34
+ // Attempt to get the base valuation report:
35
+ const baseReport = recompileBaseValuationReport(x);
36
+ // Add consolidated valuation report specific fields and return:
37
+ return baseReport.map((report) => ({
38
+ ...report,
39
+ containerType: x.containers.level,
40
+ containers: x.containers.containers,
41
+ }));
42
+ }
43
+ /**
44
+ * Attempts to retrieve remote consolidated valuation report, compiles it to
45
+ * [[ConsolidatedValuationReport]] and return it.
46
+ *
47
+ * @param client DECAF Barista client.
48
+ * @param query Remote consolidated valuation report endpoint query parameters.
49
+ * @returns Recompiled consolidated valuation report data.
50
+ */
51
+ export async function fetchConsolidatedValuationReport(client, query) {
52
+ // Attempt to fetch the remote, raw report:
53
+ const rawReport = await fetchRemoteConsolidatedValuationReport(client, query);
54
+ // Attempt to recompile the report (if any) and return:
55
+ return rawReport.chain(recompileConsolidatedValuationReport);
56
+ }
@@ -0,0 +1,150 @@
1
+ import { DecafClient } from '@decafhub/decaf-client';
2
+ import { CustomError, Either, SDate, SDateTime } from '@telostat/prelude';
3
+ import { ActionId, CurrencyCode, DateType, ExternalValuationId, OhlcSeriesId, PortfolioId, PrincipalId, ShareClassFeeScheduleId, ShareClassId } from '../../commons';
4
+ import { RemoteBaseValuationReport } from './-remote-valuation-report-shared';
5
+ import { PortfolioValuationReport, PortfolioValuationReportShareClassValue } from './-valuation-report-portfolio';
6
+ import { ValuationReportPortfolio } from './-valuation-report-shared';
7
+ /**
8
+ * Remote portfolio valuation report query type.
9
+ */
10
+ export interface PortfolioValuationReportQuery {
11
+ /**
12
+ * Date of valuation report.
13
+ */
14
+ date: SDate;
15
+ /**
16
+ * Date type of the valuation report.
17
+ */
18
+ dateType: DateType;
19
+ /**
20
+ * Reference currency of the valuation report.
21
+ */
22
+ currency: CurrencyCode;
23
+ /**
24
+ * Portfolio the valuation report is requested for.
25
+ */
26
+ portfolio: PortfolioId;
27
+ }
28
+ /**
29
+ * Type definition for the remote (raw) portfolio valuation report data.
30
+ */
31
+ export interface RemotePortfolioValuationReport extends RemoteBaseValuationReport {
32
+ portfolio: ValuationReportPortfolio;
33
+ scvals: RemoteValuationShareClassValue[];
34
+ subscriptions?: number;
35
+ }
36
+ /**
37
+ * Type definition for share class valuation on the remote portfolio valuation
38
+ * report.
39
+ */
40
+ export interface RemoteValuationShareClassValue {
41
+ shareclass: RemoteValuationShareClass;
42
+ external?: RemoteValuationExternalValue;
43
+ nav: number;
44
+ nav_adjusted: number;
45
+ nav_adjusted_total: number;
46
+ coefficient: number;
47
+ gav_refccy: number;
48
+ gav_clsccy: number;
49
+ sharecount_prev: number;
50
+ sharecount_curr: number;
51
+ sharecount_diff: number;
52
+ px_refccy: number;
53
+ px_clsccy: number;
54
+ ytdext?: number;
55
+ ytdint?: number;
56
+ }
57
+ /**
58
+ * Type definition for share class on the remote portfolio valuation report.
59
+ */
60
+ export interface RemoteValuationShareClass {
61
+ id: ShareClassId;
62
+ created: SDateTime;
63
+ creator: PrincipalId;
64
+ updated: SDateTime;
65
+ updater: PrincipalId;
66
+ guid: string;
67
+ portfolio: PortfolioId;
68
+ name: string;
69
+ currency: CurrencyCode;
70
+ isin?: string;
71
+ bbgticker?: string;
72
+ liquidity?: string;
73
+ jurisdiction?: string;
74
+ administrator?: string;
75
+ mininvestment?: string;
76
+ subredperiod?: string;
77
+ freqmngt?: number;
78
+ freqperf?: number;
79
+ benchmark?: OhlcSeriesId;
80
+ description?: string;
81
+ feeschedules: ShareClassFeeScheduleId[];
82
+ effectivefeeschedule?: ShareClassFeeScheduleId;
83
+ subscriptions: ActionId[];
84
+ outstanding?: number;
85
+ }
86
+ /**
87
+ * Type definition for external valuation on the remote portfolio valuation
88
+ * report.
89
+ */
90
+ export interface RemoteValuationExternalValue {
91
+ id: ExternalValuationId;
92
+ created: SDateTime;
93
+ creator: PrincipalId;
94
+ updated: SDateTime;
95
+ updater: PrincipalId;
96
+ guid: string;
97
+ portfolio: PortfolioId;
98
+ shareclass?: ShareClassId;
99
+ date: SDate;
100
+ ccy: CurrencyCode;
101
+ shares?: number;
102
+ price?: number;
103
+ nav?: number;
104
+ aum?: number;
105
+ hedgepnl?: number;
106
+ feemngt?: number;
107
+ feeperf?: number;
108
+ otheraccrued?: number;
109
+ totalaccrued?: number;
110
+ subred?: number;
111
+ perfdaily?: number;
112
+ perfweekly?: number;
113
+ perfmonthly?: number;
114
+ perfytd?: number;
115
+ perfstart?: number;
116
+ coefficient?: number;
117
+ }
118
+ /**
119
+ * Attempts to retrieve remote portfolio valuation report.
120
+ *
121
+ * @param client DECAF Barista client.
122
+ * @param query Remote portfolio valuation report endpoint query parameters.
123
+ * @returns Remote (raw) portfolio valuation report data.
124
+ */
125
+ export declare function fetchRemotePortfolioValuationReport(client: DecafClient, query: PortfolioValuationReportQuery): Promise<Either<CustomError, RemotePortfolioValuationReport>>;
126
+ /**
127
+ * Attempts to recompile remote valuation report share class value.
128
+ *
129
+ * @param x remote valuation report share class value object.
130
+ * @return Recompiled valuation report share class value object.
131
+ */
132
+ export declare function toShareClassValue(x: RemoteValuationShareClassValue): PortfolioValuationReportShareClassValue;
133
+ /**
134
+ * Attempts to re-compile the raw, remote portfolio valuation report and
135
+ * return it.
136
+ *
137
+ * @param x Raw, remote portfolio valuation report.
138
+ * @returns Either of an error message or the re-compiled portfolio valuation
139
+ * report.
140
+ */
141
+ export declare function recompilePortfolioValuationReport(x: RemotePortfolioValuationReport): Either<CustomError, PortfolioValuationReport>;
142
+ /**
143
+ * Attempts to retrieve remote portfolio valuation report, compiles it to
144
+ * [[PortfolioValuationReport]] and return it.
145
+ *
146
+ * @param client DECAF Barista client.
147
+ * @param query Remote portolio valuation report endpoint query parameters.
148
+ * @returns Recompiled portolio valuation report data.
149
+ */
150
+ export declare function fetchPortfolioValuationReport(client: DecafClient, query: PortfolioValuationReportQuery): Promise<Either<CustomError, PortfolioValuationReport>>;
@@ -0,0 +1,134 @@
1
+ import { asDecimal, customError, Left, Maybe, maybeDecimal, Right, sanitizedNonEmptyText, zero, } from '@telostat/prelude';
2
+ import { recompileBaseValuationReport } from './-remote-valuation-report-shared';
3
+ /**
4
+ * Attempts to retrieve remote portfolio valuation report.
5
+ *
6
+ * @param client DECAF Barista client.
7
+ * @param query Remote portfolio valuation report endpoint query parameters.
8
+ * @returns Remote (raw) portfolio valuation report data.
9
+ */
10
+ export function fetchRemotePortfolioValuationReport(client, query) {
11
+ return client.barista
12
+ .get('/portfolioreport/', {
13
+ params: {
14
+ ccy: query.currency,
15
+ date: query.date,
16
+ type: query.dateType,
17
+ portfolio: `${query.portfolio}`,
18
+ },
19
+ })
20
+ .then((x) => Right(x.data))
21
+ .catch((err) => Left(customError('Error while attempting to fetch remote portfolio valuation report', err)));
22
+ }
23
+ /**
24
+ * Attempts to recompile remote valuation report share class value.
25
+ *
26
+ * @param x remote valuation report share class value object.
27
+ * @return Recompiled valuation report share class value object.
28
+ */
29
+ export function toShareClassValue(x) {
30
+ return {
31
+ shareclass: {
32
+ id: x.shareclass.id,
33
+ created: x.shareclass.created,
34
+ creator: Maybe.fromNullable(x.shareclass.creator),
35
+ updated: x.shareclass.updated,
36
+ updater: Maybe.fromNullable(x.shareclass.updater),
37
+ guid: x.shareclass.guid,
38
+ portfolio: x.shareclass.portfolio,
39
+ name: x.shareclass.name,
40
+ currency: x.shareclass.currency,
41
+ isin: sanitizedNonEmptyText(x.shareclass.isin),
42
+ bbgticker: sanitizedNonEmptyText(x.shareclass.bbgticker),
43
+ liquidity: sanitizedNonEmptyText(x.shareclass.liquidity),
44
+ jurisdiction: sanitizedNonEmptyText(x.shareclass.jurisdiction),
45
+ administrator: sanitizedNonEmptyText(x.shareclass.administrator),
46
+ minimumInvestment: sanitizedNonEmptyText(x.shareclass.mininvestment),
47
+ subscriptionRedemptionPeriod: sanitizedNonEmptyText(x.shareclass.subredperiod),
48
+ managementFeeFrequency: Maybe.fromNullable(x.shareclass.freqmngt),
49
+ performanceFeeFrequency: Maybe.fromNullable(x.shareclass.freqperf),
50
+ benchmark: Maybe.fromNullable(x.shareclass.benchmark),
51
+ description: sanitizedNonEmptyText(x.shareclass.description),
52
+ feeScheduleIds: x.shareclass.feeschedules,
53
+ effectiveFeeScheduleId: Maybe.fromNullable(x.shareclass.effectivefeeschedule),
54
+ subscriptionIds: x.shareclass.subscriptions,
55
+ outstanding: maybeDecimal(x.shareclass.outstanding),
56
+ },
57
+ external: Maybe.fromNullable(x.external).map((ev) => ({
58
+ id: ev.id,
59
+ created: ev.created,
60
+ creator: Maybe.fromNullable(ev.updater),
61
+ updated: ev.updated,
62
+ updater: Maybe.fromNullable(ev.updater),
63
+ guid: ev.guid,
64
+ portfolio: ev.portfolio,
65
+ shareclass: Maybe.fromNullable(ev.shareclass),
66
+ date: ev.date,
67
+ ccy: ev.ccy,
68
+ shares: maybeDecimal(ev.shares),
69
+ price: maybeDecimal(ev.price),
70
+ nav: maybeDecimal(ev.nav),
71
+ aum: maybeDecimal(ev.aum),
72
+ hedgepnl: maybeDecimal(ev.hedgepnl),
73
+ feemngt: maybeDecimal(ev.feemngt),
74
+ feeperf: maybeDecimal(ev.feeperf),
75
+ otheraccrued: maybeDecimal(ev.otheraccrued),
76
+ totalaccrued: maybeDecimal(ev.totalaccrued),
77
+ subred: maybeDecimal(ev.subred),
78
+ perfdaily: maybeDecimal(ev.perfdaily),
79
+ perfweekly: maybeDecimal(ev.perfweekly),
80
+ perfmonthly: maybeDecimal(ev.perfmonthly),
81
+ perfytd: maybeDecimal(ev.perfytd),
82
+ perfstart: maybeDecimal(ev.perfstart),
83
+ coefficient: maybeDecimal(ev.coefficient),
84
+ })),
85
+ nav: asDecimal(x.nav),
86
+ navAdjusted: asDecimal(x.nav_adjusted),
87
+ navAdjustedTotal: asDecimal(x.nav_adjusted_total),
88
+ coefficient: asDecimal(x.coefficient),
89
+ gavRefccy: asDecimal(x.gav_refccy),
90
+ gavClsccy: asDecimal(x.gav_clsccy),
91
+ sharecountPrev: asDecimal(x.sharecount_prev),
92
+ sharecountCurr: asDecimal(x.sharecount_curr),
93
+ sharecountDiff: asDecimal(x.sharecount_diff),
94
+ pxRefCcy: asDecimal(x.px_refccy),
95
+ pxClsCcy: asDecimal(x.px_clsccy),
96
+ ytdExt: maybeDecimal(x.ytdext),
97
+ ytdInt: maybeDecimal(x.ytdint),
98
+ };
99
+ }
100
+ /**
101
+ * Attempts to re-compile the raw, remote portfolio valuation report and
102
+ * return it.
103
+ *
104
+ * @param x Raw, remote portfolio valuation report.
105
+ * @returns Either of an error message or the re-compiled portfolio valuation
106
+ * report.
107
+ */
108
+ export function recompilePortfolioValuationReport(x) {
109
+ // Attempt to get the base valuation report:
110
+ const baseReport = recompileBaseValuationReport(x);
111
+ // Add consolidated valuation report specific fields and return:
112
+ return baseReport.map((report) => {
113
+ return {
114
+ ...report,
115
+ portfolio: x.portfolio,
116
+ subscriptions: maybeDecimal(x.subscriptions).orDefault(zero),
117
+ shareClassValues: x.scvals.map(toShareClassValue),
118
+ };
119
+ });
120
+ }
121
+ /**
122
+ * Attempts to retrieve remote portfolio valuation report, compiles it to
123
+ * [[PortfolioValuationReport]] and return it.
124
+ *
125
+ * @param client DECAF Barista client.
126
+ * @param query Remote portolio valuation report endpoint query parameters.
127
+ * @returns Recompiled portolio valuation report data.
128
+ */
129
+ export async function fetchPortfolioValuationReport(client, query) {
130
+ // Attempt to fetch the remote, raw report:
131
+ const rawReport = await fetchRemotePortfolioValuationReport(client, query);
132
+ // Attempt to recompile the report (if any) and return:
133
+ return rawReport.chain(recompilePortfolioValuationReport);
134
+ }
@@ -0,0 +1,233 @@
1
+ import { CustomError, Decimal, Either, Maybe, SDate, SDateTime } from '@telostat/prelude';
2
+ import { ArtifactId, ArtifactTypeId, CurrencyCode, DateType } from '../../commons';
3
+ import { BaseValuationReport, BaseValuationReportHolding, ValuationReportAccount, ValuationReportAccounts, ValuationReportAccrual, ValuationReportArtifact, ValuationReportFigureOrgRef, ValuationReportHolding } from './-valuation-report-shared';
4
+ export interface RemoteBaseValuationReport {
5
+ reported: SDateTime;
6
+ asof: SDate;
7
+ type: DateType;
8
+ ccy: CurrencyCode;
9
+ accounts: ValuationReportAccounts;
10
+ holdings: RemoteValuationReportHolding[];
11
+ accruals: RemoteValuationReportAccrual[];
12
+ investment?: number;
13
+ valuation_net?: number;
14
+ valuation_abs?: number;
15
+ accrued?: number;
16
+ liabilities?: number;
17
+ gav?: number;
18
+ nav?: number;
19
+ aum?: number;
20
+ pnl?: number;
21
+ pnl_to_investment?: number;
22
+ fxrates: RemoteValuationReportFxRate[];
23
+ }
24
+ export interface RemoteValuationReportFxRate {
25
+ ccy1: CurrencyCode;
26
+ ccy2: CurrencyCode;
27
+ value: number;
28
+ asof: SDate;
29
+ }
30
+ /**
31
+ * Valuation holding.
32
+ */
33
+ export interface RemoteValuationReportHolding {
34
+ artifact: RemoteValuationReportArtifact;
35
+ tags: {
36
+ classification: {
37
+ name: string;
38
+ order?: string | number;
39
+ }[];
40
+ };
41
+ quantity: number;
42
+ accounts: ValuationReportAccount[];
43
+ investment: {
44
+ px: {
45
+ org?: number;
46
+ ref?: number;
47
+ };
48
+ txncosts: {
49
+ org?: number;
50
+ ref?: number;
51
+ };
52
+ accrued: {
53
+ org?: number;
54
+ ref?: number;
55
+ };
56
+ value: {
57
+ org?: number;
58
+ ref?: number;
59
+ };
60
+ };
61
+ valuation: {
62
+ px: {
63
+ org?: number;
64
+ ref?: number;
65
+ };
66
+ accrued: {
67
+ org?: number;
68
+ ref?: number;
69
+ };
70
+ value: {
71
+ net: {
72
+ org?: number;
73
+ ref?: number;
74
+ };
75
+ abs: {
76
+ org?: number;
77
+ ref?: number;
78
+ };
79
+ };
80
+ exposure: {
81
+ net: {
82
+ org?: number;
83
+ ref?: number;
84
+ };
85
+ abs: {
86
+ org?: number;
87
+ ref?: number;
88
+ };
89
+ };
90
+ };
91
+ children: RemoteValuationReportChildHolding[];
92
+ change?: number;
93
+ pnl?: number;
94
+ pnl_to_investment?: number;
95
+ opendate: SDate;
96
+ lastdate: SDate;
97
+ }
98
+ /**
99
+ * Valuation child holding.
100
+ */
101
+ export interface RemoteValuationReportChildHolding {
102
+ artifact: RemoteValuationReportArtifact;
103
+ tags: {};
104
+ quantity: number;
105
+ accounts: ValuationReportAccount[];
106
+ investment: {
107
+ px: {
108
+ org?: number;
109
+ ref?: number;
110
+ };
111
+ txncosts: {
112
+ org?: number;
113
+ ref?: number;
114
+ };
115
+ accrued: {
116
+ org?: number;
117
+ ref?: number;
118
+ };
119
+ value: {
120
+ org?: number;
121
+ ref?: number;
122
+ };
123
+ };
124
+ valuation: {
125
+ px: {
126
+ org?: number;
127
+ ref?: number;
128
+ };
129
+ accrued: {
130
+ org?: number;
131
+ ref?: number;
132
+ };
133
+ value: {
134
+ net: {
135
+ org?: number;
136
+ ref?: number;
137
+ };
138
+ abs: {
139
+ org?: number;
140
+ ref?: number;
141
+ };
142
+ };
143
+ exposure: {
144
+ net: {
145
+ org?: number;
146
+ ref?: number;
147
+ };
148
+ abs: {
149
+ org?: number;
150
+ ref?: number;
151
+ };
152
+ };
153
+ };
154
+ change?: number;
155
+ pnl?: number;
156
+ pnl_to_investment?: number;
157
+ opendate: SDate;
158
+ lastdate: SDate;
159
+ }
160
+ /**
161
+ * Valuation artifact.
162
+ */
163
+ export interface RemoteValuationReportArtifact {
164
+ id: ArtifactId;
165
+ guid: string;
166
+ type: {
167
+ id: ArtifactTypeId;
168
+ name: string;
169
+ order: number;
170
+ };
171
+ stype?: string;
172
+ symbol: string;
173
+ name?: string;
174
+ ccy?: CurrencyCode;
175
+ quantity: number;
176
+ country?: string;
177
+ issuer?: string;
178
+ sector?: string;
179
+ mic?: string;
180
+ ticker?: string;
181
+ isin?: string;
182
+ figi?: string;
183
+ expiry?: SDate;
184
+ underlying_id?: ArtifactId;
185
+ }
186
+ /**
187
+ * Valuation accrual.
188
+ */
189
+ export interface RemoteValuationReportAccrual {
190
+ name: string;
191
+ value: number;
192
+ accounts: RemoteValuationReportAccrualByAccount[];
193
+ }
194
+ /**
195
+ * Valuation accrual by account.
196
+ */
197
+ export interface RemoteValuationReportAccrualByAccount {
198
+ account: ValuationReportAccount;
199
+ value: number;
200
+ accruals: RemoteValuationReportAccrualByCurrency[];
201
+ }
202
+ /**
203
+ * Valuation accrual by account by currency.
204
+ */
205
+ export interface RemoteValuationReportAccrualByCurrency {
206
+ artifact: RemoteValuationReportArtifact;
207
+ ccy: CurrencyCode;
208
+ value: {
209
+ org?: number;
210
+ ref?: number;
211
+ };
212
+ }
213
+ export declare function toArtifact(x: RemoteValuationReportArtifact): ValuationReportArtifact;
214
+ export declare function toAccrual(x: RemoteValuationReportAccrual): ValuationReportAccrual;
215
+ export declare function toOrgRef(x: {
216
+ org?: number;
217
+ ref?: number;
218
+ }): ValuationReportFigureOrgRef;
219
+ export declare function toMaybeOrgRef(x?: {
220
+ org?: number;
221
+ ref?: number;
222
+ }): Maybe<ValuationReportFigureOrgRef>;
223
+ export declare function toBaseHolding(nav: Decimal, x: RemoteValuationReportHolding | RemoteValuationReportChildHolding): BaseValuationReportHolding;
224
+ export declare function toHolding(nav: Decimal, x: RemoteValuationReportHolding): ValuationReportHolding;
225
+ /**
226
+ * Attempts to re-compile the raw, remote base valuation report and
227
+ * return it.
228
+ *
229
+ * @param x Raw, remote base valuation report.
230
+ * @returns Either of an error message or the re-compiled base valuation
231
+ * report.
232
+ */
233
+ export declare function recompileBaseValuationReport(x: RemoteBaseValuationReport): Either<CustomError, BaseValuationReport>;
@@ -0,0 +1,127 @@
1
+ import { asDecimal, Just, Maybe, maybeDecimal, Right, safeDiv, sanitizedNonEmptyText, zero, } from '@telostat/prelude';
2
+ export function toArtifact(x) {
3
+ return {
4
+ id: x.id,
5
+ guid: x.guid,
6
+ type: x.type,
7
+ stype: sanitizedNonEmptyText(x.stype),
8
+ symbol: x.symbol,
9
+ name: sanitizedNonEmptyText(x.name),
10
+ ccy: Maybe.fromNullable(x.ccy),
11
+ quantity: asDecimal(x.quantity),
12
+ country: sanitizedNonEmptyText(x.country),
13
+ issuer: sanitizedNonEmptyText(x.issuer),
14
+ sector: sanitizedNonEmptyText(x.sector),
15
+ mic: sanitizedNonEmptyText(x.mic),
16
+ ticker: sanitizedNonEmptyText(x.ticker),
17
+ isin: sanitizedNonEmptyText(x.isin),
18
+ figi: sanitizedNonEmptyText(x.figi),
19
+ expiry: Maybe.fromNullable(x.expiry),
20
+ underlyingId: Maybe.fromNullable(x.underlying_id),
21
+ };
22
+ }
23
+ export function toAccrual(x) {
24
+ return {
25
+ name: x.name,
26
+ value: asDecimal(x.value),
27
+ accounts: x.accounts.map((y) => ({
28
+ account: y.account,
29
+ value: asDecimal(y.value),
30
+ accruals: y.accruals.map((z) => ({
31
+ artifact: toArtifact(z.artifact),
32
+ ccy: z.ccy,
33
+ value: { org: asDecimal(z.value.org || 0), ref: asDecimal(z.value.ref || 0) },
34
+ })),
35
+ })),
36
+ };
37
+ }
38
+ export function toOrgRef(x) {
39
+ return {
40
+ org: maybeDecimal(x.org).orDefault(zero),
41
+ ref: maybeDecimal(x.ref).orDefault(zero),
42
+ };
43
+ }
44
+ export function toMaybeOrgRef(x) {
45
+ return Maybe.fromNullable(x).chain(({ org, ref }) => maybeDecimal(org).chain((o) => maybeDecimal(ref).chain((r) => Just({ org: o, ref: r }))));
46
+ }
47
+ export function toBaseHolding(nav, x) {
48
+ return {
49
+ artifact: toArtifact(x.artifact),
50
+ quantity: asDecimal(x.quantity),
51
+ investment: {
52
+ px: toOrgRef(x.investment.px),
53
+ txncosts: toMaybeOrgRef(x.investment.txncosts),
54
+ accrued: toMaybeOrgRef(x.investment.accrued),
55
+ value: toOrgRef(x.investment.value),
56
+ },
57
+ valuation: {
58
+ px: toOrgRef(x.valuation.px),
59
+ accrued: toMaybeOrgRef(x.valuation.accrued),
60
+ value: {
61
+ net: toOrgRef(x.valuation.value.net),
62
+ abs: toOrgRef(x.valuation.value.abs),
63
+ },
64
+ exposure: {
65
+ net: toOrgRef(x.valuation.exposure.net),
66
+ abs: toOrgRef(x.valuation.exposure.abs),
67
+ },
68
+ },
69
+ valuePercentage: safeDiv(maybeDecimal(x.valuation.value.net.ref).orDefault(zero), nav),
70
+ netExposurePercentage: safeDiv(maybeDecimal(x.valuation.exposure.net.ref).orDefault(zero), nav),
71
+ absExposurePercentage: safeDiv(maybeDecimal(x.valuation.exposure.abs.ref).orDefault(zero), nav),
72
+ change: maybeDecimal(x.change),
73
+ pnl: maybeDecimal(x.pnl).orDefault(zero),
74
+ pnlToInvestment: maybeDecimal(x.pnl_to_investment),
75
+ opendate: x.opendate,
76
+ lastdate: x.lastdate,
77
+ };
78
+ }
79
+ export function toHolding(nav, x) {
80
+ return {
81
+ ...toBaseHolding(nav, x),
82
+ classification: x.tags.classification.map((n) => ({ ...n, order: n.order || '' })),
83
+ accounts: x.accounts,
84
+ children: Maybe.fromNullable(x.children)
85
+ .filter((mc) => mc.length !== 0)
86
+ .map((mc) => mc.map((c) => ({
87
+ ...toBaseHolding(nav, c),
88
+ account: c.accounts[0],
89
+ }))),
90
+ };
91
+ }
92
+ /**
93
+ * Attempts to re-compile the raw, remote base valuation report and
94
+ * return it.
95
+ *
96
+ * @param x Raw, remote base valuation report.
97
+ * @returns Either of an error message or the re-compiled base valuation
98
+ * report.
99
+ */
100
+ export function recompileBaseValuationReport(x) {
101
+ const nav = maybeDecimal(x.nav).orDefault(zero);
102
+ const report = {
103
+ asof: x.reported,
104
+ date: x.asof,
105
+ dateType: x.type,
106
+ currency: x.ccy,
107
+ accounts: x.accounts,
108
+ holdings: x.holdings.map((rh) => toHolding(nav, rh)),
109
+ accruals: x.accruals.map(toAccrual),
110
+ fxRates: x.fxrates.map((r) => ({ ccy1: r.ccy1, ccy2: r.ccy2, value: asDecimal(r.value), asof: r.asof })),
111
+ figures: {
112
+ investment: maybeDecimal(x.investment).orDefault(zero),
113
+ valuation: {
114
+ net: maybeDecimal(x.valuation_net).orDefault(zero),
115
+ abs: maybeDecimal(x.valuation_abs).orDefault(zero),
116
+ },
117
+ accrued: maybeDecimal(x.accrued).orDefault(zero),
118
+ liabilities: maybeDecimal(x.liabilities).orDefault(zero),
119
+ gav: maybeDecimal(x.gav).orDefault(zero),
120
+ nav,
121
+ aum: maybeDecimal(x.aum).orDefault(zero),
122
+ pnl: maybeDecimal(x.pnl).orDefault(zero),
123
+ pnlToInvestment: maybeDecimal(x.pnl_to_investment),
124
+ },
125
+ };
126
+ return Right(report);
127
+ }