@barchart/portfolio-api-common 1.2.57 → 1.2.61

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.
@@ -19,11 +19,12 @@ module.exports = (() => {
19
19
  * @param {Boolean} canSwitchDirection
20
20
  * @param {Boolean} usesSymbols
21
21
  * @param {Boolean} hasCorporateActions
22
- * @param {Number} closeFractional
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';
@@ -26,10 +26,11 @@ module.exports = (() => {
26
26
  * @public
27
27
  * @static
28
28
  * @param {Array.<Object>} transactions
29
+ * @param {Boolean=} strict
29
30
  * @returns {Boolean}
30
31
  */
31
- static validateOrder(transactions) {
32
- return TransactionValidator.getInvalidIndex(transactions) < 0;
32
+ static validateOrder(transactions, strict) {
33
+ return TransactionValidator.getInvalidIndex(transactions, strict) < 0;
33
34
  }
34
35
 
35
36
  /**
@@ -77,15 +78,14 @@ module.exports = (() => {
77
78
  * @public
78
79
  * @static
79
80
  * @param {Array.<Object>} transactions
81
+ * @param {Boolean=} strict
80
82
  * @returns {Number}
81
83
  */
82
- static getInvalidIndex(transactions) {
84
+ static getInvalidIndex(transactions, strict) {
83
85
  assert.argumentIsArray(transactions, 'transactions');
86
+ assert.argumentIsOptional(strict, 'strict', Boolean);
84
87
 
85
- return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(transactions[i - 1].date)))
86
-
87
- //return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)));
88
- //return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
88
+ return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && is.boolean(strict) && strict && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
89
89
  }
90
90
 
91
91
  /**
@@ -1,5 +1,4 @@
1
- const assert = require('@barchart/common-js/lang/assert'),
2
- Enum = require('@barchart/common-js/lang/Enum');
1
+ const Enum = require('@barchart/common-js/lang/Enum');
3
2
 
4
3
  module.exports = (() => {
5
4
  '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 summary = item.currentSummary;
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 (!summary.end.open.getIsZero()) {
421
- priceToUse = summary.end.value.divide(summary.end.open);
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 = summary.period;
429
+ const period = currentSummary.period;
428
430
 
429
- let unrealized = summary.end.open.multiply(priceToUse).add(summary.end.basis);
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(summary) {
468
+ function calculateSummaryTotal(currentSummary, previousSummary) {
467
469
  let returnRef;
468
470
 
469
- if (summary) {
470
- const period = summary.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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.57",
3
+ "version": "1.2.61",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -20,11 +20,12 @@ module.exports = (() => {
20
20
  * @param {Boolean} canSwitchDirection
21
21
  * @param {Boolean} usesSymbols
22
22
  * @param {Boolean} hasCorporateActions
23
- * @param {Number} closeFractional
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,"@barchart/common-js/lang/is":33}],4:[function(require,module,exports){
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
 
@@ -1083,10 +1095,11 @@ module.exports = (() => {
1083
1095
  * @public
1084
1096
  * @static
1085
1097
  * @param {Array.<Object>} transactions
1098
+ * @param {Boolean=} strict
1086
1099
  * @returns {Boolean}
1087
1100
  */
1088
- static validateOrder(transactions) {
1089
- return TransactionValidator.getInvalidIndex(transactions) < 0;
1101
+ static validateOrder(transactions, strict) {
1102
+ return TransactionValidator.getInvalidIndex(transactions, strict) < 0;
1090
1103
  }
1091
1104
 
1092
1105
  /**
@@ -1134,15 +1147,14 @@ module.exports = (() => {
1134
1147
  * @public
1135
1148
  * @static
1136
1149
  * @param {Array.<Object>} transactions
1150
+ * @param {Boolean=} strict
1137
1151
  * @returns {Number}
1138
1152
  */
1139
- static getInvalidIndex(transactions) {
1153
+ static getInvalidIndex(transactions, strict) {
1140
1154
  assert.argumentIsArray(transactions, 'transactions');
1155
+ assert.argumentIsOptional(strict, 'strict', Boolean);
1141
1156
 
1142
- return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(transactions[i - 1].date)))
1143
-
1144
- //return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)));
1145
- //return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
1157
+ return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && is.boolean(strict) && strict && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
1146
1158
  }
1147
1159
 
1148
1160
  /**
@@ -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/lang/is":33,"@barchart/common-js/messaging/Event":35}],7:[function(require,module,exports){
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 summary = item.currentSummary;
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 (!summary.end.open.getIsZero()) {
3558
- priceToUse = summary.end.value.divide(summary.end.open);
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 = summary.period;
3577
+ const period = currentSummary.period;
3565
3578
 
3566
- let unrealized = summary.end.open.multiply(priceToUse).add(summary.end.basis);
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(summary) {
3616
+ function calculateSummaryTotal(currentSummary, previousSummary) {
3604
3617
  let returnRef;
3605
3618
 
3606
- if (summary) {
3607
- const period = summary.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 {String} a
5170
- * @param {String} b
5182
+ * @param {Number} a
5183
+ * @param {Number} 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 leftPad(this._year, 4, '0') + '-' + leftPad(this._month, 2, '0') + '-' + leftPad(this._day, 2, '0');
5873
+ return this._year + '-' + leftPad(this._month) + '-' + leftPad(this._day);
5861
5874
  }
5862
5875
 
5863
5876
  /**
@@ -5974,7 +5987,7 @@ module.exports = function () {
5974
5987
  *
5975
5988
  * @static
5976
5989
  * @public
5977
- * @returns {Day}
5990
+ * @return {Day}
5978
5991
  */
5979
5992
 
5980
5993
  }, {
@@ -6066,11 +6079,8 @@ module.exports = function () {
6066
6079
 
6067
6080
  var dayRegex = /^([0-9]{4}).?([0-9]{2}).?([0-9]{2})$/;
6068
6081
 
6069
- function leftPad(value, digits, character) {
6070
- var string = value.toString();
6071
- var padding = digits - string.length;
6072
-
6073
- return '' + character.repeat(padding) + string;
6082
+ function leftPad(value) {
6083
+ return value < 10 ? '0' + value : '' + value;
6074
6084
  }
6075
6085
 
6076
6086
  var comparator = ComparatorBuilder.startWith(function (a, b) {
@@ -6425,7 +6435,7 @@ module.exports = function () {
6425
6435
  *
6426
6436
  * @public
6427
6437
  * @param {Decimal} instance
6428
- * @returns {Boolean}
6438
+ * @return {Boolean}
6429
6439
  */
6430
6440
  value: function getIsZero(instance) {
6431
6441
  assert.argumentIsRequired(instance, 'instance', Decimal, 'Decimal');
@@ -6438,7 +6448,7 @@ module.exports = function () {
6438
6448
  *
6439
6449
  * @public
6440
6450
  * @param {Decimal} instance
6441
- * @returns {Boolean}
6451
+ * @return {Boolean}
6442
6452
  */
6443
6453
 
6444
6454
  }, {
@@ -6454,7 +6464,7 @@ module.exports = function () {
6454
6464
  *
6455
6465
  * @public
6456
6466
  * @param {Decimal} instance
6457
- * @returns {Boolean}
6467
+ * @return {Boolean}
6458
6468
  */
6459
6469
 
6460
6470
  }, {
@@ -6470,7 +6480,7 @@ module.exports = function () {
6470
6480
  *
6471
6481
  * @public
6472
6482
  * @param {Decimal} instance
6473
- * @returns {Boolean}
6483
+ * @return {Boolean}
6474
6484
  */
6475
6485
 
6476
6486
  }, {
@@ -6486,7 +6496,7 @@ module.exports = function () {
6486
6496
  *
6487
6497
  * @public
6488
6498
  * @param {Decimal} instance
6489
- * @returns {Boolean}
6499
+ * @return {Boolean}
6490
6500
  */
6491
6501
 
6492
6502
  }, {
@@ -6502,7 +6512,7 @@ module.exports = function () {
6502
6512
  *
6503
6513
  * @public
6504
6514
  * @param {Decimal} instance
6505
- * @returns {Boolean}
6515
+ * @return {Boolean}
6506
6516
  */
6507
6517
 
6508
6518
  }, {
@@ -6892,7 +6902,6 @@ module.exports = function () {
6892
6902
  /**
6893
6903
  * The unique code.
6894
6904
  *
6895
- * @public
6896
6905
  * @returns {String}
6897
6906
  */
6898
6907
 
@@ -6905,7 +6914,6 @@ module.exports = function () {
6905
6914
  * Returns true if the provided {@link Enum} argument is equal
6906
6915
  * to the instance.
6907
6916
  *
6908
- * @public
6909
6917
  * @param {Enum} other
6910
6918
  * @returns {boolean}
6911
6919
  */
@@ -6930,7 +6938,6 @@ module.exports = function () {
6930
6938
  * Looks up a enumeration item; given the enumeration type and the enumeration
6931
6939
  * item's value. If no matching item can be found, a null value is returned.
6932
6940
  *
6933
- * @public
6934
6941
  * @param {Function} type - The enumeration type.
6935
6942
  * @param {String} code - The enumeration item's code.
6936
6943
  * @returns {*|null}
@@ -6950,7 +6957,6 @@ module.exports = function () {
6950
6957
  /**
6951
6958
  * The description.
6952
6959
  *
6953
- * @public
6954
6960
  * @returns {String}
6955
6961
  */
6956
6962
 
@@ -6970,7 +6976,6 @@ module.exports = function () {
6970
6976
  /**
6971
6977
  * Returns all of the enumeration's items (given an enumeration type).
6972
6978
  *
6973
- * @public
6974
6979
  * @param {Function} type - The enumeration to list.
6975
6980
  * @returns {Array}
6976
6981
  */
@@ -7428,7 +7433,7 @@ module.exports = function () {
7428
7433
  * Parses the value emitted by {@link Timestamp#toJSON}.
7429
7434
  *
7430
7435
  * @public
7431
- * @param {Number} value
7436
+ * @param {String} value
7432
7437
  * @returns {Timestamp}
7433
7438
  */
7434
7439
 
@@ -8064,7 +8069,7 @@ module.exports = function () {
8064
8069
 
8065
8070
  if (typeof itemConstraint === 'function' && itemConstraint !== Function) {
8066
8071
  itemValidator = function itemValidator(value, index) {
8067
- return itemConstraint.prototype !== undefined && value instanceof itemConstraint || itemConstraint(value, variableName + '[' + index + ']');
8072
+ return value instanceof itemConstraint || itemConstraint(value, variableName + '[' + index + ']');
8068
8073
  };
8069
8074
  } else {
8070
8075
  itemValidator = function itemValidator(value, index) {
@@ -8174,7 +8179,7 @@ module.exports = function () {
8174
8179
  *
8175
8180
  * @static
8176
8181
  * @param {Object} target - The object to check for existence of the property.
8177
- * @param {String|Array.<String>} propertyNames - The property to check -- either a string with separators, or an array of strings (already split by separator).
8182
+ * @param {String|Array<String>} propertyNames - The property to check -- either a string with separators, or an array of strings (already split by separator).
8178
8183
  * @param {String=} separator - The separator (defaults to a period character).
8179
8184
  * @returns {boolean}
8180
8185
  */
@@ -8200,7 +8205,7 @@ module.exports = function () {
8200
8205
  *
8201
8206
  * @static
8202
8207
  * @param {Object} target - The object to read from.
8203
- * @param {String|Array.<String>} propertyNames - The property to read -- either a string with separators, or an array of strings (already split by separator).
8208
+ * @param {String|Array<String>} propertyNames - The property to read -- either a string with separators, or an array of strings (already split by separator).
8204
8209
  * @param {String=} separator - The separator (defaults to a period character).
8205
8210
  * @returns {*}
8206
8211
  */
@@ -8235,8 +8240,7 @@ module.exports = function () {
8235
8240
  *
8236
8241
  * @static
8237
8242
  * @param {Object} target - The object to write to.
8238
- * @param {String|Array.<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
8239
- * @param {*} value - The value to assign.
8243
+ * @param {String|Array<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
8240
8244
  * @param {String=} separator - The separator (defaults to a period character).
8241
8245
  */
8242
8246
  write: function write(target, propertyNames, value, separator) {
@@ -8262,7 +8266,7 @@ module.exports = function () {
8262
8266
  *
8263
8267
  * @static
8264
8268
  * @param {Object} target - The object to erase a property from.
8265
- * @param {String|Array.<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
8269
+ * @param {String|Array<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
8266
8270
  * @param {String=} separator - The separator (defaults to a period character).
8267
8271
  */
8268
8272
  erase: function erase(target, propertyNames, separator) {
@@ -9515,7 +9519,7 @@ module.exports = function () {
9515
9519
  }
9516
9520
 
9517
9521
  /**
9518
- * Generates a function suitable for use by {@link JSON.parse}.
9522
+ * Generates a function suitable for use by JSON.parse.
9519
9523
  *
9520
9524
  * @public
9521
9525
  * @returns {Function}
@@ -13640,9 +13644,9 @@ moment.tz.load(require('./data/packed/latest.json'));
13640
13644
 
13641
13645
  mom = createUTC([2000, 1]).day(i);
13642
13646
  if (strict && !this._fullWeekdaysParse[i]) {
13643
- this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\\.?') + '$', 'i');
13644
- this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\\.?') + '$', 'i');
13645
- this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\\.?') + '$', 'i');
13647
+ this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
13648
+ this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
13649
+ this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
13646
13650
  }
13647
13651
  if (!this._weekdaysParse[i]) {
13648
13652
  regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
@@ -14445,7 +14449,7 @@ moment.tz.load(require('./data/packed/latest.json'));
14445
14449
 
14446
14450
  function preprocessRFC2822(s) {
14447
14451
  // Remove comments and folding whitespace and replace multiple-spaces with a single space
14448
- return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, '');
14452
+ return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').trim();
14449
14453
  }
14450
14454
 
14451
14455
  function checkWeekday(weekdayStr, parsedInput, config) {
@@ -16624,7 +16628,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16624
16628
  // Side effect imports
16625
16629
 
16626
16630
 
16627
- hooks.version = '2.22.2';
16631
+ hooks.version = '2.22.1';
16628
16632
 
16629
16633
  setHookCallback(createLocal);
16630
16634
 
@@ -17256,15 +17260,17 @@ describe('When validating transaction order', () => {
17256
17260
  expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
17257
17261
  });
17258
17262
 
17259
- /*
17260
17263
  it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
17261
17264
  expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
17262
17265
  });
17263
17266
 
17264
- it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
17265
- expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
17267
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, in strict mode, should not be valid', () => {
17268
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ], true)).toEqual(false);
17269
+ });
17270
+
17271
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, in non-strict mode, should be valid', () => {
17272
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ], false)).toEqual(true);
17266
17273
  });
17267
- */
17268
17274
 
17269
17275
  it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
17270
17276
  expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
@@ -18,15 +18,17 @@ describe('When validating transaction order', () => {
18
18
  expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
19
19
  });
20
20
 
21
- /*
22
21
  it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
23
22
  expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
24
23
  });
25
24
 
26
- it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
27
- expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
25
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, in strict mode, should not be valid', () => {
26
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ], true)).toEqual(false);
27
+ });
28
+
29
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, in non-strict mode, should be valid', () => {
30
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ], false)).toEqual(true);
28
31
  });
29
- */
30
32
 
31
33
  it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
32
34
  expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);