@barchart/portfolio-api-common 1.0.89 → 1.0.93
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.
|
@@ -37,12 +37,11 @@ module.exports = (() => {
|
|
|
37
37
|
* start and end dates.
|
|
38
38
|
*
|
|
39
39
|
* @public
|
|
40
|
-
* @
|
|
41
|
-
* @param {Day} endDate
|
|
40
|
+
* @return {PositionSummaryRange} range
|
|
42
41
|
* @return {String}
|
|
43
42
|
*/
|
|
44
|
-
describeRange(
|
|
45
|
-
return this._descriptionCalculator(
|
|
43
|
+
describeRange(range) {
|
|
44
|
+
return this._descriptionCalculator(range.start, range.end);
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
/**
|
|
@@ -226,20 +225,20 @@ module.exports = (() => {
|
|
|
226
225
|
return null;
|
|
227
226
|
}
|
|
228
227
|
|
|
229
|
-
function getYearlyRangeDescription(
|
|
230
|
-
return
|
|
228
|
+
function getYearlyRangeDescription(start, end) {
|
|
229
|
+
return end.year.toString();
|
|
231
230
|
}
|
|
232
231
|
|
|
233
|
-
function getQuarterlyRangeDescription(
|
|
232
|
+
function getQuarterlyRangeDescription(start, end) {
|
|
234
233
|
return '';
|
|
235
234
|
}
|
|
236
235
|
|
|
237
|
-
function getMonthlyRangeDescription(
|
|
236
|
+
function getMonthlyRangeDescription(start, end) {
|
|
238
237
|
return '';
|
|
239
238
|
}
|
|
240
239
|
|
|
241
|
-
function getYearToDateRangeDescription(
|
|
242
|
-
return `${
|
|
240
|
+
function getYearToDateRangeDescription(start, end) {
|
|
241
|
+
return `${end.year.toString()} YTD`;
|
|
243
242
|
}
|
|
244
243
|
|
|
245
244
|
function getFilteredTransactions(transactions) {
|
|
@@ -18,12 +18,18 @@ module.exports = (() => {
|
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
20
|
class PositionContainer {
|
|
21
|
-
constructor(portfolios, positions, summaries, definitions, defaultCurrency,
|
|
21
|
+
constructor(portfolios, positions, summaries, definitions, defaultCurrency, summaryFrame) {
|
|
22
22
|
this._definitions = definitions;
|
|
23
23
|
this._defaultCurrency = defaultCurrency || Currency.CAD;
|
|
24
|
+
|
|
25
|
+
const previousSummaryFrame = summaryFrame || PositionSummaryFrame.YEARLY;
|
|
26
|
+
const previousSummaryRanges = previousSummaryFrame.getRecentRanges(0);
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
const currentSummaryFrame = PositionSummaryFrame.YTD;
|
|
29
|
+
const currentSummaryRange = array.last(currentSummaryFrame.getRecentRanges(0));
|
|
30
|
+
|
|
31
|
+
this._summaryDescriptionCurrent = previousSummaryFrame.describeRange(array.last(previousSummaryRanges));
|
|
32
|
+
this._summaryDescriptionPrevious = currentSummaryFrame.describeRange(currentSummaryRange);
|
|
27
33
|
|
|
28
34
|
this._portfolios = portfolios.reduce((map, portfolio) => {
|
|
29
35
|
map[portfolio.portfolio] = portfolio;
|
|
@@ -31,15 +37,25 @@ module.exports = (() => {
|
|
|
31
37
|
return map;
|
|
32
38
|
}, { });
|
|
33
39
|
|
|
34
|
-
this.
|
|
35
|
-
if (
|
|
40
|
+
this._summariesCurrent = summaries.reduce((map, summary) => {
|
|
41
|
+
if (summary.frame === currentSummaryFrame && currentSummaryRange.start.getIsEqual(summary.start.date) && currentSummaryRange.end.getIsEqual(summary.end.date)) {
|
|
42
|
+
const key = summary.position;
|
|
43
|
+
|
|
44
|
+
map[key] = summary;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return map;
|
|
48
|
+
}, { });
|
|
49
|
+
|
|
50
|
+
this._summariesPrevious = summaries.reduce((map, summary) => {
|
|
51
|
+
if (summary.frame === previousSummaryFrame) {
|
|
36
52
|
const key = summary.position;
|
|
37
53
|
|
|
38
54
|
if (!map.hasOwnProperty(key)) {
|
|
39
|
-
map[key] = getSummaryArray(
|
|
55
|
+
map[key] = getSummaryArray(previousSummaryRanges);
|
|
40
56
|
}
|
|
41
57
|
|
|
42
|
-
const index =
|
|
58
|
+
const index = previousSummaryRanges.findIndex(r => r.start.getIsEqual(summary.start.date) && r.end.getIsEqual(summary.end.date));
|
|
43
59
|
|
|
44
60
|
if (!(index < 0)) {
|
|
45
61
|
map[key][index] = summary;
|
|
@@ -53,9 +69,10 @@ module.exports = (() => {
|
|
|
53
69
|
const portfolio = this._portfolios[position.portfolio];
|
|
54
70
|
|
|
55
71
|
if (position) {
|
|
56
|
-
const
|
|
72
|
+
const currentSummary = this._summariesCurrent[position.position] || null;
|
|
73
|
+
const previousSummaries = this._summariesPrevious[position.position] || getSummaryArray(previousSummaryRanges);
|
|
57
74
|
|
|
58
|
-
items.push(new PositionItem(portfolio, position,
|
|
75
|
+
items.push(new PositionItem(portfolio, position, currentSummary, previousSummaries));
|
|
59
76
|
}
|
|
60
77
|
|
|
61
78
|
return items;
|
|
@@ -167,7 +184,25 @@ module.exports = (() => {
|
|
|
167
184
|
get defaultCurrency() {
|
|
168
185
|
return this._defaultCurrency;
|
|
169
186
|
}
|
|
187
|
+
|
|
188
|
+
getCurrentSummaryDescription() {
|
|
189
|
+
return this._summaryDescriptionCurrent;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
getPreviousSummaryDescription() {
|
|
193
|
+
return this._summaryDescriptionPrevious;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
startTransaction(executor) {
|
|
197
|
+
assert.argumentIsRequired(executor, 'executor', Function);
|
|
198
|
+
|
|
199
|
+
this._tree.walk(group => group.setSuspended(true), false, false);
|
|
170
200
|
|
|
201
|
+
executor(this);
|
|
202
|
+
|
|
203
|
+
this._tree.walk(group => group.setSuspended(false), false, false);
|
|
204
|
+
}
|
|
205
|
+
|
|
171
206
|
getSymbols() {
|
|
172
207
|
return Object.keys(this._symbols);
|
|
173
208
|
}
|
|
@@ -194,16 +229,6 @@ module.exports = (() => {
|
|
|
194
229
|
|
|
195
230
|
}
|
|
196
231
|
|
|
197
|
-
startTransaction(executor) {
|
|
198
|
-
assert.argumentIsRequired(executor, 'executor', Function);
|
|
199
|
-
|
|
200
|
-
this._tree.walk(group => group.setSuspended(true), false, false);
|
|
201
|
-
|
|
202
|
-
executor(this);
|
|
203
|
-
|
|
204
|
-
this._tree.walk(group => group.setSuspended(false), false, false);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
232
|
getGroup(keys) {
|
|
208
233
|
const node = keys.reduce((tree, key) => {
|
|
209
234
|
tree = tree.findChild(group => group.description === key);
|
|
@@ -42,8 +42,8 @@ module.exports = (() => {
|
|
|
42
42
|
this._dataActual.marketPercent = null;
|
|
43
43
|
this._dataActual.unrealizedToday = null;
|
|
44
44
|
this._dataActual.total = null;
|
|
45
|
-
this._dataActual.
|
|
46
|
-
this._dataActual.
|
|
45
|
+
this._dataActual.summaryTotalCurrent = null;
|
|
46
|
+
this._dataActual.summaryTotalPrevious = null;
|
|
47
47
|
|
|
48
48
|
this._dataFormat.currentPrice = null;
|
|
49
49
|
this._dataFormat.previousPrice = null;
|
|
@@ -57,8 +57,9 @@ module.exports = (() => {
|
|
|
57
57
|
this._dataFormat.unrealizedTodayNegative = false;
|
|
58
58
|
this._dataFormat.total = null;
|
|
59
59
|
this._dataFormat.totalNegative = false;
|
|
60
|
-
this._dataFormat.
|
|
61
|
-
this.
|
|
60
|
+
this._dataFormat.summaryTotalCurrent = null;
|
|
61
|
+
this._dataActual.summaryTotalCurrentNegative = false;
|
|
62
|
+
this._dataFormat.summaryTotalPrevious = null;
|
|
62
63
|
|
|
63
64
|
this._dataFormat.unrealizedTodayNegative = false;
|
|
64
65
|
|
|
@@ -187,29 +188,29 @@ module.exports = (() => {
|
|
|
187
188
|
updates.basis = updates.basis.add(item.data.basis);
|
|
188
189
|
updates.realized = updates.realized.add(item.data.realized);
|
|
189
190
|
updates.income = updates.income.add(item.data.income);
|
|
190
|
-
updates.
|
|
191
|
-
updates.
|
|
191
|
+
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(item.data.summaryTotalCurrent);
|
|
192
|
+
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(item.data.summaryTotalPrevious);
|
|
192
193
|
|
|
193
194
|
return updates;
|
|
194
195
|
}, {
|
|
195
196
|
basis: Decimal.ZERO,
|
|
196
197
|
realized: Decimal.ZERO,
|
|
197
198
|
income: Decimal.ZERO,
|
|
198
|
-
|
|
199
|
-
|
|
199
|
+
summaryTotalCurrent: Decimal.ZERO,
|
|
200
|
+
summaryTotalPrevious: Decimal.ZERO
|
|
200
201
|
});
|
|
201
202
|
|
|
202
203
|
actual.basis = updates.basis;
|
|
203
204
|
actual.realized = updates.realized;
|
|
204
205
|
actual.income = updates.income;
|
|
205
|
-
actual.
|
|
206
|
-
actual.
|
|
206
|
+
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
207
|
+
actual.summaryTotalPrevious = updates.summaryTotalPrevious;
|
|
207
208
|
|
|
208
209
|
format.basis = formatCurrency(actual.basis, currency);
|
|
209
210
|
format.realized = formatCurrency(actual.basis, currency);
|
|
210
211
|
format.income = formatCurrency(actual.income, currency);
|
|
211
|
-
format.
|
|
212
|
-
format.
|
|
212
|
+
format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
|
|
213
|
+
format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
function calculatePriceData(group, item, forceRefresh) {
|
|
@@ -234,19 +235,22 @@ module.exports = (() => {
|
|
|
234
235
|
updates = items.reduce((updates, item) => {
|
|
235
236
|
updates.market = updates.market.add(item.data.market);
|
|
236
237
|
updates.unrealizedToday = updates.unrealizedToday.add(item.data.unrealizedToday);
|
|
238
|
+
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(item.data.summaryTotalCurrent);
|
|
237
239
|
|
|
238
240
|
return updates;
|
|
239
241
|
}, {
|
|
240
242
|
market: Decimal.ZERO,
|
|
241
243
|
marketDirection: unchanged,
|
|
242
|
-
unrealizedToday: Decimal.ZERO
|
|
244
|
+
unrealizedToday: Decimal.ZERO,
|
|
245
|
+
summaryTotalCurrent: Decimal.ZERO
|
|
243
246
|
|
|
244
247
|
});
|
|
245
248
|
} else {
|
|
246
249
|
updates = {
|
|
247
250
|
market: actual.market.add(item.data.marketChange),
|
|
248
251
|
marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
|
|
249
|
-
unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange)
|
|
252
|
+
unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange),
|
|
253
|
+
summaryTotalCurrent: actual.summaryTotalCurrent.add(item.data.summaryTotalCurrentChange)
|
|
250
254
|
};
|
|
251
255
|
}
|
|
252
256
|
|
|
@@ -264,6 +268,7 @@ module.exports = (() => {
|
|
|
264
268
|
|
|
265
269
|
actual.market = updates.market;
|
|
266
270
|
actual.unrealizedToday = updates.unrealizedToday;
|
|
271
|
+
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
267
272
|
actual.total = updates.unrealizedToday.add(actual.realized).add(actual.income);
|
|
268
273
|
|
|
269
274
|
format.market = formatCurrency(actual.market, currency);
|
|
@@ -275,6 +280,10 @@ module.exports = (() => {
|
|
|
275
280
|
|
|
276
281
|
format.unrealizedToday = formatCurrency(actual.unrealizedToday, currency);
|
|
277
282
|
format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
|
|
283
|
+
|
|
284
|
+
format.summaryTotalCurrent = formatCurrency(actual.summaryTotalCurrent, currency);
|
|
285
|
+
format.summaryTotalCurrentNegative = actual.summaryTotalCurrent.getIsNegative();
|
|
286
|
+
|
|
278
287
|
format.total = formatCurrency(actual.total, currency);
|
|
279
288
|
format.totalNegative = actual.total.getIsNegative();
|
|
280
289
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const array = require('@barchart/common-js/lang/array'),
|
|
2
|
+
assert = require('@barchart/common-js/lang/assert'),
|
|
2
3
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
3
4
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
4
5
|
is = require('@barchart/common-js/lang/is');
|
|
@@ -12,10 +13,12 @@ module.exports = (() => {
|
|
|
12
13
|
* @public
|
|
13
14
|
*/
|
|
14
15
|
class PositionItem {
|
|
15
|
-
constructor(portfolio, position,
|
|
16
|
+
constructor(portfolio, position, currentSummary, previousSummaries) {
|
|
16
17
|
this._portfolio = portfolio;
|
|
17
18
|
this._position = position;
|
|
18
|
-
|
|
19
|
+
|
|
20
|
+
this._currentSummary = currentSummary || null;
|
|
21
|
+
this._previousSummaries = previousSummaries || [ ];
|
|
19
22
|
|
|
20
23
|
this._data = { };
|
|
21
24
|
|
|
@@ -32,6 +35,11 @@ module.exports = (() => {
|
|
|
32
35
|
|
|
33
36
|
this._data.realized = null;
|
|
34
37
|
this._data.income = null;
|
|
38
|
+
|
|
39
|
+
this._data.summaryTotalCurrent = null;
|
|
40
|
+
this._data.summaryTotalCurrentChange = null;
|
|
41
|
+
|
|
42
|
+
this._data.summaryTotalPrevious = null;
|
|
35
43
|
|
|
36
44
|
this._excluded = false;
|
|
37
45
|
|
|
@@ -50,8 +58,12 @@ module.exports = (() => {
|
|
|
50
58
|
return this._position;
|
|
51
59
|
}
|
|
52
60
|
|
|
53
|
-
get
|
|
54
|
-
return this.
|
|
61
|
+
get currentSummary() {
|
|
62
|
+
return this._currentSummary;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get previousSummaries() {
|
|
66
|
+
return this._previousSummaries;
|
|
55
67
|
}
|
|
56
68
|
|
|
57
69
|
get data() {
|
|
@@ -96,7 +108,7 @@ module.exports = (() => {
|
|
|
96
108
|
function calculateStaticData(item) {
|
|
97
109
|
const position = item.position;
|
|
98
110
|
const snapshot = item.position.snapshot;
|
|
99
|
-
const
|
|
111
|
+
const previousSummaries = item.previousSummaries;
|
|
100
112
|
|
|
101
113
|
const data = item._data;
|
|
102
114
|
|
|
@@ -115,22 +127,8 @@ module.exports = (() => {
|
|
|
115
127
|
data.realized = snapshot.gain;
|
|
116
128
|
data.income = snapshot.income;
|
|
117
129
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (summaries.length > index && summaries[index] !== null) {
|
|
122
|
-
const period = summaries[index].period;
|
|
123
|
-
|
|
124
|
-
summaryTotal = period.realized.add(period.unrealized).add(period.income);
|
|
125
|
-
} else {
|
|
126
|
-
summaryTotal = Decimal.ZERO;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return summaryTotal;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
data.summaryOneTotal = getSummaryTotal(0);
|
|
133
|
-
data.summaryTwoTotal = getSummaryTotal(1);
|
|
130
|
+
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary);
|
|
131
|
+
data.summaryTotalPrevious = calculateSummaryTotal(array.last(previousSummaries));
|
|
134
132
|
}
|
|
135
133
|
|
|
136
134
|
function calculatePriceData(item, price) {
|
|
@@ -182,6 +180,42 @@ module.exports = (() => {
|
|
|
182
180
|
|
|
183
181
|
data.unrealizedToday = unrealizedToday;
|
|
184
182
|
data.unrealizedTodayChange = unrealizedTodayChange;
|
|
183
|
+
|
|
184
|
+
const summary = item.currentSummary;
|
|
185
|
+
|
|
186
|
+
if (summary && price) {
|
|
187
|
+
const period = summary.period;
|
|
188
|
+
|
|
189
|
+
let unrealizedCurrent = summary.open.multiply(price).add(summary.end.basis);
|
|
190
|
+
|
|
191
|
+
let summaryTotalCurrent = period.realized.add(period.income).add(unrealizedCurrent);
|
|
192
|
+
let summaryTotalCurrentChange;
|
|
193
|
+
|
|
194
|
+
if (data.summaryTotalCurrent !== null) {
|
|
195
|
+
summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
|
|
196
|
+
} else {
|
|
197
|
+
summaryTotalCurrentChange = Decimal.ZERO;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
data.summaryTotalCurrent = summaryTotalCurrent;
|
|
201
|
+
data.summaryTotalCurrentChange = summaryTotalCurrentChange;
|
|
202
|
+
} else {
|
|
203
|
+
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function calculateSummaryTotal(summary) {
|
|
208
|
+
let returnRef;
|
|
209
|
+
|
|
210
|
+
if (summary) {
|
|
211
|
+
const period = summary.period;
|
|
212
|
+
|
|
213
|
+
returnRef = period.realized.add(period.income).add(period.unrealized);
|
|
214
|
+
} else {
|
|
215
|
+
returnRef = Decimal.ZERO;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return returnRef;
|
|
185
219
|
}
|
|
186
220
|
|
|
187
221
|
return PositionItem;
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -156,12 +156,11 @@ module.exports = (() => {
|
|
|
156
156
|
* start and end dates.
|
|
157
157
|
*
|
|
158
158
|
* @public
|
|
159
|
-
* @
|
|
160
|
-
* @param {Day} endDate
|
|
159
|
+
* @return {PositionSummaryRange} range
|
|
161
160
|
* @return {String}
|
|
162
161
|
*/
|
|
163
|
-
describeRange(
|
|
164
|
-
return this._descriptionCalculator(
|
|
162
|
+
describeRange(range) {
|
|
163
|
+
return this._descriptionCalculator(range.start, range.end);
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
/**
|
|
@@ -345,20 +344,20 @@ module.exports = (() => {
|
|
|
345
344
|
return null;
|
|
346
345
|
}
|
|
347
346
|
|
|
348
|
-
function getYearlyRangeDescription(
|
|
349
|
-
return
|
|
347
|
+
function getYearlyRangeDescription(start, end) {
|
|
348
|
+
return end.year.toString();
|
|
350
349
|
}
|
|
351
350
|
|
|
352
|
-
function getQuarterlyRangeDescription(
|
|
351
|
+
function getQuarterlyRangeDescription(start, end) {
|
|
353
352
|
return '';
|
|
354
353
|
}
|
|
355
354
|
|
|
356
|
-
function getMonthlyRangeDescription(
|
|
355
|
+
function getMonthlyRangeDescription(start, end) {
|
|
357
356
|
return '';
|
|
358
357
|
}
|
|
359
358
|
|
|
360
|
-
function getYearToDateRangeDescription(
|
|
361
|
-
return `${
|
|
359
|
+
function getYearToDateRangeDescription(start, end) {
|
|
360
|
+
return `${end.year.toString()} YTD`;
|
|
362
361
|
}
|
|
363
362
|
|
|
364
363
|
function getFilteredTransactions(transactions) {
|
|
@@ -735,12 +734,18 @@ module.exports = (() => {
|
|
|
735
734
|
* @public
|
|
736
735
|
*/
|
|
737
736
|
class PositionContainer {
|
|
738
|
-
constructor(portfolios, positions, summaries, definitions, defaultCurrency,
|
|
737
|
+
constructor(portfolios, positions, summaries, definitions, defaultCurrency, summaryFrame) {
|
|
739
738
|
this._definitions = definitions;
|
|
740
739
|
this._defaultCurrency = defaultCurrency || Currency.CAD;
|
|
740
|
+
|
|
741
|
+
const previousSummaryFrame = summaryFrame || PositionSummaryFrame.YEARLY;
|
|
742
|
+
const previousSummaryRanges = previousSummaryFrame.getRecentRanges(0);
|
|
743
|
+
|
|
744
|
+
const currentSummaryFrame = PositionSummaryFrame.YTD;
|
|
745
|
+
const currentSummaryRange = array.last(currentSummaryFrame.getRecentRanges(0));
|
|
741
746
|
|
|
742
|
-
this.
|
|
743
|
-
this.
|
|
747
|
+
this._summaryDescriptionCurrent = previousSummaryFrame.describeRange(array.last(previousSummaryRanges));
|
|
748
|
+
this._summaryDescriptionPrevious = currentSummaryFrame.describeRange(currentSummaryRange);
|
|
744
749
|
|
|
745
750
|
this._portfolios = portfolios.reduce((map, portfolio) => {
|
|
746
751
|
map[portfolio.portfolio] = portfolio;
|
|
@@ -748,15 +753,25 @@ module.exports = (() => {
|
|
|
748
753
|
return map;
|
|
749
754
|
}, { });
|
|
750
755
|
|
|
751
|
-
this.
|
|
752
|
-
if (
|
|
756
|
+
this._summariesCurrent = summaries.reduce((map, summary) => {
|
|
757
|
+
if (summary.frame === currentSummaryFrame && currentSummaryRange.start.getIsEqual(summary.start.date) && currentSummaryRange.end.getIsEqual(summary.end.date)) {
|
|
758
|
+
const key = summary.position;
|
|
759
|
+
|
|
760
|
+
map[key] = summary;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
return map;
|
|
764
|
+
}, { });
|
|
765
|
+
|
|
766
|
+
this._summariesPrevious = summaries.reduce((map, summary) => {
|
|
767
|
+
if (summary.frame === previousSummaryFrame) {
|
|
753
768
|
const key = summary.position;
|
|
754
769
|
|
|
755
770
|
if (!map.hasOwnProperty(key)) {
|
|
756
|
-
map[key] = getSummaryArray(
|
|
771
|
+
map[key] = getSummaryArray(previousSummaryRanges);
|
|
757
772
|
}
|
|
758
773
|
|
|
759
|
-
const index =
|
|
774
|
+
const index = previousSummaryRanges.findIndex(r => r.start.getIsEqual(summary.start.date) && r.end.getIsEqual(summary.end.date));
|
|
760
775
|
|
|
761
776
|
if (!(index < 0)) {
|
|
762
777
|
map[key][index] = summary;
|
|
@@ -770,9 +785,10 @@ module.exports = (() => {
|
|
|
770
785
|
const portfolio = this._portfolios[position.portfolio];
|
|
771
786
|
|
|
772
787
|
if (position) {
|
|
773
|
-
const
|
|
788
|
+
const currentSummary = this._summariesCurrent[position.position] || null;
|
|
789
|
+
const previousSummaries = this._summariesPrevious[position.position] || getSummaryArray(previousSummaryRanges);
|
|
774
790
|
|
|
775
|
-
items.push(new PositionItem(portfolio, position,
|
|
791
|
+
items.push(new PositionItem(portfolio, position, currentSummary, previousSummaries));
|
|
776
792
|
}
|
|
777
793
|
|
|
778
794
|
return items;
|
|
@@ -884,7 +900,25 @@ module.exports = (() => {
|
|
|
884
900
|
get defaultCurrency() {
|
|
885
901
|
return this._defaultCurrency;
|
|
886
902
|
}
|
|
903
|
+
|
|
904
|
+
getCurrentSummaryDescription() {
|
|
905
|
+
return this._summaryDescriptionCurrent;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
getPreviousSummaryDescription() {
|
|
909
|
+
return this._summaryDescriptionPrevious;
|
|
910
|
+
}
|
|
887
911
|
|
|
912
|
+
startTransaction(executor) {
|
|
913
|
+
assert.argumentIsRequired(executor, 'executor', Function);
|
|
914
|
+
|
|
915
|
+
this._tree.walk(group => group.setSuspended(true), false, false);
|
|
916
|
+
|
|
917
|
+
executor(this);
|
|
918
|
+
|
|
919
|
+
this._tree.walk(group => group.setSuspended(false), false, false);
|
|
920
|
+
}
|
|
921
|
+
|
|
888
922
|
getSymbols() {
|
|
889
923
|
return Object.keys(this._symbols);
|
|
890
924
|
}
|
|
@@ -911,16 +945,6 @@ module.exports = (() => {
|
|
|
911
945
|
|
|
912
946
|
}
|
|
913
947
|
|
|
914
|
-
startTransaction(executor) {
|
|
915
|
-
assert.argumentIsRequired(executor, 'executor', Function);
|
|
916
|
-
|
|
917
|
-
this._tree.walk(group => group.setSuspended(true), false, false);
|
|
918
|
-
|
|
919
|
-
executor(this);
|
|
920
|
-
|
|
921
|
-
this._tree.walk(group => group.setSuspended(false), false, false);
|
|
922
|
-
}
|
|
923
|
-
|
|
924
948
|
getGroup(keys) {
|
|
925
949
|
const node = keys.reduce((tree, key) => {
|
|
926
950
|
tree = tree.findChild(group => group.description === key);
|
|
@@ -998,8 +1022,8 @@ module.exports = (() => {
|
|
|
998
1022
|
this._dataActual.marketPercent = null;
|
|
999
1023
|
this._dataActual.unrealizedToday = null;
|
|
1000
1024
|
this._dataActual.total = null;
|
|
1001
|
-
this._dataActual.
|
|
1002
|
-
this._dataActual.
|
|
1025
|
+
this._dataActual.summaryTotalCurrent = null;
|
|
1026
|
+
this._dataActual.summaryTotalPrevious = null;
|
|
1003
1027
|
|
|
1004
1028
|
this._dataFormat.currentPrice = null;
|
|
1005
1029
|
this._dataFormat.previousPrice = null;
|
|
@@ -1013,8 +1037,9 @@ module.exports = (() => {
|
|
|
1013
1037
|
this._dataFormat.unrealizedTodayNegative = false;
|
|
1014
1038
|
this._dataFormat.total = null;
|
|
1015
1039
|
this._dataFormat.totalNegative = false;
|
|
1016
|
-
this._dataFormat.
|
|
1017
|
-
this.
|
|
1040
|
+
this._dataFormat.summaryTotalCurrent = null;
|
|
1041
|
+
this._dataActual.summaryTotalCurrentNegative = false;
|
|
1042
|
+
this._dataFormat.summaryTotalPrevious = null;
|
|
1018
1043
|
|
|
1019
1044
|
this._dataFormat.unrealizedTodayNegative = false;
|
|
1020
1045
|
|
|
@@ -1143,29 +1168,29 @@ module.exports = (() => {
|
|
|
1143
1168
|
updates.basis = updates.basis.add(item.data.basis);
|
|
1144
1169
|
updates.realized = updates.realized.add(item.data.realized);
|
|
1145
1170
|
updates.income = updates.income.add(item.data.income);
|
|
1146
|
-
updates.
|
|
1147
|
-
updates.
|
|
1171
|
+
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(item.data.summaryTotalCurrent);
|
|
1172
|
+
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(item.data.summaryTotalPrevious);
|
|
1148
1173
|
|
|
1149
1174
|
return updates;
|
|
1150
1175
|
}, {
|
|
1151
1176
|
basis: Decimal.ZERO,
|
|
1152
1177
|
realized: Decimal.ZERO,
|
|
1153
1178
|
income: Decimal.ZERO,
|
|
1154
|
-
|
|
1155
|
-
|
|
1179
|
+
summaryTotalCurrent: Decimal.ZERO,
|
|
1180
|
+
summaryTotalPrevious: Decimal.ZERO
|
|
1156
1181
|
});
|
|
1157
1182
|
|
|
1158
1183
|
actual.basis = updates.basis;
|
|
1159
1184
|
actual.realized = updates.realized;
|
|
1160
1185
|
actual.income = updates.income;
|
|
1161
|
-
actual.
|
|
1162
|
-
actual.
|
|
1186
|
+
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
1187
|
+
actual.summaryTotalPrevious = updates.summaryTotalPrevious;
|
|
1163
1188
|
|
|
1164
1189
|
format.basis = formatCurrency(actual.basis, currency);
|
|
1165
1190
|
format.realized = formatCurrency(actual.basis, currency);
|
|
1166
1191
|
format.income = formatCurrency(actual.income, currency);
|
|
1167
|
-
format.
|
|
1168
|
-
format.
|
|
1192
|
+
format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
|
|
1193
|
+
format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
|
|
1169
1194
|
}
|
|
1170
1195
|
|
|
1171
1196
|
function calculatePriceData(group, item, forceRefresh) {
|
|
@@ -1190,19 +1215,22 @@ module.exports = (() => {
|
|
|
1190
1215
|
updates = items.reduce((updates, item) => {
|
|
1191
1216
|
updates.market = updates.market.add(item.data.market);
|
|
1192
1217
|
updates.unrealizedToday = updates.unrealizedToday.add(item.data.unrealizedToday);
|
|
1218
|
+
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(item.data.summaryTotalCurrent);
|
|
1193
1219
|
|
|
1194
1220
|
return updates;
|
|
1195
1221
|
}, {
|
|
1196
1222
|
market: Decimal.ZERO,
|
|
1197
1223
|
marketDirection: unchanged,
|
|
1198
|
-
unrealizedToday: Decimal.ZERO
|
|
1224
|
+
unrealizedToday: Decimal.ZERO,
|
|
1225
|
+
summaryTotalCurrent: Decimal.ZERO
|
|
1199
1226
|
|
|
1200
1227
|
});
|
|
1201
1228
|
} else {
|
|
1202
1229
|
updates = {
|
|
1203
1230
|
market: actual.market.add(item.data.marketChange),
|
|
1204
1231
|
marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
|
|
1205
|
-
unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange)
|
|
1232
|
+
unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange),
|
|
1233
|
+
summaryTotalCurrent: actual.summaryTotalCurrent.add(item.data.summaryTotalCurrentChange)
|
|
1206
1234
|
};
|
|
1207
1235
|
}
|
|
1208
1236
|
|
|
@@ -1220,6 +1248,7 @@ module.exports = (() => {
|
|
|
1220
1248
|
|
|
1221
1249
|
actual.market = updates.market;
|
|
1222
1250
|
actual.unrealizedToday = updates.unrealizedToday;
|
|
1251
|
+
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
1223
1252
|
actual.total = updates.unrealizedToday.add(actual.realized).add(actual.income);
|
|
1224
1253
|
|
|
1225
1254
|
format.market = formatCurrency(actual.market, currency);
|
|
@@ -1231,6 +1260,10 @@ module.exports = (() => {
|
|
|
1231
1260
|
|
|
1232
1261
|
format.unrealizedToday = formatCurrency(actual.unrealizedToday, currency);
|
|
1233
1262
|
format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
|
|
1263
|
+
|
|
1264
|
+
format.summaryTotalCurrent = formatCurrency(actual.summaryTotalCurrent, currency);
|
|
1265
|
+
format.summaryTotalCurrentNegative = actual.summaryTotalCurrent.getIsNegative();
|
|
1266
|
+
|
|
1234
1267
|
format.total = formatCurrency(actual.total, currency);
|
|
1235
1268
|
format.totalNegative = actual.total.getIsNegative();
|
|
1236
1269
|
|
|
@@ -1326,7 +1359,8 @@ module.exports = (() => {
|
|
|
1326
1359
|
})();
|
|
1327
1360
|
|
|
1328
1361
|
},{"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19}],7:[function(require,module,exports){
|
|
1329
|
-
const
|
|
1362
|
+
const array = require('@barchart/common-js/lang/array'),
|
|
1363
|
+
assert = require('@barchart/common-js/lang/assert'),
|
|
1330
1364
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
1331
1365
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
1332
1366
|
is = require('@barchart/common-js/lang/is');
|
|
@@ -1340,10 +1374,12 @@ module.exports = (() => {
|
|
|
1340
1374
|
* @public
|
|
1341
1375
|
*/
|
|
1342
1376
|
class PositionItem {
|
|
1343
|
-
constructor(portfolio, position,
|
|
1377
|
+
constructor(portfolio, position, currentSummary, previousSummaries) {
|
|
1344
1378
|
this._portfolio = portfolio;
|
|
1345
1379
|
this._position = position;
|
|
1346
|
-
|
|
1380
|
+
|
|
1381
|
+
this._currentSummary = currentSummary || null;
|
|
1382
|
+
this._previousSummaries = previousSummaries || [ ];
|
|
1347
1383
|
|
|
1348
1384
|
this._data = { };
|
|
1349
1385
|
|
|
@@ -1360,6 +1396,11 @@ module.exports = (() => {
|
|
|
1360
1396
|
|
|
1361
1397
|
this._data.realized = null;
|
|
1362
1398
|
this._data.income = null;
|
|
1399
|
+
|
|
1400
|
+
this._data.summaryTotalCurrent = null;
|
|
1401
|
+
this._data.summaryTotalCurrentChange = null;
|
|
1402
|
+
|
|
1403
|
+
this._data.summaryTotalPrevious = null;
|
|
1363
1404
|
|
|
1364
1405
|
this._excluded = false;
|
|
1365
1406
|
|
|
@@ -1378,8 +1419,12 @@ module.exports = (() => {
|
|
|
1378
1419
|
return this._position;
|
|
1379
1420
|
}
|
|
1380
1421
|
|
|
1381
|
-
get
|
|
1382
|
-
return this.
|
|
1422
|
+
get currentSummary() {
|
|
1423
|
+
return this._currentSummary;
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
get previousSummaries() {
|
|
1427
|
+
return this._previousSummaries;
|
|
1383
1428
|
}
|
|
1384
1429
|
|
|
1385
1430
|
get data() {
|
|
@@ -1424,7 +1469,7 @@ module.exports = (() => {
|
|
|
1424
1469
|
function calculateStaticData(item) {
|
|
1425
1470
|
const position = item.position;
|
|
1426
1471
|
const snapshot = item.position.snapshot;
|
|
1427
|
-
const
|
|
1472
|
+
const previousSummaries = item.previousSummaries;
|
|
1428
1473
|
|
|
1429
1474
|
const data = item._data;
|
|
1430
1475
|
|
|
@@ -1443,22 +1488,8 @@ module.exports = (() => {
|
|
|
1443
1488
|
data.realized = snapshot.gain;
|
|
1444
1489
|
data.income = snapshot.income;
|
|
1445
1490
|
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
if (summaries.length > index && summaries[index] !== null) {
|
|
1450
|
-
const period = summaries[index].period;
|
|
1451
|
-
|
|
1452
|
-
summaryTotal = period.realized.add(period.unrealized).add(period.income);
|
|
1453
|
-
} else {
|
|
1454
|
-
summaryTotal = Decimal.ZERO;
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
return summaryTotal;
|
|
1458
|
-
};
|
|
1459
|
-
|
|
1460
|
-
data.summaryOneTotal = getSummaryTotal(0);
|
|
1461
|
-
data.summaryTwoTotal = getSummaryTotal(1);
|
|
1491
|
+
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary);
|
|
1492
|
+
data.summaryTotalPrevious = calculateSummaryTotal(array.last(previousSummaries));
|
|
1462
1493
|
}
|
|
1463
1494
|
|
|
1464
1495
|
function calculatePriceData(item, price) {
|
|
@@ -1510,12 +1541,48 @@ module.exports = (() => {
|
|
|
1510
1541
|
|
|
1511
1542
|
data.unrealizedToday = unrealizedToday;
|
|
1512
1543
|
data.unrealizedTodayChange = unrealizedTodayChange;
|
|
1544
|
+
|
|
1545
|
+
const summary = item.currentSummary;
|
|
1546
|
+
|
|
1547
|
+
if (summary && price) {
|
|
1548
|
+
const period = summary.period;
|
|
1549
|
+
|
|
1550
|
+
let unrealizedCurrent = summary.open.multiply(price).add(summary.end.basis);
|
|
1551
|
+
|
|
1552
|
+
let summaryTotalCurrent = period.realized.add(period.income).add(unrealizedCurrent);
|
|
1553
|
+
let summaryTotalCurrentChange;
|
|
1554
|
+
|
|
1555
|
+
if (data.summaryTotalCurrent !== null) {
|
|
1556
|
+
summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
|
|
1557
|
+
} else {
|
|
1558
|
+
summaryTotalCurrentChange = Decimal.ZERO;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
data.summaryTotalCurrent = summaryTotalCurrent;
|
|
1562
|
+
data.summaryTotalCurrentChange = summaryTotalCurrentChange;
|
|
1563
|
+
} else {
|
|
1564
|
+
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
function calculateSummaryTotal(summary) {
|
|
1569
|
+
let returnRef;
|
|
1570
|
+
|
|
1571
|
+
if (summary) {
|
|
1572
|
+
const period = summary.period;
|
|
1573
|
+
|
|
1574
|
+
returnRef = period.realized.add(period.income).add(period.unrealized);
|
|
1575
|
+
} else {
|
|
1576
|
+
returnRef = Decimal.ZERO;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
return returnRef;
|
|
1513
1580
|
}
|
|
1514
1581
|
|
|
1515
1582
|
return PositionItem;
|
|
1516
1583
|
})();
|
|
1517
1584
|
|
|
1518
|
-
},{"./../data/InstrumentType":1,"@barchart/common-js/lang/Decimal":13,"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19,"@barchart/common-js/messaging/Event":20}],8:[function(require,module,exports){
|
|
1585
|
+
},{"./../data/InstrumentType":1,"@barchart/common-js/lang/Decimal":13,"@barchart/common-js/lang/array":16,"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19,"@barchart/common-js/messaging/Event":20}],8:[function(require,module,exports){
|
|
1519
1586
|
'use strict';
|
|
1520
1587
|
|
|
1521
1588
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
@@ -3155,9 +3222,9 @@ module.exports = function () {
|
|
|
3155
3222
|
assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
|
|
3156
3223
|
assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
|
|
3157
3224
|
|
|
3158
|
-
if (a._big.gt(b)) {
|
|
3225
|
+
if (a._big.gt(b._big)) {
|
|
3159
3226
|
return 1;
|
|
3160
|
-
} else if (a._big.lt(b)) {
|
|
3227
|
+
} else if (a._big.lt(b._big)) {
|
|
3161
3228
|
return -1;
|
|
3162
3229
|
} else {
|
|
3163
3230
|
return 0;
|