@barchart/portfolio-api-common 1.2.58 → 1.2.62
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.
- package/lib/data/InstrumentType.js +19 -6
- package/lib/data/PositionSummaryFrame.js +1 -2
- package/lib/data/ValuationType.js +1 -2
- package/lib/formatters/PositionSummaryFormatter.js +0 -1
- package/lib/processing/PositionContainer.js +0 -1
- package/lib/processing/PositionItem.js +17 -15
- package/lib/serialization/PortfolioSchema.js +1 -3
- package/lib/serialization/PositionSchema.js +1 -3
- package/lib/serialization/PositionSummarySchema.js +1 -18
- package/package.json +1 -1
- package/test/SpecRunner.js +113 -52
|
@@ -19,11 +19,12 @@ module.exports = (() => {
|
|
|
19
19
|
* @param {Boolean} canSwitchDirection
|
|
20
20
|
* @param {Boolean} usesSymbols
|
|
21
21
|
* @param {Boolean} hasCorporateActions
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {Boolean} closeFractional
|
|
23
|
+
* @param {Boolean} roundQuantity
|
|
23
24
|
* @param {Function} generator
|
|
24
25
|
*/
|
|
25
26
|
class InstrumentType extends Enum {
|
|
26
|
-
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, generator) {
|
|
27
|
+
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, roundQuantity, generator) {
|
|
27
28
|
super(code, description);
|
|
28
29
|
|
|
29
30
|
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
@@ -33,6 +34,7 @@ module.exports = (() => {
|
|
|
33
34
|
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
34
35
|
assert.argumentIsRequired(hasCorporateActions, 'hasCorporateActions', Boolean);
|
|
35
36
|
assert.argumentIsRequired(closeFractional, 'closeFractional', Boolean);
|
|
37
|
+
assert.argumentIsRequired(roundQuantity, 'roundQuantity', Boolean);
|
|
36
38
|
assert.argumentIsRequired(generator, 'generator', Function);
|
|
37
39
|
|
|
38
40
|
this._alternateDescription = alternateDescription;
|
|
@@ -42,6 +44,7 @@ module.exports = (() => {
|
|
|
42
44
|
this._usesSymbols = usesSymbols;
|
|
43
45
|
this._hasCorporateActions = hasCorporateActions;
|
|
44
46
|
this._closeFractional = closeFractional;
|
|
47
|
+
this._roundQuantity = roundQuantity;
|
|
45
48
|
|
|
46
49
|
this._generator = generator;
|
|
47
50
|
}
|
|
@@ -118,6 +121,16 @@ module.exports = (() => {
|
|
|
118
121
|
return this._closeFractional;
|
|
119
122
|
}
|
|
120
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Indicates transaction quantities should be rounded.
|
|
126
|
+
*
|
|
127
|
+
* @public
|
|
128
|
+
* @returns {Boolean}
|
|
129
|
+
*/
|
|
130
|
+
get roundQuantity() {
|
|
131
|
+
return this._roundQuantity;
|
|
132
|
+
}
|
|
133
|
+
|
|
121
134
|
/**
|
|
122
135
|
* Generates an identifier for the instrument.
|
|
123
136
|
*
|
|
@@ -215,10 +228,10 @@ module.exports = (() => {
|
|
|
215
228
|
}
|
|
216
229
|
}
|
|
217
230
|
|
|
218
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
219
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
220
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
221
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
231
|
+
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
232
|
+
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
233
|
+
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
234
|
+
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, true, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
222
235
|
|
|
223
236
|
const map = { };
|
|
224
237
|
|
|
@@ -2,8 +2,7 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
2
2
|
assert = require('@barchart/common-js/lang/assert'),
|
|
3
3
|
Day = require('@barchart/common-js/lang/Day'),
|
|
4
4
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
5
|
-
Enum = require('@barchart/common-js/lang/Enum')
|
|
6
|
-
is = require('@barchart/common-js/lang/is');
|
|
5
|
+
Enum = require('@barchart/common-js/lang/Enum');
|
|
7
6
|
|
|
8
7
|
module.exports = (() => {
|
|
9
8
|
'use strict';
|
|
@@ -6,7 +6,6 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
6
6
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
7
7
|
DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
|
|
8
8
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
9
|
-
is = require('@barchart/common-js/lang/is'),
|
|
10
9
|
Rate = require('@barchart/common-js/lang/Rate'),
|
|
11
10
|
Tree = require('@barchart/common-js/collections/Tree');
|
|
12
11
|
|
|
@@ -311,7 +311,6 @@ module.exports = (() => {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
function calculateStaticData(item) {
|
|
314
|
-
const portfolio = item.portfolio;
|
|
315
314
|
const position = item.position;
|
|
316
315
|
const snapshot = item.position.snapshot;
|
|
317
316
|
const previousSummaries = item.previousSummaries;
|
|
@@ -335,9 +334,9 @@ module.exports = (() => {
|
|
|
335
334
|
|
|
336
335
|
data.income = snapshot.income;
|
|
337
336
|
|
|
338
|
-
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary);
|
|
339
|
-
data.summaryTotalPrevious = calculateSummaryTotal(getPreviousSummary(previousSummaries, 1));
|
|
340
|
-
data.summaryTotalPrevious2 = calculateSummaryTotal(getPreviousSummary(previousSummaries, 2));
|
|
337
|
+
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary, getPreviousSummary(previousSummaries, 1));
|
|
338
|
+
data.summaryTotalPrevious = calculateSummaryTotal(getPreviousSummary(previousSummaries, 1), getPreviousSummary(previousSummaries, 2));
|
|
339
|
+
data.summaryTotalPrevious2 = calculateSummaryTotal(getPreviousSummary(previousSummaries, 2), getPreviousSummary(previousSummaries, 3));
|
|
341
340
|
|
|
342
341
|
if (snapshot.open.getIsZero()) {
|
|
343
342
|
data.basisPrice = Decimal.ZERO;
|
|
@@ -349,6 +348,7 @@ module.exports = (() => {
|
|
|
349
348
|
function calculatePriceData(item, price) {
|
|
350
349
|
const position = item.position;
|
|
351
350
|
const snapshot = item.position.snapshot;
|
|
351
|
+
const previousSummaries = item.previousSummaries;
|
|
352
352
|
|
|
353
353
|
const data = item._data;
|
|
354
354
|
|
|
@@ -408,25 +408,27 @@ module.exports = (() => {
|
|
|
408
408
|
data.unrealizedToday = unrealizedToday;
|
|
409
409
|
data.unrealizedTodayChange = unrealizedTodayChange;
|
|
410
410
|
|
|
411
|
-
const
|
|
411
|
+
const currentSummary = item.currentSummary;
|
|
412
|
+
|
|
413
|
+
if (currentSummary && position.instrument.type !== InstrumentType.CASH) {
|
|
414
|
+
const previousSummary = getPreviousSummary(previousSummaries, 1);
|
|
412
415
|
|
|
413
|
-
if (summary && position.instrument.type !== InstrumentType.CASH) {
|
|
414
416
|
let priceToUse;
|
|
415
417
|
|
|
416
418
|
if (price) {
|
|
417
419
|
priceToUse = price;
|
|
418
420
|
} else if (data.previousPrice) {
|
|
419
421
|
priceToUse = new Decimal(data.previousPrice);
|
|
420
|
-
} else if (!
|
|
421
|
-
priceToUse =
|
|
422
|
+
} else if (!currentSummary.end.open.getIsZero()) {
|
|
423
|
+
priceToUse = currentSummary.end.value.divide(currentSummary.end.open);
|
|
422
424
|
} else {
|
|
423
425
|
priceToUse = null;
|
|
424
426
|
}
|
|
425
427
|
|
|
426
428
|
if (priceToUse !== null) {
|
|
427
|
-
const period =
|
|
429
|
+
const period = currentSummary.period;
|
|
428
430
|
|
|
429
|
-
let unrealized =
|
|
431
|
+
let unrealized = currentSummary.end.open.multiply(priceToUse).add(currentSummary.end.basis);
|
|
430
432
|
let unrealizedChange;
|
|
431
433
|
|
|
432
434
|
if (data.unrealized !== null) {
|
|
@@ -435,7 +437,7 @@ module.exports = (() => {
|
|
|
435
437
|
unrealizedChange = Decimal.ZERO;
|
|
436
438
|
}
|
|
437
439
|
|
|
438
|
-
let summaryTotalCurrent = period.realized.add(period.income).add(unrealized);
|
|
440
|
+
let summaryTotalCurrent = period.realized.add(period.income).add(unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
|
|
439
441
|
let summaryTotalCurrentChange;
|
|
440
442
|
|
|
441
443
|
if (data.summaryTotalCurrent !== null) {
|
|
@@ -463,13 +465,13 @@ module.exports = (() => {
|
|
|
463
465
|
}
|
|
464
466
|
}
|
|
465
467
|
|
|
466
|
-
function calculateSummaryTotal(
|
|
468
|
+
function calculateSummaryTotal(currentSummary, previousSummary) {
|
|
467
469
|
let returnRef;
|
|
468
470
|
|
|
469
|
-
if (
|
|
470
|
-
const period =
|
|
471
|
+
if (currentSummary) {
|
|
472
|
+
const period = currentSummary.period;
|
|
471
473
|
|
|
472
|
-
returnRef = period.realized.add(period.income).add(period.unrealized);
|
|
474
|
+
returnRef = period.realized.add(period.income).add(period.unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
|
|
473
475
|
} else {
|
|
474
476
|
returnRef = Decimal.ZERO;
|
|
475
477
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
Currency = require('@barchart/common-js/lang/Currency'),
|
|
1
|
+
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
3
2
|
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
4
3
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
5
|
-
is = require('@barchart/common-js/lang/is'),
|
|
6
4
|
Schema = require('@barchart/common-js/serialization/json/Schema'),
|
|
7
5
|
SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder'),
|
|
8
6
|
Timezones = require('@barchart/common-js/lang/Timezones');
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
Currency = require('@barchart/common-js/lang/Currency'),
|
|
1
|
+
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
3
2
|
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
4
3
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
5
|
-
is = require('@barchart/common-js/lang/is'),
|
|
6
4
|
Schema = require('@barchart/common-js/serialization/json/Schema'),
|
|
7
5
|
SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder');
|
|
8
6
|
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
Currency = require('@barchart/common-js/lang/Currency'),
|
|
3
|
-
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
1
|
+
const DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
4
2
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
5
|
-
is = require('@barchart/common-js/lang/is'),
|
|
6
3
|
Schema = require('@barchart/common-js/serialization/json/Schema'),
|
|
7
4
|
SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder');
|
|
8
5
|
|
|
@@ -66,13 +63,6 @@ module.exports = (() => {
|
|
|
66
63
|
.withField('user', DataType.STRING)
|
|
67
64
|
.withField('portfolio', DataType.STRING)
|
|
68
65
|
.withField('position', DataType.STRING)
|
|
69
|
-
.withField('instrument.id', DataType.STRING)
|
|
70
|
-
.withField('instrument.name', DataType.STRING)
|
|
71
|
-
.withField('instrument.type', DataType.STRING)
|
|
72
|
-
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
|
|
73
|
-
.withField('instrument.delist', DataType.DAY, true)
|
|
74
|
-
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
75
|
-
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
76
66
|
.withField('frame', DataType.forEnum(PositionSummaryFrame, 'PositionSummaryFrame'))
|
|
77
67
|
.withField('start.date', DataType.DAY)
|
|
78
68
|
.withField('start.sequence', DataType.NUMBER)
|
|
@@ -100,13 +90,6 @@ module.exports = (() => {
|
|
|
100
90
|
.withField('user', DataType.STRING)
|
|
101
91
|
.withField('portfolio', DataType.STRING)
|
|
102
92
|
.withField('position', DataType.STRING)
|
|
103
|
-
.withField('instrument.id', DataType.STRING)
|
|
104
|
-
.withField('instrument.name', DataType.STRING)
|
|
105
|
-
.withField('instrument.type', DataType.STRING)
|
|
106
|
-
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
|
|
107
|
-
.withField('instrument.delist', DataType.DAY, true)
|
|
108
|
-
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
109
|
-
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
110
93
|
.withField('frame', DataType.forEnum(PositionSummaryFrame, 'PositionSummaryFrame'))
|
|
111
94
|
.withField('start.date', DataType.DAY)
|
|
112
95
|
.withField('start.sequence', DataType.NUMBER)
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -20,11 +20,12 @@ module.exports = (() => {
|
|
|
20
20
|
* @param {Boolean} canSwitchDirection
|
|
21
21
|
* @param {Boolean} usesSymbols
|
|
22
22
|
* @param {Boolean} hasCorporateActions
|
|
23
|
-
* @param {
|
|
23
|
+
* @param {Boolean} closeFractional
|
|
24
|
+
* @param {Boolean} roundQuantity
|
|
24
25
|
* @param {Function} generator
|
|
25
26
|
*/
|
|
26
27
|
class InstrumentType extends Enum {
|
|
27
|
-
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, generator) {
|
|
28
|
+
constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, roundQuantity, generator) {
|
|
28
29
|
super(code, description);
|
|
29
30
|
|
|
30
31
|
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
@@ -34,6 +35,7 @@ module.exports = (() => {
|
|
|
34
35
|
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
35
36
|
assert.argumentIsRequired(hasCorporateActions, 'hasCorporateActions', Boolean);
|
|
36
37
|
assert.argumentIsRequired(closeFractional, 'closeFractional', Boolean);
|
|
38
|
+
assert.argumentIsRequired(roundQuantity, 'roundQuantity', Boolean);
|
|
37
39
|
assert.argumentIsRequired(generator, 'generator', Function);
|
|
38
40
|
|
|
39
41
|
this._alternateDescription = alternateDescription;
|
|
@@ -43,6 +45,7 @@ module.exports = (() => {
|
|
|
43
45
|
this._usesSymbols = usesSymbols;
|
|
44
46
|
this._hasCorporateActions = hasCorporateActions;
|
|
45
47
|
this._closeFractional = closeFractional;
|
|
48
|
+
this._roundQuantity = roundQuantity;
|
|
46
49
|
|
|
47
50
|
this._generator = generator;
|
|
48
51
|
}
|
|
@@ -119,6 +122,16 @@ module.exports = (() => {
|
|
|
119
122
|
return this._closeFractional;
|
|
120
123
|
}
|
|
121
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Indicates transaction quantities should be rounded.
|
|
127
|
+
*
|
|
128
|
+
* @public
|
|
129
|
+
* @returns {Boolean}
|
|
130
|
+
*/
|
|
131
|
+
get roundQuantity() {
|
|
132
|
+
return this._roundQuantity;
|
|
133
|
+
}
|
|
134
|
+
|
|
122
135
|
/**
|
|
123
136
|
* Generates an identifier for the instrument.
|
|
124
137
|
*
|
|
@@ -216,10 +229,10 @@ module.exports = (() => {
|
|
|
216
229
|
}
|
|
217
230
|
}
|
|
218
231
|
|
|
219
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
220
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
221
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
222
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
232
|
+
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
233
|
+
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
234
|
+
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
235
|
+
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, true, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
223
236
|
|
|
224
237
|
const map = { };
|
|
225
238
|
|
|
@@ -366,8 +379,7 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
366
379
|
assert = require('@barchart/common-js/lang/assert'),
|
|
367
380
|
Day = require('@barchart/common-js/lang/Day'),
|
|
368
381
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
369
|
-
Enum = require('@barchart/common-js/lang/Enum')
|
|
370
|
-
is = require('@barchart/common-js/lang/is');
|
|
382
|
+
Enum = require('@barchart/common-js/lang/Enum');
|
|
371
383
|
|
|
372
384
|
module.exports = (() => {
|
|
373
385
|
'use strict';
|
|
@@ -634,7 +646,7 @@ module.exports = (() => {
|
|
|
634
646
|
return PositionSummaryFrame;
|
|
635
647
|
})();
|
|
636
648
|
|
|
637
|
-
},{"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Enum":24,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29
|
|
649
|
+
},{"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Enum":24,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29}],4:[function(require,module,exports){
|
|
638
650
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
639
651
|
Enum = require('@barchart/common-js/lang/Enum');
|
|
640
652
|
|
|
@@ -1340,7 +1352,6 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
1340
1352
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
1341
1353
|
DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
|
|
1342
1354
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
1343
|
-
is = require('@barchart/common-js/lang/is'),
|
|
1344
1355
|
Rate = require('@barchart/common-js/lang/Rate'),
|
|
1345
1356
|
Tree = require('@barchart/common-js/collections/Tree');
|
|
1346
1357
|
|
|
@@ -2274,7 +2285,7 @@ module.exports = (() => {
|
|
|
2274
2285
|
return PositionContainer;
|
|
2275
2286
|
})();
|
|
2276
2287
|
|
|
2277
|
-
},{"./../data/PositionSummaryFrame":3,"./PositionGroup":7,"./PositionItem":8,"./definitions/PositionLevelDefinition":9,"./definitions/PositionLevelType":10,"./definitions/PositionTreeDefinition":11,"@barchart/common-js/collections/Tree":15,"@barchart/common-js/collections/sorting/ComparatorBuilder":16,"@barchart/common-js/collections/sorting/comparators":17,"@barchart/common-js/collections/specialized/DisposableStack":18,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Rate":26,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29,"@barchart/common-js/
|
|
2288
|
+
},{"./../data/PositionSummaryFrame":3,"./PositionGroup":7,"./PositionItem":8,"./definitions/PositionLevelDefinition":9,"./definitions/PositionLevelType":10,"./definitions/PositionTreeDefinition":11,"@barchart/common-js/collections/Tree":15,"@barchart/common-js/collections/sorting/ComparatorBuilder":16,"@barchart/common-js/collections/sorting/comparators":17,"@barchart/common-js/collections/specialized/DisposableStack":18,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Rate":26,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29,"@barchart/common-js/messaging/Event":35}],7:[function(require,module,exports){
|
|
2278
2289
|
const array = require('@barchart/common-js/lang/array'),
|
|
2279
2290
|
assert = require('@barchart/common-js/lang/assert'),
|
|
2280
2291
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
@@ -3448,7 +3459,6 @@ module.exports = (() => {
|
|
|
3448
3459
|
}
|
|
3449
3460
|
|
|
3450
3461
|
function calculateStaticData(item) {
|
|
3451
|
-
const portfolio = item.portfolio;
|
|
3452
3462
|
const position = item.position;
|
|
3453
3463
|
const snapshot = item.position.snapshot;
|
|
3454
3464
|
const previousSummaries = item.previousSummaries;
|
|
@@ -3472,9 +3482,9 @@ module.exports = (() => {
|
|
|
3472
3482
|
|
|
3473
3483
|
data.income = snapshot.income;
|
|
3474
3484
|
|
|
3475
|
-
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary);
|
|
3476
|
-
data.summaryTotalPrevious = calculateSummaryTotal(getPreviousSummary(previousSummaries, 1));
|
|
3477
|
-
data.summaryTotalPrevious2 = calculateSummaryTotal(getPreviousSummary(previousSummaries, 2));
|
|
3485
|
+
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary, getPreviousSummary(previousSummaries, 1));
|
|
3486
|
+
data.summaryTotalPrevious = calculateSummaryTotal(getPreviousSummary(previousSummaries, 1), getPreviousSummary(previousSummaries, 2));
|
|
3487
|
+
data.summaryTotalPrevious2 = calculateSummaryTotal(getPreviousSummary(previousSummaries, 2), getPreviousSummary(previousSummaries, 3));
|
|
3478
3488
|
|
|
3479
3489
|
if (snapshot.open.getIsZero()) {
|
|
3480
3490
|
data.basisPrice = Decimal.ZERO;
|
|
@@ -3486,6 +3496,7 @@ module.exports = (() => {
|
|
|
3486
3496
|
function calculatePriceData(item, price) {
|
|
3487
3497
|
const position = item.position;
|
|
3488
3498
|
const snapshot = item.position.snapshot;
|
|
3499
|
+
const previousSummaries = item.previousSummaries;
|
|
3489
3500
|
|
|
3490
3501
|
const data = item._data;
|
|
3491
3502
|
|
|
@@ -3545,25 +3556,27 @@ module.exports = (() => {
|
|
|
3545
3556
|
data.unrealizedToday = unrealizedToday;
|
|
3546
3557
|
data.unrealizedTodayChange = unrealizedTodayChange;
|
|
3547
3558
|
|
|
3548
|
-
const
|
|
3559
|
+
const currentSummary = item.currentSummary;
|
|
3560
|
+
|
|
3561
|
+
if (currentSummary && position.instrument.type !== InstrumentType.CASH) {
|
|
3562
|
+
const previousSummary = getPreviousSummary(previousSummaries, 1);
|
|
3549
3563
|
|
|
3550
|
-
if (summary && position.instrument.type !== InstrumentType.CASH) {
|
|
3551
3564
|
let priceToUse;
|
|
3552
3565
|
|
|
3553
3566
|
if (price) {
|
|
3554
3567
|
priceToUse = price;
|
|
3555
3568
|
} else if (data.previousPrice) {
|
|
3556
3569
|
priceToUse = new Decimal(data.previousPrice);
|
|
3557
|
-
} else if (!
|
|
3558
|
-
priceToUse =
|
|
3570
|
+
} else if (!currentSummary.end.open.getIsZero()) {
|
|
3571
|
+
priceToUse = currentSummary.end.value.divide(currentSummary.end.open);
|
|
3559
3572
|
} else {
|
|
3560
3573
|
priceToUse = null;
|
|
3561
3574
|
}
|
|
3562
3575
|
|
|
3563
3576
|
if (priceToUse !== null) {
|
|
3564
|
-
const period =
|
|
3577
|
+
const period = currentSummary.period;
|
|
3565
3578
|
|
|
3566
|
-
let unrealized =
|
|
3579
|
+
let unrealized = currentSummary.end.open.multiply(priceToUse).add(currentSummary.end.basis);
|
|
3567
3580
|
let unrealizedChange;
|
|
3568
3581
|
|
|
3569
3582
|
if (data.unrealized !== null) {
|
|
@@ -3572,7 +3585,7 @@ module.exports = (() => {
|
|
|
3572
3585
|
unrealizedChange = Decimal.ZERO;
|
|
3573
3586
|
}
|
|
3574
3587
|
|
|
3575
|
-
let summaryTotalCurrent = period.realized.add(period.income).add(unrealized);
|
|
3588
|
+
let summaryTotalCurrent = period.realized.add(period.income).add(unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
|
|
3576
3589
|
let summaryTotalCurrentChange;
|
|
3577
3590
|
|
|
3578
3591
|
if (data.summaryTotalCurrent !== null) {
|
|
@@ -3600,13 +3613,13 @@ module.exports = (() => {
|
|
|
3600
3613
|
}
|
|
3601
3614
|
}
|
|
3602
3615
|
|
|
3603
|
-
function calculateSummaryTotal(
|
|
3616
|
+
function calculateSummaryTotal(currentSummary, previousSummary) {
|
|
3604
3617
|
let returnRef;
|
|
3605
3618
|
|
|
3606
|
-
if (
|
|
3607
|
-
const period =
|
|
3619
|
+
if (currentSummary) {
|
|
3620
|
+
const period = currentSummary.period;
|
|
3608
3621
|
|
|
3609
|
-
returnRef = period.realized.add(period.income).add(period.unrealized);
|
|
3622
|
+
returnRef = period.realized.add(period.income).add(period.unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
|
|
3610
3623
|
} else {
|
|
3611
3624
|
returnRef = Decimal.ZERO;
|
|
3612
3625
|
}
|
|
@@ -5166,8 +5179,8 @@ module.exports = function () {
|
|
|
5166
5179
|
* Compares two strings (in ascending order), using {@link String#localeCompare}.
|
|
5167
5180
|
*
|
|
5168
5181
|
* @static
|
|
5169
|
-
* @param {
|
|
5170
|
-
* @param {
|
|
5182
|
+
* @param {String} a
|
|
5183
|
+
* @param {String} b
|
|
5171
5184
|
* @returns {Number}
|
|
5172
5185
|
*/
|
|
5173
5186
|
compareStrings: function compareStrings(a, b) {
|
|
@@ -5857,7 +5870,7 @@ module.exports = function () {
|
|
|
5857
5870
|
* @returns {String}
|
|
5858
5871
|
*/
|
|
5859
5872
|
value: function format() {
|
|
5860
|
-
return this._year + '-' + leftPad(this._month) + '-' + leftPad(this._day);
|
|
5873
|
+
return leftPad(this._year, 4, '0') + '-' + leftPad(this._month, 2, '0') + '-' + leftPad(this._day, 2, '0');
|
|
5861
5874
|
}
|
|
5862
5875
|
|
|
5863
5876
|
/**
|
|
@@ -5974,7 +5987,7 @@ module.exports = function () {
|
|
|
5974
5987
|
*
|
|
5975
5988
|
* @static
|
|
5976
5989
|
* @public
|
|
5977
|
-
* @
|
|
5990
|
+
* @returns {Day}
|
|
5978
5991
|
*/
|
|
5979
5992
|
|
|
5980
5993
|
}, {
|
|
@@ -6066,8 +6079,11 @@ module.exports = function () {
|
|
|
6066
6079
|
|
|
6067
6080
|
var dayRegex = /^([0-9]{4}).?([0-9]{2}).?([0-9]{2})$/;
|
|
6068
6081
|
|
|
6069
|
-
function leftPad(value) {
|
|
6070
|
-
|
|
6082
|
+
function leftPad(value, digits, character) {
|
|
6083
|
+
var string = value.toString();
|
|
6084
|
+
var padding = digits - string.length;
|
|
6085
|
+
|
|
6086
|
+
return '' + character.repeat(padding) + string;
|
|
6071
6087
|
}
|
|
6072
6088
|
|
|
6073
6089
|
var comparator = ComparatorBuilder.startWith(function (a, b) {
|
|
@@ -6233,15 +6249,17 @@ module.exports = function () {
|
|
|
6233
6249
|
*
|
|
6234
6250
|
* @public
|
|
6235
6251
|
* @param {Boolean=} approximate
|
|
6252
|
+
* @param {Number=} places
|
|
6236
6253
|
* @returns {Boolean}
|
|
6237
6254
|
*/
|
|
6238
6255
|
|
|
6239
6256
|
}, {
|
|
6240
6257
|
key: 'getIsZero',
|
|
6241
|
-
value: function getIsZero(approximate) {
|
|
6258
|
+
value: function getIsZero(approximate, places) {
|
|
6242
6259
|
assert.argumentIsOptional(approximate, 'approximate', Boolean);
|
|
6260
|
+
assert.argumentIsOptional(places, 'places', Number);
|
|
6243
6261
|
|
|
6244
|
-
return this._big.eq(zero) || is.boolean(approximate) && approximate && this.round(
|
|
6262
|
+
return this._big.eq(zero) || is.boolean(approximate) && approximate && this.round(places || Big.DP, RoundingMode.NORMAL).getIsZero();
|
|
6245
6263
|
}
|
|
6246
6264
|
|
|
6247
6265
|
/**
|
|
@@ -6340,6 +6358,43 @@ module.exports = function () {
|
|
|
6340
6358
|
return this._big.eq(getBig(other));
|
|
6341
6359
|
}
|
|
6342
6360
|
|
|
6361
|
+
/**
|
|
6362
|
+
* Returns true if the current instance is an integer (i.e. has no decimal
|
|
6363
|
+
* component).
|
|
6364
|
+
*
|
|
6365
|
+
* @public
|
|
6366
|
+
* @return {Boolean}
|
|
6367
|
+
*/
|
|
6368
|
+
|
|
6369
|
+
}, {
|
|
6370
|
+
key: 'getIsInteger',
|
|
6371
|
+
value: function getIsInteger() {
|
|
6372
|
+
return this.getIsEqual(this.round(0));
|
|
6373
|
+
}
|
|
6374
|
+
|
|
6375
|
+
/**
|
|
6376
|
+
* Returns the number of decimal places used.
|
|
6377
|
+
*
|
|
6378
|
+
* @public
|
|
6379
|
+
* @returns {Number}
|
|
6380
|
+
*/
|
|
6381
|
+
|
|
6382
|
+
}, {
|
|
6383
|
+
key: 'getDecimalPlaces',
|
|
6384
|
+
value: function getDecimalPlaces() {
|
|
6385
|
+
var matches = this.toFixed().match(/-?\d*\.(\d*)/);
|
|
6386
|
+
|
|
6387
|
+
var returnVal = void 0;
|
|
6388
|
+
|
|
6389
|
+
if (matches === null) {
|
|
6390
|
+
returnVal = 0;
|
|
6391
|
+
} else {
|
|
6392
|
+
returnVal = matches[1].length;
|
|
6393
|
+
}
|
|
6394
|
+
|
|
6395
|
+
return returnVal;
|
|
6396
|
+
}
|
|
6397
|
+
|
|
6343
6398
|
/**
|
|
6344
6399
|
* Emits a floating point value that approximates the value of the current
|
|
6345
6400
|
* instance.
|
|
@@ -6422,7 +6477,7 @@ module.exports = function () {
|
|
|
6422
6477
|
*
|
|
6423
6478
|
* @public
|
|
6424
6479
|
* @param {Decimal} instance
|
|
6425
|
-
* @
|
|
6480
|
+
* @returns {Boolean}
|
|
6426
6481
|
*/
|
|
6427
6482
|
value: function getIsZero(instance) {
|
|
6428
6483
|
assert.argumentIsRequired(instance, 'instance', Decimal, 'Decimal');
|
|
@@ -6435,7 +6490,7 @@ module.exports = function () {
|
|
|
6435
6490
|
*
|
|
6436
6491
|
* @public
|
|
6437
6492
|
* @param {Decimal} instance
|
|
6438
|
-
* @
|
|
6493
|
+
* @returns {Boolean}
|
|
6439
6494
|
*/
|
|
6440
6495
|
|
|
6441
6496
|
}, {
|
|
@@ -6451,7 +6506,7 @@ module.exports = function () {
|
|
|
6451
6506
|
*
|
|
6452
6507
|
* @public
|
|
6453
6508
|
* @param {Decimal} instance
|
|
6454
|
-
* @
|
|
6509
|
+
* @returns {Boolean}
|
|
6455
6510
|
*/
|
|
6456
6511
|
|
|
6457
6512
|
}, {
|
|
@@ -6467,7 +6522,7 @@ module.exports = function () {
|
|
|
6467
6522
|
*
|
|
6468
6523
|
* @public
|
|
6469
6524
|
* @param {Decimal} instance
|
|
6470
|
-
* @
|
|
6525
|
+
* @returns {Boolean}
|
|
6471
6526
|
*/
|
|
6472
6527
|
|
|
6473
6528
|
}, {
|
|
@@ -6483,7 +6538,7 @@ module.exports = function () {
|
|
|
6483
6538
|
*
|
|
6484
6539
|
* @public
|
|
6485
6540
|
* @param {Decimal} instance
|
|
6486
|
-
* @
|
|
6541
|
+
* @returns {Boolean}
|
|
6487
6542
|
*/
|
|
6488
6543
|
|
|
6489
6544
|
}, {
|
|
@@ -6499,7 +6554,7 @@ module.exports = function () {
|
|
|
6499
6554
|
*
|
|
6500
6555
|
* @public
|
|
6501
6556
|
* @param {Decimal} instance
|
|
6502
|
-
* @
|
|
6557
|
+
* @returns {Boolean}
|
|
6503
6558
|
*/
|
|
6504
6559
|
|
|
6505
6560
|
}, {
|
|
@@ -6889,6 +6944,7 @@ module.exports = function () {
|
|
|
6889
6944
|
/**
|
|
6890
6945
|
* The unique code.
|
|
6891
6946
|
*
|
|
6947
|
+
* @public
|
|
6892
6948
|
* @returns {String}
|
|
6893
6949
|
*/
|
|
6894
6950
|
|
|
@@ -6901,6 +6957,7 @@ module.exports = function () {
|
|
|
6901
6957
|
* Returns true if the provided {@link Enum} argument is equal
|
|
6902
6958
|
* to the instance.
|
|
6903
6959
|
*
|
|
6960
|
+
* @public
|
|
6904
6961
|
* @param {Enum} other
|
|
6905
6962
|
* @returns {boolean}
|
|
6906
6963
|
*/
|
|
@@ -6925,6 +6982,7 @@ module.exports = function () {
|
|
|
6925
6982
|
* Looks up a enumeration item; given the enumeration type and the enumeration
|
|
6926
6983
|
* item's value. If no matching item can be found, a null value is returned.
|
|
6927
6984
|
*
|
|
6985
|
+
* @public
|
|
6928
6986
|
* @param {Function} type - The enumeration type.
|
|
6929
6987
|
* @param {String} code - The enumeration item's code.
|
|
6930
6988
|
* @returns {*|null}
|
|
@@ -6944,6 +7002,7 @@ module.exports = function () {
|
|
|
6944
7002
|
/**
|
|
6945
7003
|
* The description.
|
|
6946
7004
|
*
|
|
7005
|
+
* @public
|
|
6947
7006
|
* @returns {String}
|
|
6948
7007
|
*/
|
|
6949
7008
|
|
|
@@ -6963,6 +7022,7 @@ module.exports = function () {
|
|
|
6963
7022
|
/**
|
|
6964
7023
|
* Returns all of the enumeration's items (given an enumeration type).
|
|
6965
7024
|
*
|
|
7025
|
+
* @public
|
|
6966
7026
|
* @param {Function} type - The enumeration to list.
|
|
6967
7027
|
* @returns {Array}
|
|
6968
7028
|
*/
|
|
@@ -7420,7 +7480,7 @@ module.exports = function () {
|
|
|
7420
7480
|
* Parses the value emitted by {@link Timestamp#toJSON}.
|
|
7421
7481
|
*
|
|
7422
7482
|
* @public
|
|
7423
|
-
* @param {
|
|
7483
|
+
* @param {Number} value
|
|
7424
7484
|
* @returns {Timestamp}
|
|
7425
7485
|
*/
|
|
7426
7486
|
|
|
@@ -8056,7 +8116,7 @@ module.exports = function () {
|
|
|
8056
8116
|
|
|
8057
8117
|
if (typeof itemConstraint === 'function' && itemConstraint !== Function) {
|
|
8058
8118
|
itemValidator = function itemValidator(value, index) {
|
|
8059
|
-
return value instanceof itemConstraint || itemConstraint(value, variableName + '[' + index + ']');
|
|
8119
|
+
return itemConstraint.prototype !== undefined && value instanceof itemConstraint || itemConstraint(value, variableName + '[' + index + ']');
|
|
8060
8120
|
};
|
|
8061
8121
|
} else {
|
|
8062
8122
|
itemValidator = function itemValidator(value, index) {
|
|
@@ -8166,7 +8226,7 @@ module.exports = function () {
|
|
|
8166
8226
|
*
|
|
8167
8227
|
* @static
|
|
8168
8228
|
* @param {Object} target - The object to check for existence of the property.
|
|
8169
|
-
* @param {String|Array
|
|
8229
|
+
* @param {String|Array.<String>} propertyNames - The property to check -- either a string with separators, or an array of strings (already split by separator).
|
|
8170
8230
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
8171
8231
|
* @returns {boolean}
|
|
8172
8232
|
*/
|
|
@@ -8192,7 +8252,7 @@ module.exports = function () {
|
|
|
8192
8252
|
*
|
|
8193
8253
|
* @static
|
|
8194
8254
|
* @param {Object} target - The object to read from.
|
|
8195
|
-
* @param {String|Array
|
|
8255
|
+
* @param {String|Array.<String>} propertyNames - The property to read -- either a string with separators, or an array of strings (already split by separator).
|
|
8196
8256
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
8197
8257
|
* @returns {*}
|
|
8198
8258
|
*/
|
|
@@ -8227,7 +8287,8 @@ module.exports = function () {
|
|
|
8227
8287
|
*
|
|
8228
8288
|
* @static
|
|
8229
8289
|
* @param {Object} target - The object to write to.
|
|
8230
|
-
* @param {String|Array
|
|
8290
|
+
* @param {String|Array.<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
|
|
8291
|
+
* @param {*} value - The value to assign.
|
|
8231
8292
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
8232
8293
|
*/
|
|
8233
8294
|
write: function write(target, propertyNames, value, separator) {
|
|
@@ -8253,7 +8314,7 @@ module.exports = function () {
|
|
|
8253
8314
|
*
|
|
8254
8315
|
* @static
|
|
8255
8316
|
* @param {Object} target - The object to erase a property from.
|
|
8256
|
-
* @param {String|Array
|
|
8317
|
+
* @param {String|Array.<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
|
|
8257
8318
|
* @param {String=} separator - The separator (defaults to a period character).
|
|
8258
8319
|
*/
|
|
8259
8320
|
erase: function erase(target, propertyNames, separator) {
|
|
@@ -9506,7 +9567,7 @@ module.exports = function () {
|
|
|
9506
9567
|
}
|
|
9507
9568
|
|
|
9508
9569
|
/**
|
|
9509
|
-
* Generates a function suitable for use by JSON.parse.
|
|
9570
|
+
* Generates a function suitable for use by {@link JSON.parse}.
|
|
9510
9571
|
*
|
|
9511
9572
|
* @public
|
|
9512
9573
|
* @returns {Function}
|
|
@@ -13631,9 +13692,9 @@ moment.tz.load(require('./data/packed/latest.json'));
|
|
|
13631
13692
|
|
|
13632
13693
|
mom = createUTC([2000, 1]).day(i);
|
|
13633
13694
|
if (strict && !this._fullWeekdaysParse[i]) {
|
|
13634
|
-
this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '
|
|
13635
|
-
this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '
|
|
13636
|
-
this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '
|
|
13695
|
+
this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\\.?') + '$', 'i');
|
|
13696
|
+
this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\\.?') + '$', 'i');
|
|
13697
|
+
this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\\.?') + '$', 'i');
|
|
13637
13698
|
}
|
|
13638
13699
|
if (!this._weekdaysParse[i]) {
|
|
13639
13700
|
regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
|
|
@@ -14436,7 +14497,7 @@ moment.tz.load(require('./data/packed/latest.json'));
|
|
|
14436
14497
|
|
|
14437
14498
|
function preprocessRFC2822(s) {
|
|
14438
14499
|
// Remove comments and folding whitespace and replace multiple-spaces with a single space
|
|
14439
|
-
return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').
|
|
14500
|
+
return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
|
14440
14501
|
}
|
|
14441
14502
|
|
|
14442
14503
|
function checkWeekday(weekdayStr, parsedInput, config) {
|
|
@@ -16615,7 +16676,7 @@ moment.tz.load(require('./data/packed/latest.json'));
|
|
|
16615
16676
|
// Side effect imports
|
|
16616
16677
|
|
|
16617
16678
|
|
|
16618
|
-
hooks.version = '2.22.
|
|
16679
|
+
hooks.version = '2.22.2';
|
|
16619
16680
|
|
|
16620
16681
|
setHookCallback(createLocal);
|
|
16621
16682
|
|