@barchart/portfolio-api-common 1.0.260 → 1.0.264

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.
@@ -20,18 +20,34 @@ module.exports = (() => {
20
20
  * @param {Function} descriptionCalculator
21
21
  */
22
22
  class PositionSummaryFrame extends Enum {
23
- constructor(code, description, rangeCalculator, startDateCalculator, descriptionCalculator) {
23
+ constructor(code, description, unique, rangeCalculator, startDateCalculator, descriptionCalculator) {
24
24
  super(code, description);
25
25
 
26
+ assert.argumentIsRequired(unique, 'unique', Boolean);
27
+
26
28
  assert.argumentIsRequired(rangeCalculator, 'rangeCalculator', Function);
27
29
  assert.argumentIsRequired(startDateCalculator, 'startDateCalculator', Function);
28
30
  assert.argumentIsRequired(descriptionCalculator, 'descriptionCalculator', Function);
29
31
 
32
+ this._unique = unique;
33
+
30
34
  this._rangeCalculator = rangeCalculator;
31
35
  this._startDateCalculator = startDateCalculator;
32
36
  this._descriptionCalculator = descriptionCalculator;
33
37
  }
34
38
 
39
+ /**
40
+ * If true, only one summary, of the given type, can exist for a
41
+ * position. If false, multiple summaries, of the given type, can
42
+ * exist for a position.
43
+ *
44
+ * @public
45
+ * @return {Boolean}
46
+ */
47
+ get unique() {
48
+ return this._unique;
49
+ }
50
+
35
51
  /**
36
52
  * Returns a human-readable description of the frame, given
37
53
  * start and end dates.
@@ -129,10 +145,10 @@ module.exports = (() => {
129
145
  }
130
146
  }
131
147
 
132
- const yearly = new PositionSummaryFrame('YEARLY', 'year', getYearlyRanges, getYearlyStartDate, getYearlyRangeDescription);
133
- const quarterly = new PositionSummaryFrame('QUARTER', 'quarter', getQuarterlyRanges, getQuarterlyStartDate, getQuarterlyRangeDescription);
134
- const monthly = new PositionSummaryFrame('MONTH', 'month', getMonthlyRanges, getMonthlyStartDate, getMonthlyRangeDescription);
135
- const ytd = new PositionSummaryFrame('YTD', 'year-to-date', getYearToDateRanges, getYearToDateStartDate, getYearToDateRangeDescription);
148
+ const yearly = new PositionSummaryFrame('YEARLY', 'year', false, getYearlyRanges, getYearlyStartDate, getYearlyRangeDescription);
149
+ const quarterly = new PositionSummaryFrame('QUARTER', 'quarter', false, getQuarterlyRanges, getQuarterlyStartDate, getQuarterlyRangeDescription);
150
+ const monthly = new PositionSummaryFrame('MONTH', 'month', false, getMonthlyRanges, getMonthlyStartDate, getMonthlyRangeDescription);
151
+ const ytd = new PositionSummaryFrame('YTD', 'year-to-date', true, getYearToDateRanges, getYearToDateStartDate, getYearToDateRangeDescription);
136
152
 
137
153
  /**
138
154
  * The start and and date for a {@link PositionSummaryFrame}
@@ -18,9 +18,10 @@ module.exports = (() => {
18
18
  * @param {Boolean} opening
19
19
  * @param {Boolean} closing
20
20
  * @param {Boolean} fee
21
+ * @param {Boolean} corporateAction
21
22
  */
22
23
  class TransactionType extends Enum {
23
- constructor(code, description, display, purchase, sale, income, opening, closing, fee) {
24
+ constructor(code, description, display, purchase, sale, income, opening, closing, fee, corporateAction) {
24
25
  super(code, description);
25
26
 
26
27
  assert.argumentIsRequired(display, 'display', String);
@@ -30,6 +31,7 @@ module.exports = (() => {
30
31
  assert.argumentIsRequired(opening, 'opening', Boolean);
31
32
  assert.argumentIsRequired(closing, 'closing', Boolean);
32
33
  assert.argumentIsRequired(fee, 'fee', Boolean);
34
+ assert.argumentIsRequired(corporateAction, 'corporateAction', Boolean);
33
35
 
34
36
  this._display = display;
35
37
  this._purchase = purchase;
@@ -38,6 +40,7 @@ module.exports = (() => {
38
40
  this._opening = opening;
39
41
  this._closing = closing;
40
42
  this._fee = fee;
43
+ this._corporateAction = corporateAction;
41
44
  }
42
45
 
43
46
  /**
@@ -123,6 +126,16 @@ module.exports = (() => {
123
126
  return this._fee;
124
127
  }
125
128
 
129
+ /**
130
+ * Indicates if the transaction is a corporate action.
131
+ *
132
+ * @public
133
+ * @returns {Boolean}
134
+ */
135
+ get corporateAction() {
136
+ return this._corporateAction;
137
+ }
138
+
126
139
  /**
127
140
  * A purchase.
128
141
  *
@@ -326,27 +339,27 @@ module.exports = (() => {
326
339
  }
327
340
  }
328
341
 
329
- const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false);
330
- const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false);
331
- const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false);
332
- const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false);
333
- const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false);
334
- const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false);
335
- const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false);
336
- const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false);
337
- const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, false, false, true);
338
- const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false);
339
-
340
- const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false);
341
- const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false);
342
-
343
- const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false);
344
- const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false);
345
- const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false);
346
- const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false);
347
-
348
- const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false);
349
- const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false);
342
+ const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false, false);
343
+ const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false, false);
344
+ const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false, false);
345
+ const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false, false);
346
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false, true);
347
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false, true);
348
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false, true);
349
+ const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false, true);
350
+ const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, false, false, true, false);
351
+ const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false, false);
352
+
353
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false, true);
354
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false, true);
355
+
356
+ const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false, false);
357
+ const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false, false);
358
+ const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false, false);
359
+ const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false, false);
360
+
361
+ const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false, false);
362
+ const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false, false);
350
363
 
351
364
  return TransactionType;
352
365
  })();
@@ -1,4 +1,5 @@
1
- const assert = require('@barchart/common-js/lang/assert');
1
+ const assert = require('@barchart/common-js/lang/assert'),
2
+ array = require('@barchart/common-js/lang/array')
2
3
 
3
4
  const InstrumentType = require('./InstrumentType'),
4
5
  PositionDirection = require('./PositionDirection'),
@@ -17,6 +18,31 @@ module.exports = (() => {
17
18
 
18
19
  }
19
20
 
21
+ /**
22
+ * Given a set of transaction, ensures that sequence numbers and dates
23
+ * are properly ordered.
24
+ *
25
+ * @public
26
+ * @static
27
+ * @param {Array.<Object>} transactions
28
+ * @param {Boolean=} partial - If true, sequence validation starts with the array's first transaction.
29
+ * @return {boolean}
30
+ */
31
+ static validateOrder(transactions, partial) {
32
+ assert.argumentIsArray(transactions, 'transactions');
33
+ assert.argumentIsOptional(partial, 'partial', Boolean);
34
+
35
+ let startSequence;
36
+
37
+ if (partial && transactions.length !== 0) {
38
+ startSequence = array.first(transactions).sequence;
39
+ } else {
40
+ startSequence = 1;
41
+ }
42
+
43
+ return transactions.every((t, i) => t.sequence === (i + startSequence) && (i === 0 || !t.date.getIsBefore(transactions[i - 1].date)));
44
+ }
45
+
20
46
  /**
21
47
  * Given an instrument type, returns all valid transaction types.
22
48
  *
@@ -123,7 +123,7 @@ module.exports = (() => {
123
123
 
124
124
  this._forexSymbols = forexCurrencyCodes.reduce((symbols, code) => {
125
125
  if (code !== DEFAULT_CURRENCY.code) {
126
- symbols.push(`^${DEFAULT_CURRENCY.code}${code}`);
126
+ symbols.push(`^${code}${DEFAULT_CURRENCY.code}`);
127
127
  }
128
128
 
129
129
  return symbols;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.260",
3
+ "version": "1.0.264",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -185,7 +185,137 @@ module.exports = (() => {
185
185
  return InstrumentType;
186
186
  })();
187
187
 
188
- },{"@barchart/common-js/lang/Enum":19,"@barchart/common-js/lang/assert":22,"uuid":28}],2:[function(require,module,exports){
188
+ },{"@barchart/common-js/lang/Enum":21,"@barchart/common-js/lang/assert":24,"uuid":30}],2:[function(require,module,exports){
189
+ const assert = require('@barchart/common-js/lang/assert'),
190
+ Decimal = require('@barchart/common-js/lang/Decimal'),
191
+ Enum = require('@barchart/common-js/lang/Enum');
192
+
193
+ module.exports = (() => {
194
+ 'use strict';
195
+
196
+ /**
197
+ * Describes a position size -- positive values are long, negative values
198
+ * are short and zero values are even.
199
+ *
200
+ * @public
201
+ * @extends {Enum}
202
+ * @param {String} code
203
+ * @param {String} description
204
+ * @param {sign} sign
205
+ */
206
+ class PositionDirection extends Enum {
207
+ constructor(code, description, sign) {
208
+ super(code, description);
209
+
210
+ assert.argumentIsRequired(sign, 'sign', String);
211
+
212
+ this._sign = sign;
213
+ }
214
+
215
+ /**
216
+ * A description of the positiveness or negativeness of the size of the
217
+ * position.
218
+ *
219
+ * @public
220
+ * @returns {String}
221
+ */
222
+ get sign() {
223
+ return this._sign;
224
+ }
225
+
226
+ /**
227
+ * Indicates if the position size is positive (i.e. is {@link PositionDirection.LONG}).
228
+ *
229
+ * @public
230
+ * @returns {boolean}
231
+ */
232
+ get positive() {
233
+ return this === long;
234
+ }
235
+
236
+ /**
237
+ * Indicates if the position size is negative (i.e. is {@link PositionDirection.SHORT}).
238
+ *
239
+ * @public
240
+ * @returns {boolean}
241
+ */
242
+ get negative() {
243
+ return this === short;
244
+ }
245
+
246
+ /**
247
+ * Indicates if the position size is zero (i.e. is {@link PositionDirection.EVEN}).
248
+ *
249
+ * @public
250
+ * @returns {boolean}
251
+ */
252
+ get closed() {
253
+ return this === even;
254
+ }
255
+
256
+ /**
257
+ * A positive quantity position.
258
+ *
259
+ * @public
260
+ * @static
261
+ * @returns {PositionDirection}
262
+ */
263
+ static get LONG() {
264
+ return long;
265
+ }
266
+
267
+ /**
268
+ * A positive quantity position.
269
+ *
270
+ * @public
271
+ * @static
272
+ * @returns {PositionDirection}
273
+ */
274
+ static get SHORT() {
275
+ return short;
276
+ }
277
+
278
+ /**
279
+ * A zero quantity position.
280
+ *
281
+ * @public
282
+ * @static
283
+ * @returns {PositionDirection}
284
+ */
285
+ static get EVEN() {
286
+ return even;
287
+ }
288
+
289
+ /**
290
+ * Given an open quantity, returns a {@link PositionDirection} that
291
+ * describes the quantity.
292
+ *
293
+ * @public
294
+ * @static
295
+ * @param {Decimal} open
296
+ * @returns {PositionDirection}
297
+ */
298
+ static for(open) {
299
+ assert.argumentIsRequired(open, 'open', Decimal, 'Decimal');
300
+
301
+ if (open.getIsPositive()) {
302
+ return long;
303
+ } else if (open.getIsNegative()) {
304
+ return short;
305
+ } else {
306
+ return even;
307
+ }
308
+ }
309
+ }
310
+
311
+ const long = new PositionDirection('LONG', 'Long', 'positive');
312
+ const short = new PositionDirection('SHORT', 'Short', 'negative');
313
+ const even = new PositionDirection('EVEN', 'Even', 'zero');
314
+
315
+ return PositionDirection;
316
+ })();
317
+
318
+ },{"@barchart/common-js/lang/Decimal":19,"@barchart/common-js/lang/Enum":21,"@barchart/common-js/lang/assert":24}],3:[function(require,module,exports){
189
319
  const array = require('@barchart/common-js/lang/array'),
190
320
  assert = require('@barchart/common-js/lang/assert'),
191
321
  Day = require('@barchart/common-js/lang/Day'),
@@ -208,18 +338,34 @@ module.exports = (() => {
208
338
  * @param {Function} descriptionCalculator
209
339
  */
210
340
  class PositionSummaryFrame extends Enum {
211
- constructor(code, description, rangeCalculator, startDateCalculator, descriptionCalculator) {
341
+ constructor(code, description, unique, rangeCalculator, startDateCalculator, descriptionCalculator) {
212
342
  super(code, description);
213
343
 
344
+ assert.argumentIsRequired(unique, 'unique', Boolean);
345
+
214
346
  assert.argumentIsRequired(rangeCalculator, 'rangeCalculator', Function);
215
347
  assert.argumentIsRequired(startDateCalculator, 'startDateCalculator', Function);
216
348
  assert.argumentIsRequired(descriptionCalculator, 'descriptionCalculator', Function);
217
349
 
350
+ this._unique = unique;
351
+
218
352
  this._rangeCalculator = rangeCalculator;
219
353
  this._startDateCalculator = startDateCalculator;
220
354
  this._descriptionCalculator = descriptionCalculator;
221
355
  }
222
356
 
357
+ /**
358
+ * If true, only one summary, of the given type, can exist for a
359
+ * position. If false, multiple summaries, of the given type, can
360
+ * exist for a position.
361
+ *
362
+ * @public
363
+ * @return {Boolean}
364
+ */
365
+ get unique() {
366
+ return this._unique;
367
+ }
368
+
223
369
  /**
224
370
  * Returns a human-readable description of the frame, given
225
371
  * start and end dates.
@@ -317,10 +463,10 @@ module.exports = (() => {
317
463
  }
318
464
  }
319
465
 
320
- const yearly = new PositionSummaryFrame('YEARLY', 'year', getYearlyRanges, getYearlyStartDate, getYearlyRangeDescription);
321
- const quarterly = new PositionSummaryFrame('QUARTER', 'quarter', getQuarterlyRanges, getQuarterlyStartDate, getQuarterlyRangeDescription);
322
- const monthly = new PositionSummaryFrame('MONTH', 'month', getMonthlyRanges, getMonthlyStartDate, getMonthlyRangeDescription);
323
- const ytd = new PositionSummaryFrame('YTD', 'year-to-date', getYearToDateRanges, getYearToDateStartDate, getYearToDateRangeDescription);
466
+ const yearly = new PositionSummaryFrame('YEARLY', 'year', false, getYearlyRanges, getYearlyStartDate, getYearlyRangeDescription);
467
+ const quarterly = new PositionSummaryFrame('QUARTER', 'quarter', false, getQuarterlyRanges, getQuarterlyStartDate, getQuarterlyRangeDescription);
468
+ const monthly = new PositionSummaryFrame('MONTH', 'month', false, getMonthlyRanges, getMonthlyStartDate, getMonthlyRangeDescription);
469
+ const ytd = new PositionSummaryFrame('YTD', 'year-to-date', true, getYearToDateRanges, getYearToDateStartDate, getYearToDateRangeDescription);
324
470
 
325
471
  /**
326
472
  * The start and and date for a {@link PositionSummaryFrame}
@@ -442,7 +588,7 @@ module.exports = (() => {
442
588
  return PositionSummaryFrame;
443
589
  })();
444
590
 
445
- },{"@barchart/common-js/lang/Day":16,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Enum":19,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24}],3:[function(require,module,exports){
591
+ },{"@barchart/common-js/lang/Day":18,"@barchart/common-js/lang/Decimal":19,"@barchart/common-js/lang/Enum":21,"@barchart/common-js/lang/array":23,"@barchart/common-js/lang/assert":24,"@barchart/common-js/lang/is":26}],4:[function(require,module,exports){
446
592
  const assert = require('@barchart/common-js/lang/assert'),
447
593
  Enum = require('@barchart/common-js/lang/Enum');
448
594
 
@@ -463,9 +609,10 @@ module.exports = (() => {
463
609
  * @param {Boolean} opening
464
610
  * @param {Boolean} closing
465
611
  * @param {Boolean} fee
612
+ * @param {Boolean} corporateAction
466
613
  */
467
614
  class TransactionType extends Enum {
468
- constructor(code, description, display, purchase, sale, income, opening, closing, fee) {
615
+ constructor(code, description, display, purchase, sale, income, opening, closing, fee, corporateAction) {
469
616
  super(code, description);
470
617
 
471
618
  assert.argumentIsRequired(display, 'display', String);
@@ -475,6 +622,7 @@ module.exports = (() => {
475
622
  assert.argumentIsRequired(opening, 'opening', Boolean);
476
623
  assert.argumentIsRequired(closing, 'closing', Boolean);
477
624
  assert.argumentIsRequired(fee, 'fee', Boolean);
625
+ assert.argumentIsRequired(corporateAction, 'corporateAction', Boolean);
478
626
 
479
627
  this._display = display;
480
628
  this._purchase = purchase;
@@ -483,6 +631,7 @@ module.exports = (() => {
483
631
  this._opening = opening;
484
632
  this._closing = closing;
485
633
  this._fee = fee;
634
+ this._corporateAction = corporateAction;
486
635
  }
487
636
 
488
637
  /**
@@ -568,6 +717,16 @@ module.exports = (() => {
568
717
  return this._fee;
569
718
  }
570
719
 
720
+ /**
721
+ * Indicates if the transaction is a corporate action.
722
+ *
723
+ * @public
724
+ * @returns {Boolean}
725
+ */
726
+ get corporateAction() {
727
+ return this._corporateAction;
728
+ }
729
+
571
730
  /**
572
731
  * A purchase.
573
732
  *
@@ -771,32 +930,230 @@ module.exports = (() => {
771
930
  }
772
931
  }
773
932
 
774
- const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false);
775
- const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false);
776
- const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false);
777
- const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false);
778
- const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false);
779
- const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false);
780
- const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false);
781
- const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false);
782
- const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, false, false, true);
783
- const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false);
933
+ const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false, false);
934
+ const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false, false);
935
+ const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false, false);
936
+ const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false, false);
937
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false, true);
938
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false, true);
939
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false, true);
940
+ const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false, true);
941
+ const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, false, false, true, false);
942
+ const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false, false);
784
943
 
785
- const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false);
786
- const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false);
944
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false, true);
945
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false, true);
787
946
 
788
- const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false);
789
- const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false);
790
- const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false);
791
- const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false);
947
+ const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false, false);
948
+ const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false, false);
949
+ const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false, false);
950
+ const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false, false);
792
951
 
793
- const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false);
794
- const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false);
952
+ const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false, false);
953
+ const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false, false);
795
954
 
796
955
  return TransactionType;
797
956
  })();
798
957
 
799
- },{"@barchart/common-js/lang/Enum":19,"@barchart/common-js/lang/assert":22}],4:[function(require,module,exports){
958
+ },{"@barchart/common-js/lang/Enum":21,"@barchart/common-js/lang/assert":24}],5:[function(require,module,exports){
959
+ const assert = require('@barchart/common-js/lang/assert'),
960
+ array = require('@barchart/common-js/lang/array')
961
+
962
+ const InstrumentType = require('./InstrumentType'),
963
+ PositionDirection = require('./PositionDirection'),
964
+ TransactionType = require('./TransactionType');
965
+
966
+ module.exports = (() => {
967
+ 'use strict';
968
+
969
+ /**
970
+ * Static utilities for validating transactions.
971
+ *
972
+ * @public
973
+ */
974
+ class TransactionValidator {
975
+ constructor() {
976
+
977
+ }
978
+
979
+ /**
980
+ * Given a set of transaction, ensures that sequence numbers and dates
981
+ * are properly ordered.
982
+ *
983
+ * @public
984
+ * @static
985
+ * @param {Array.<Object>} transactions
986
+ * @param {Boolean=} partial - If true, sequence validation starts with the array's first transaction.
987
+ * @return {boolean}
988
+ */
989
+ static validateOrder(transactions, partial) {
990
+ assert.argumentIsArray(transactions, 'transactions');
991
+ assert.argumentIsOptional(partial, 'partial', Boolean);
992
+
993
+ let startSequence;
994
+
995
+ if (partial && transactions.length !== 0) {
996
+ startSequence = array.first(transactions).sequence;
997
+ } else {
998
+ startSequence = 1;
999
+ }
1000
+
1001
+ return transactions.every((t, i) => t.sequence === (i + startSequence) && (i === 0 || !t.date.getIsBefore(transactions[i - 1].date)));
1002
+ }
1003
+
1004
+ /**
1005
+ * Given an instrument type, returns all valid transaction types.
1006
+ *
1007
+ * @static
1008
+ * @public
1009
+ * @param {InstrumentType} instrumentType
1010
+ * @param {Boolean=} userInitiated
1011
+ * @pararm {PositionDirection=} currentDirection
1012
+ * @return {Array.<TransactionType>}
1013
+ */
1014
+ static getTransactionTypesFor(instrumentType, userInitiated, currentDirection) {
1015
+ assert.argumentIsRequired(instrumentType, 'instrumentType', InstrumentType, 'InstrumentType');
1016
+ assert.argumentIsOptional(userInitiated, 'userInitiated', Boolean);
1017
+
1018
+ let valid = validTransactionTypes[instrumentType.code] || [ ];
1019
+
1020
+ if (userInitiated) {
1021
+ valid = valid.filter(data => data.user === userInitiated);
1022
+ }
1023
+
1024
+ if (currentDirection) {
1025
+ valid = valid.filter(data => data.directions.some(d => d === currentDirection));
1026
+ }
1027
+
1028
+ return valid.map(d => d.type);
1029
+ }
1030
+
1031
+ /**
1032
+ * Checks to see if an transaction type is applicable to an instrument type.
1033
+ *
1034
+ * @static
1035
+ * @public
1036
+ * @param {InstrumentType} instrumentType
1037
+ * @param {TransactionType} transactionType
1038
+ * @param {Boolean=} userInitiated
1039
+ * @return {Boolean}
1040
+ */
1041
+ static validateTransactionType(instrumentType, transactionType, userInitiated) {
1042
+ assert.argumentIsRequired(transactionType, 'transactionType', TransactionType, 'TransactionType');
1043
+
1044
+ const transactionTypes = TransactionValidator.getTransactionTypesFor(instrumentType, userInitiated);
1045
+
1046
+ return transactionTypes.some(t => t === transactionType);
1047
+ }
1048
+
1049
+ /**
1050
+ * Checks to see if a position for a given instrument type can exist in
1051
+ * the given direction.
1052
+ *
1053
+ * @static
1054
+ * @public
1055
+ * @param {InstrumentType} instrumentType
1056
+ * @param {PositionDirection} direction
1057
+ * @return {Boolean}
1058
+ */
1059
+ static validateDirection(instrumentType, direction) {
1060
+ assert.argumentIsRequired(instrumentType, 'instrumentType', InstrumentType, 'InstrumentType');
1061
+ assert.argumentIsRequired(direction, 'direction', PositionDirection, 'PositionDirection');
1062
+
1063
+ return validDirections[instrumentType.code].some(d => d === direction);
1064
+ }
1065
+
1066
+ /**
1067
+ * Checks to see if the position switches direction and if the direction switch
1068
+ * is valid.
1069
+ *
1070
+ * @static
1071
+ * @public
1072
+ * @param {InstrumentType} instrumentType
1073
+ * @param {PositionDirection|null|undefined} currentDirection
1074
+ * @param {PositionDirection} proposedDirection
1075
+ * @return {Boolean}
1076
+ */
1077
+ static validateDirectionSwitch(instrumentType, currentDirection, proposedDirection) {
1078
+ return currentDirection === null || instrumentType.canSwitchDirection || (currentDirection.closed || proposedDirection.closed || currentDirection.positive === proposedDirection.positive);
1079
+ }
1080
+
1081
+ toString() {
1082
+ return '[TransactionValidator]';
1083
+ }
1084
+ }
1085
+
1086
+ const validTransactionTypes = { };
1087
+
1088
+ function associateTypes(instrumentType, transactionType, userInitiated, directions) {
1089
+ const instrumentTypeCode = instrumentType.code;
1090
+
1091
+ if (!validTransactionTypes.hasOwnProperty(instrumentTypeCode)) {
1092
+ validTransactionTypes[instrumentTypeCode] = [ ];
1093
+ }
1094
+
1095
+ validTransactionTypes[instrumentTypeCode].push({ type: transactionType, user: userInitiated, directions: directions || [ PositionDirection.LONG, PositionDirection.SHORT, PositionDirection.EVEN ] });
1096
+ }
1097
+
1098
+ associateTypes(InstrumentType.EQUITY, TransactionType.BUY, true, [ PositionDirection.LONG, PositionDirection.EVEN ]);
1099
+ associateTypes(InstrumentType.EQUITY, TransactionType.SELL, true, [ PositionDirection.LONG ]);
1100
+ associateTypes(InstrumentType.EQUITY, TransactionType.SELL_SHORT, true, [ PositionDirection.SHORT, PositionDirection.EVEN ]);
1101
+ associateTypes(InstrumentType.EQUITY, TransactionType.BUY_SHORT, true, [ PositionDirection.SHORT ]);
1102
+ associateTypes(InstrumentType.EQUITY, TransactionType.FEE, true, [ PositionDirection.LONG, PositionDirection.SHORT ]);
1103
+ associateTypes(InstrumentType.EQUITY, TransactionType.DIVIDEND, false);
1104
+ associateTypes(InstrumentType.EQUITY, TransactionType.DIVIDEND_REINVEST, false);
1105
+ associateTypes(InstrumentType.EQUITY, TransactionType.DIVIDEND_STOCK, false);
1106
+ associateTypes(InstrumentType.EQUITY, TransactionType.SPLIT, false);
1107
+
1108
+ associateTypes(InstrumentType.FUND, TransactionType.BUY, true, [ PositionDirection.LONG, PositionDirection.EVEN ]);
1109
+ associateTypes(InstrumentType.FUND, TransactionType.SELL, true, [ PositionDirection.LONG ]);
1110
+ associateTypes(InstrumentType.FUND, TransactionType.FEE, true, [ PositionDirection.LONG ]);
1111
+ associateTypes(InstrumentType.FUND, TransactionType.FEE_UNITS, false);
1112
+ associateTypes(InstrumentType.FUND, TransactionType.DISTRIBUTION_CASH, false);
1113
+ associateTypes(InstrumentType.FUND, TransactionType.DISTRIBUTION_FUND, false);
1114
+
1115
+ associateTypes(InstrumentType.OTHER, TransactionType.BUY, true, [ PositionDirection.LONG, PositionDirection.EVEN ]);
1116
+ associateTypes(InstrumentType.OTHER, TransactionType.SELL, true, [ PositionDirection.LONG ]);
1117
+ associateTypes(InstrumentType.OTHER, TransactionType.INCOME, true, [ PositionDirection.LONG ]);
1118
+ associateTypes(InstrumentType.OTHER, TransactionType.FEE, true, [ PositionDirection.LONG ]);
1119
+ associateTypes(InstrumentType.OTHER, TransactionType.VALUATION, true, [ PositionDirection.LONG ]);
1120
+
1121
+ associateTypes(InstrumentType.CASH, TransactionType.DEPOSIT, true);
1122
+ associateTypes(InstrumentType.CASH, TransactionType.WITHDRAWAL, true);
1123
+ associateTypes(InstrumentType.CASH, TransactionType.FEE, true);
1124
+ associateTypes(InstrumentType.CASH, TransactionType.DEBIT, false);
1125
+ associateTypes(InstrumentType.CASH, TransactionType.CREDIT, false);
1126
+
1127
+ const validDirections = { };
1128
+
1129
+ function associateDirections(instrumentType, positionDirection) {
1130
+ const instrumentTypeCode = instrumentType.code;
1131
+
1132
+ if (!validDirections.hasOwnProperty(instrumentTypeCode)) {
1133
+ validDirections[instrumentTypeCode] = [ ];
1134
+ }
1135
+
1136
+ validDirections[instrumentTypeCode].push(positionDirection);
1137
+ }
1138
+
1139
+ associateDirections(InstrumentType.EQUITY, PositionDirection.EVEN);
1140
+ associateDirections(InstrumentType.EQUITY, PositionDirection.LONG);
1141
+ associateDirections(InstrumentType.EQUITY, PositionDirection.SHORT);
1142
+
1143
+ associateDirections(InstrumentType.FUND, PositionDirection.EVEN);
1144
+ associateDirections(InstrumentType.FUND, PositionDirection.LONG);
1145
+
1146
+ associateDirections(InstrumentType.OTHER, PositionDirection.EVEN);
1147
+ associateDirections(InstrumentType.OTHER, PositionDirection.LONG);
1148
+
1149
+ associateDirections(InstrumentType.CASH, PositionDirection.EVEN);
1150
+ associateDirections(InstrumentType.CASH, PositionDirection.LONG);
1151
+ associateDirections(InstrumentType.CASH, PositionDirection.SHORT);
1152
+
1153
+ return TransactionValidator;
1154
+ })();
1155
+
1156
+ },{"./InstrumentType":1,"./PositionDirection":2,"./TransactionType":4,"@barchart/common-js/lang/array":23,"@barchart/common-js/lang/assert":24}],6:[function(require,module,exports){
800
1157
  const array = require('@barchart/common-js/lang/array'),
801
1158
  assert = require('@barchart/common-js/lang/assert'),
802
1159
  ComparatorBuilder = require('@barchart/common-js/collections/sorting/ComparatorBuilder'),
@@ -922,7 +1279,7 @@ module.exports = (() => {
922
1279
 
923
1280
  this._forexSymbols = forexCurrencyCodes.reduce((symbols, code) => {
924
1281
  if (code !== DEFAULT_CURRENCY.code) {
925
- symbols.push(`^${DEFAULT_CURRENCY.code}${code}`);
1282
+ symbols.push(`^${code}${DEFAULT_CURRENCY.code}`);
926
1283
  }
927
1284
 
928
1285
  return symbols;
@@ -1754,7 +2111,7 @@ module.exports = (() => {
1754
2111
  return PositionContainer;
1755
2112
  })();
1756
2113
 
1757
- },{"./../data/PositionSummaryFrame":2,"./PositionGroup":5,"./PositionItem":6,"./definitions/PositionLevelDefinition":7,"./definitions/PositionLevelType":8,"./definitions/PositionTreeDefinition":9,"@barchart/common-js/collections/Tree":11,"@barchart/common-js/collections/sorting/ComparatorBuilder":12,"@barchart/common-js/collections/sorting/comparators":13,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],5:[function(require,module,exports){
2114
+ },{"./../data/PositionSummaryFrame":3,"./PositionGroup":7,"./PositionItem":8,"./definitions/PositionLevelDefinition":9,"./definitions/PositionLevelType":10,"./definitions/PositionTreeDefinition":11,"@barchart/common-js/collections/Tree":13,"@barchart/common-js/collections/sorting/ComparatorBuilder":14,"@barchart/common-js/collections/sorting/comparators":15,"@barchart/common-js/collections/specialized/DisposableStack":16,"@barchart/common-js/lang/Currency":17,"@barchart/common-js/lang/Decimal":19,"@barchart/common-js/lang/Rate":22,"@barchart/common-js/lang/array":23,"@barchart/common-js/lang/assert":24,"@barchart/common-js/lang/is":26,"@barchart/common-js/messaging/Event":28}],7:[function(require,module,exports){
1758
2115
  const array = require('@barchart/common-js/lang/array'),
1759
2116
  assert = require('@barchart/common-js/lang/assert'),
1760
2117
  Currency = require('@barchart/common-js/lang/Currency'),
@@ -2629,7 +2986,7 @@ module.exports = (() => {
2629
2986
  return PositionGroup;
2630
2987
  })();
2631
2988
 
2632
- },{"./../data/InstrumentType":1,"./definitions/PositionLevelDefinition":7,"./definitions/PositionLevelType":8,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Disposable":18,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/formatter":23,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],6:[function(require,module,exports){
2989
+ },{"./../data/InstrumentType":1,"./definitions/PositionLevelDefinition":9,"./definitions/PositionLevelType":10,"@barchart/common-js/collections/specialized/DisposableStack":16,"@barchart/common-js/lang/Currency":17,"@barchart/common-js/lang/Decimal":19,"@barchart/common-js/lang/Disposable":20,"@barchart/common-js/lang/Rate":22,"@barchart/common-js/lang/array":23,"@barchart/common-js/lang/assert":24,"@barchart/common-js/lang/formatter":25,"@barchart/common-js/lang/is":26,"@barchart/common-js/messaging/Event":28}],8:[function(require,module,exports){
2633
2990
  const assert = require('@barchart/common-js/lang/assert'),
2634
2991
  Currency = require('@barchart/common-js/lang/Currency'),
2635
2992
  Decimal = require('@barchart/common-js/lang/Decimal'),
@@ -3089,7 +3446,7 @@ module.exports = (() => {
3089
3446
  return PositionItem;
3090
3447
  })();
3091
3448
 
3092
- },{"./../data/InstrumentType":1,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Disposable":18,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],7:[function(require,module,exports){
3449
+ },{"./../data/InstrumentType":1,"@barchart/common-js/lang/Currency":17,"@barchart/common-js/lang/Decimal":19,"@barchart/common-js/lang/Disposable":20,"@barchart/common-js/lang/assert":24,"@barchart/common-js/lang/is":26,"@barchart/common-js/messaging/Event":28}],9:[function(require,module,exports){
3093
3450
  const assert = require('@barchart/common-js/lang/assert'),
3094
3451
  Currency = require('@barchart/common-js/lang/Currency'),
3095
3452
  is = require('@barchart/common-js/lang/is');
@@ -3368,7 +3725,7 @@ module.exports = (() => {
3368
3725
  return PositionLevelDefinition;
3369
3726
  })();
3370
3727
 
3371
- },{"./../../data/InstrumentType":1,"./PositionLevelType":8,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24}],8:[function(require,module,exports){
3728
+ },{"./../../data/InstrumentType":1,"./PositionLevelType":10,"@barchart/common-js/lang/Currency":17,"@barchart/common-js/lang/assert":24,"@barchart/common-js/lang/is":26}],10:[function(require,module,exports){
3372
3729
  const Enum = require('@barchart/common-js/lang/Enum');
3373
3730
 
3374
3731
  module.exports = (() => {
@@ -3399,7 +3756,7 @@ module.exports = (() => {
3399
3756
  return PositionLevelType;
3400
3757
  })();
3401
3758
 
3402
- },{"@barchart/common-js/lang/Enum":19}],9:[function(require,module,exports){
3759
+ },{"@barchart/common-js/lang/Enum":21}],11:[function(require,module,exports){
3403
3760
  const assert = require('@barchart/common-js/lang/assert');
3404
3761
 
3405
3762
  const PositionLevelDefinition = require('./PositionLevelDefinition');
@@ -3470,7 +3827,7 @@ module.exports = (() => {
3470
3827
  return PositionTreeDefinitions;
3471
3828
  })();
3472
3829
 
3473
- },{"./PositionLevelDefinition":7,"@barchart/common-js/lang/assert":22}],10:[function(require,module,exports){
3830
+ },{"./PositionLevelDefinition":9,"@barchart/common-js/lang/assert":24}],12:[function(require,module,exports){
3474
3831
  'use strict';
3475
3832
 
3476
3833
  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; }; }();
@@ -3602,7 +3959,7 @@ module.exports = function () {
3602
3959
  return Stack;
3603
3960
  }();
3604
3961
 
3605
- },{"./../lang/assert":22}],11:[function(require,module,exports){
3962
+ },{"./../lang/assert":24}],13:[function(require,module,exports){
3606
3963
  'use strict';
3607
3964
 
3608
3965
  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; }; }();
@@ -3972,7 +4329,7 @@ module.exports = function () {
3972
4329
  return Tree;
3973
4330
  }();
3974
4331
 
3975
- },{"./../lang/is":24}],12:[function(require,module,exports){
4332
+ },{"./../lang/is":26}],14:[function(require,module,exports){
3976
4333
  'use strict';
3977
4334
 
3978
4335
  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; }; }();
@@ -4116,7 +4473,7 @@ module.exports = function () {
4116
4473
  return ComparatorBuilder;
4117
4474
  }();
4118
4475
 
4119
- },{"./../../lang/assert":22,"./comparators":13}],13:[function(require,module,exports){
4476
+ },{"./../../lang/assert":24,"./comparators":15}],15:[function(require,module,exports){
4120
4477
  'use strict';
4121
4478
 
4122
4479
  var assert = require('./../../lang/assert');
@@ -4191,7 +4548,7 @@ module.exports = function () {
4191
4548
  };
4192
4549
  }();
4193
4550
 
4194
- },{"./../../lang/assert":22}],14:[function(require,module,exports){
4551
+ },{"./../../lang/assert":24}],16:[function(require,module,exports){
4195
4552
  'use strict';
4196
4553
 
4197
4554
  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; }; }();
@@ -4299,7 +4656,7 @@ module.exports = function () {
4299
4656
  return DisposableStack;
4300
4657
  }();
4301
4658
 
4302
- },{"./../../lang/Disposable":18,"./../../lang/assert":22,"./../../lang/is":24,"./../Stack":10}],15:[function(require,module,exports){
4659
+ },{"./../../lang/Disposable":20,"./../../lang/assert":24,"./../../lang/is":26,"./../Stack":12}],17:[function(require,module,exports){
4303
4660
  'use strict';
4304
4661
 
4305
4662
  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; }; }();
@@ -4442,7 +4799,7 @@ module.exports = function () {
4442
4799
  return Currency;
4443
4800
  }();
4444
4801
 
4445
- },{"./Enum":19,"./assert":22,"./is":24}],16:[function(require,module,exports){
4802
+ },{"./Enum":21,"./assert":24,"./is":26}],18:[function(require,module,exports){
4446
4803
  'use strict';
4447
4804
 
4448
4805
  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; }; }();
@@ -4995,7 +5352,7 @@ module.exports = function () {
4995
5352
  return Day;
4996
5353
  }();
4997
5354
 
4998
- },{"./../collections/sorting/ComparatorBuilder":12,"./../collections/sorting/comparators":13,"./assert":22,"./is":24}],17:[function(require,module,exports){
5355
+ },{"./../collections/sorting/ComparatorBuilder":14,"./../collections/sorting/comparators":15,"./assert":24,"./is":26}],19:[function(require,module,exports){
4999
5356
  'use strict';
5000
5357
 
5001
5358
  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; }; }();
@@ -5603,7 +5960,7 @@ module.exports = function () {
5603
5960
  return Decimal;
5604
5961
  }();
5605
5962
 
5606
- },{"./Enum":19,"./assert":22,"./is":24,"big.js":27}],18:[function(require,module,exports){
5963
+ },{"./Enum":21,"./assert":24,"./is":26,"big.js":29}],20:[function(require,module,exports){
5607
5964
  'use strict';
5608
5965
 
5609
5966
  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; }; }();
@@ -5752,7 +6109,7 @@ module.exports = function () {
5752
6109
  return Disposable;
5753
6110
  }();
5754
6111
 
5755
- },{"./assert":22}],19:[function(require,module,exports){
6112
+ },{"./assert":24}],21:[function(require,module,exports){
5756
6113
  'use strict';
5757
6114
 
5758
6115
  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; }; }();
@@ -5894,7 +6251,7 @@ module.exports = function () {
5894
6251
  return Enum;
5895
6252
  }();
5896
6253
 
5897
- },{"./assert":22}],20:[function(require,module,exports){
6254
+ },{"./assert":24}],22:[function(require,module,exports){
5898
6255
  'use strict';
5899
6256
 
5900
6257
  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; }; }();
@@ -6149,7 +6506,7 @@ module.exports = function () {
6149
6506
  return Rate;
6150
6507
  }();
6151
6508
 
6152
- },{"./Currency":15,"./Decimal":17,"./assert":22,"./memoize":25}],21:[function(require,module,exports){
6509
+ },{"./Currency":17,"./Decimal":19,"./assert":24,"./memoize":27}],23:[function(require,module,exports){
6153
6510
  'use strict';
6154
6511
 
6155
6512
  var assert = require('./assert'),
@@ -6550,7 +6907,7 @@ module.exports = function () {
6550
6907
  };
6551
6908
  }();
6552
6909
 
6553
- },{"./assert":22,"./is":24}],22:[function(require,module,exports){
6910
+ },{"./assert":24,"./is":26}],24:[function(require,module,exports){
6554
6911
  'use strict';
6555
6912
 
6556
6913
  var is = require('./is');
@@ -6698,7 +7055,7 @@ module.exports = function () {
6698
7055
  };
6699
7056
  }();
6700
7057
 
6701
- },{"./is":24}],23:[function(require,module,exports){
7058
+ },{"./is":26}],25:[function(require,module,exports){
6702
7059
  'use strict';
6703
7060
 
6704
7061
  module.exports = function () {
@@ -6763,7 +7120,7 @@ module.exports = function () {
6763
7120
  };
6764
7121
  }();
6765
7122
 
6766
- },{}],24:[function(require,module,exports){
7123
+ },{}],26:[function(require,module,exports){
6767
7124
  'use strict';
6768
7125
 
6769
7126
  var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
@@ -6986,7 +7343,7 @@ module.exports = function () {
6986
7343
  };
6987
7344
  }();
6988
7345
 
6989
- },{}],25:[function(require,module,exports){
7346
+ },{}],27:[function(require,module,exports){
6990
7347
  'use strict';
6991
7348
 
6992
7349
  var assert = require('./assert'),
@@ -7059,7 +7416,7 @@ module.exports = function () {
7059
7416
  };
7060
7417
  }();
7061
7418
 
7062
- },{"./assert":22,"./is":24}],26:[function(require,module,exports){
7419
+ },{"./assert":24,"./is":26}],28:[function(require,module,exports){
7063
7420
  'use strict';
7064
7421
 
7065
7422
  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; }; }();
@@ -7231,7 +7588,7 @@ module.exports = function () {
7231
7588
  return Event;
7232
7589
  }();
7233
7590
 
7234
- },{"./../lang/Disposable":18,"./../lang/assert":22}],27:[function(require,module,exports){
7591
+ },{"./../lang/Disposable":20,"./../lang/assert":24}],29:[function(require,module,exports){
7235
7592
  /*
7236
7593
  * big.js v5.0.3
7237
7594
  * A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
@@ -8172,7 +8529,7 @@ module.exports = function () {
8172
8529
  }
8173
8530
  })(this);
8174
8531
 
8175
- },{}],28:[function(require,module,exports){
8532
+ },{}],30:[function(require,module,exports){
8176
8533
  var v1 = require('./v1');
8177
8534
  var v4 = require('./v4');
8178
8535
 
@@ -8182,7 +8539,7 @@ uuid.v4 = v4;
8182
8539
 
8183
8540
  module.exports = uuid;
8184
8541
 
8185
- },{"./v1":31,"./v4":32}],29:[function(require,module,exports){
8542
+ },{"./v1":33,"./v4":34}],31:[function(require,module,exports){
8186
8543
  /**
8187
8544
  * Convert array of 16 byte values to UUID string format of the form:
8188
8545
  * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
@@ -8207,7 +8564,7 @@ function bytesToUuid(buf, offset) {
8207
8564
 
8208
8565
  module.exports = bytesToUuid;
8209
8566
 
8210
- },{}],30:[function(require,module,exports){
8567
+ },{}],32:[function(require,module,exports){
8211
8568
  (function (global){
8212
8569
  // Unique ID creation requires a high quality random # generator. In the
8213
8570
  // browser this is a little complicated due to unknown quality of Math.random()
@@ -8244,7 +8601,7 @@ if (!rng) {
8244
8601
  module.exports = rng;
8245
8602
 
8246
8603
  }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
8247
- },{}],31:[function(require,module,exports){
8604
+ },{}],33:[function(require,module,exports){
8248
8605
  var rng = require('./lib/rng');
8249
8606
  var bytesToUuid = require('./lib/bytesToUuid');
8250
8607
 
@@ -8346,7 +8703,7 @@ function v1(options, buf, offset) {
8346
8703
 
8347
8704
  module.exports = v1;
8348
8705
 
8349
- },{"./lib/bytesToUuid":29,"./lib/rng":30}],32:[function(require,module,exports){
8706
+ },{"./lib/bytesToUuid":31,"./lib/rng":32}],34:[function(require,module,exports){
8350
8707
  var rng = require('./lib/rng');
8351
8708
  var bytesToUuid = require('./lib/bytesToUuid');
8352
8709
 
@@ -8377,7 +8734,7 @@ function v4(options, buf, offset) {
8377
8734
 
8378
8735
  module.exports = v4;
8379
8736
 
8380
- },{"./lib/bytesToUuid":29,"./lib/rng":30}],33:[function(require,module,exports){
8737
+ },{"./lib/bytesToUuid":31,"./lib/rng":32}],35:[function(require,module,exports){
8381
8738
  const Day = require('@barchart/common-js/lang/Day'),
8382
8739
  Decimal = require('@barchart/common-js/lang/Decimal');
8383
8740
 
@@ -8548,7 +8905,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
8548
8905
  });
8549
8906
  });
8550
8907
 
8551
- describe('and yearly position summary ranges are processed for a transaction set closed in 2016, but has after-the-face superfluous valuations in 2017 and 2018', () => {
8908
+ describe('and yearly position summary ranges are processed for a transaction set closed in 2016, but has after-the-fact superfluous valuations in 2017 and 2018', () => {
8552
8909
  let ranges;
8553
8910
 
8554
8911
  beforeEach(() => {
@@ -8734,7 +9091,60 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
8734
9091
  });
8735
9092
  });
8736
9093
 
8737
- },{"./../../../lib/data/PositionSummaryFrame":2,"./../../../lib/data/TransactionType":3,"@barchart/common-js/lang/Day":16,"@barchart/common-js/lang/Decimal":17}],34:[function(require,module,exports){
9094
+ },{"./../../../lib/data/PositionSummaryFrame":3,"./../../../lib/data/TransactionType":4,"@barchart/common-js/lang/Day":18,"@barchart/common-js/lang/Decimal":19}],36:[function(require,module,exports){
9095
+ const Day = require('@barchart/common-js/lang/Day');
9096
+
9097
+ const TransactionValidator = require('./../../../lib/data/TransactionValidator');
9098
+
9099
+ describe('When validating transaction order', () => {
9100
+ 'use strict';
9101
+
9102
+ const build = (sequence, day) => {
9103
+ return { sequence: sequence, date: Day.parse(day) };
9104
+ };
9105
+
9106
+ it('An array of zero transactions should be valid', () => {
9107
+ expect(TransactionValidator.validateOrder([])).toEqual(true);
9108
+ });
9109
+
9110
+ it('An array of transactions with ordered sequences, on the same day should be valid', () => {
9111
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
9112
+ });
9113
+
9114
+ it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
9115
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02') ])).toEqual(true);
9116
+ });
9117
+
9118
+ it('An array of transactions with ordered sequences (starting after one), on the same day should not be valid', () => {
9119
+ expect(TransactionValidator.validateOrder([ build(3, '2018-04-30'), build(4, '2018-04-30'), build(5, '2018-04-30') ])).toEqual(false);
9120
+ });
9121
+
9122
+ it('An array of transactions with duplicate sequences, on the same day should not be valid', () => {
9123
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(1, '2018-04-30') ])).toEqual(false);
9124
+ });
9125
+
9126
+ it('An array of transactions with with a gap in sequences, on the same day should not be valid', () => {
9127
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(false);
9128
+ });
9129
+
9130
+ it('An array of transactions with with a reversed sequences, on the same subsequent days should not be valid', () => {
9131
+ expect(TransactionValidator.validateOrder([ build(2, '2018-04-30'), build(1, '2018-05-01') ])).toEqual(false);
9132
+ });
9133
+
9134
+ it('An array of transactions with ordered sequences, on the reversed days should not be valid', () => {
9135
+ expect(TransactionValidator.validateOrder([ build(1, '2018-05-02'), build(2, '2018-05-01'), build(3, '2018-04-30') ])).toEqual(false);
9136
+ });
9137
+
9138
+ it('A partial array of transactions with ordered sequences (starting after one), on the same day should be valid', () => {
9139
+ expect(TransactionValidator.validateOrder([ build(3, '2018-04-30'), build(4, '2018-04-30'), build(5, '2018-04-30') ], true)).toEqual(true);
9140
+ });
9141
+
9142
+ it('A partial array of transactions with gap in sequences (starting after one), on the same day should be not valid', () => {
9143
+ expect(TransactionValidator.validateOrder([ build(3, '2018-04-30'), build(5, '2018-04-30'), build(6, '2018-04-30') ], true)).toEqual(false);
9144
+ });
9145
+ });
9146
+
9147
+ },{"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":18}],37:[function(require,module,exports){
8738
9148
  const Currency = require('@barchart/common-js/lang/Currency'),
8739
9149
  Decimal = require('@barchart/common-js/lang/Decimal');
8740
9150
 
@@ -8844,4 +9254,4 @@ describe('When a position container data is gathered', () => {
8844
9254
  });
8845
9255
  });
8846
9256
 
8847
- },{"./../../../lib/data/InstrumentType":1,"./../../../lib/processing/PositionContainer":4,"./../../../lib/processing/definitions/PositionLevelDefinition":7,"./../../../lib/processing/definitions/PositionLevelType":8,"./../../../lib/processing/definitions/PositionTreeDefinition":9,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17}]},{},[33,34]);
9257
+ },{"./../../../lib/data/InstrumentType":1,"./../../../lib/processing/PositionContainer":6,"./../../../lib/processing/definitions/PositionLevelDefinition":9,"./../../../lib/processing/definitions/PositionLevelType":10,"./../../../lib/processing/definitions/PositionTreeDefinition":11,"@barchart/common-js/lang/Currency":17,"@barchart/common-js/lang/Decimal":19}]},{},[35,36,37]);
@@ -168,7 +168,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
168
168
  });
169
169
  });
170
170
 
171
- describe('and yearly position summary ranges are processed for a transaction set closed in 2016, but has after-the-face superfluous valuations in 2017 and 2018', () => {
171
+ describe('and yearly position summary ranges are processed for a transaction set closed in 2016, but has after-the-fact superfluous valuations in 2017 and 2018', () => {
172
172
  let ranges;
173
173
 
174
174
  beforeEach(() => {
@@ -0,0 +1,51 @@
1
+ const Day = require('@barchart/common-js/lang/Day');
2
+
3
+ const TransactionValidator = require('./../../../lib/data/TransactionValidator');
4
+
5
+ describe('When validating transaction order', () => {
6
+ 'use strict';
7
+
8
+ const build = (sequence, day) => {
9
+ return { sequence: sequence, date: Day.parse(day) };
10
+ };
11
+
12
+ it('An array of zero transactions should be valid', () => {
13
+ expect(TransactionValidator.validateOrder([])).toEqual(true);
14
+ });
15
+
16
+ it('An array of transactions with ordered sequences, on the same day should be valid', () => {
17
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
18
+ });
19
+
20
+ it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
21
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02') ])).toEqual(true);
22
+ });
23
+
24
+ it('An array of transactions with ordered sequences (starting after one), on the same day should not be valid', () => {
25
+ expect(TransactionValidator.validateOrder([ build(3, '2018-04-30'), build(4, '2018-04-30'), build(5, '2018-04-30') ])).toEqual(false);
26
+ });
27
+
28
+ it('An array of transactions with duplicate sequences, on the same day should not be valid', () => {
29
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(1, '2018-04-30') ])).toEqual(false);
30
+ });
31
+
32
+ it('An array of transactions with with a gap in sequences, on the same day should not be valid', () => {
33
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(false);
34
+ });
35
+
36
+ it('An array of transactions with with a reversed sequences, on the same subsequent days should not be valid', () => {
37
+ expect(TransactionValidator.validateOrder([ build(2, '2018-04-30'), build(1, '2018-05-01') ])).toEqual(false);
38
+ });
39
+
40
+ it('An array of transactions with ordered sequences, on the reversed days should not be valid', () => {
41
+ expect(TransactionValidator.validateOrder([ build(1, '2018-05-02'), build(2, '2018-05-01'), build(3, '2018-04-30') ])).toEqual(false);
42
+ });
43
+
44
+ it('A partial array of transactions with ordered sequences (starting after one), on the same day should be valid', () => {
45
+ expect(TransactionValidator.validateOrder([ build(3, '2018-04-30'), build(4, '2018-04-30'), build(5, '2018-04-30') ], true)).toEqual(true);
46
+ });
47
+
48
+ it('A partial array of transactions with gap in sequences (starting after one), on the same day should be not valid', () => {
49
+ expect(TransactionValidator.validateOrder([ build(3, '2018-04-30'), build(5, '2018-04-30'), build(6, '2018-04-30') ], true)).toEqual(false);
50
+ });
51
+ });