@barchart/portfolio-api-common 1.0.32 → 1.0.36

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.
@@ -28,7 +28,7 @@ module.exports = (() => {
28
28
  getRanges(transactions) {
29
29
  assert.argumentIsArray(transactions, 'transactions');
30
30
 
31
- return this._rangeCalculator(transactions);
31
+ return this._rangeCalculator(getFilteredTransactions(transactions));
32
32
  }
33
33
 
34
34
  /**
@@ -142,5 +142,15 @@ module.exports = (() => {
142
142
  return ranges;
143
143
  }
144
144
 
145
+ function getFilteredTransactions(transactions) {
146
+ return transactions.reduce((filtered, transaction) => {
147
+ if (!transaction.snapshot.open.getIsZero() || transaction.type.closing) {
148
+ filtered.push(transaction);
149
+ }
150
+
151
+ return filtered;
152
+ }, [ ]);
153
+ }
154
+
145
155
  return PositionSummaryFrame;
146
156
  })();
@@ -313,10 +313,10 @@ module.exports = (() => {
313
313
  const distributionCash = new TransactionType('DC', 'Distribution (Cash)', false, false, true, false, false);
314
314
  const distributionFund = new TransactionType('DF', 'Distribution (Units)', false, false, false, true, false);
315
315
 
316
- const deposit = new TransactionType('D', 'Deposit', false, false, false, false, false);
317
- const withdrawal = new TransactionType('W', 'Withdrawal', false, false, false, false, false);
318
- const debit = new TransactionType('DR', 'Debit', false, false, false, false, false);
319
- const credit = new TransactionType('CR', 'Credit', false, false, false, false, false);
316
+ const deposit = new TransactionType('D', 'Deposit', false, false, false, true, false);
317
+ const withdrawal = new TransactionType('W', 'Withdrawal', false, false, false, false, true);
318
+ const debit = new TransactionType('DR', 'Debit', false, false, false, false, true);
319
+ const credit = new TransactionType('CR', 'Credit', false, false, false, true, false);
320
320
 
321
321
  const valuation = new TransactionType('V', 'Valuation', false, false, false, false, false);
322
322
  const income = new TransactionType('I', 'Income', false, false, true, false, false);
@@ -6,14 +6,17 @@ const array = require('@barchart/common-js/lang/array'),
6
6
  module.exports = (() => {
7
7
 
8
8
  /**
9
- * Formats Position Summary records into groups based on instrument type
9
+ * Static utilities for formatting position summary records (into groups based on
10
+ * instrument type)
10
11
  *
12
+ * @public
11
13
  */
12
14
  class PositionSummaryFormatter{
13
-
14
15
  /**
15
16
  * The formatter
16
17
  *
18
+ * @public
19
+ * @static
17
20
  * @param {Array} summaries
18
21
  * @returns {Object}
19
22
  */
@@ -67,5 +70,4 @@ module.exports = (() => {
67
70
  };
68
71
 
69
72
  return PositionSummaryFormatter;
70
-
71
73
  })();
@@ -57,6 +57,17 @@ module.exports = (() => {
57
57
  return client;
58
58
  }
59
59
 
60
+ /**
61
+ * Only returns identifiers and portfolio name.
62
+ *
63
+ * @static
64
+ * @public
65
+ * @returns {PortfolioSchema}
66
+ */
67
+ static get NAME() {
68
+ return name;
69
+ }
70
+
60
71
  /**
61
72
  * Data required to create a portfolio.
62
73
  *
@@ -125,6 +136,13 @@ module.exports = (() => {
125
136
  .schema
126
137
  );
127
138
 
139
+ const name = new PortfolioSchema(SchemaBuilder.withName('name')
140
+ .withField('user', DataType.STRING)
141
+ .withField('portfolio', DataType.STRING)
142
+ .withField('name', DataType.STRING)
143
+ .schema
144
+ );
145
+
128
146
  const create = new PortfolioSchema(SchemaBuilder.withName('create')
129
147
  .withField('name', DataType.STRING)
130
148
  .withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
@@ -56,6 +56,15 @@ module.exports = (() => {
56
56
  return client;
57
57
  }
58
58
 
59
+ /**
60
+ * @static
61
+ * @public
62
+ * @returns {PositionSummarySchema}
63
+ */
64
+ static get DISPLAY() {
65
+ return display;
66
+ }
67
+
59
68
  toString() {
60
69
  return '[PositionSummarySchema]';
61
70
  }
@@ -123,5 +132,37 @@ module.exports = (() => {
123
132
  .schema
124
133
  );
125
134
 
135
+ const display = new PositionSummarySchema(SchemaBuilder.withName('display')
136
+ .withField('user', DataType.STRING)
137
+ .withField('portfolio', DataType.STRING)
138
+ .withField('position', DataType.STRING)
139
+ .withField('instrument.id', DataType.STRING)
140
+ .withField('instrument.name', DataType.STRING)
141
+ .withField('instrument.type', DataType.STRING)
142
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
143
+ .withField('instrument.delist', DataType.DAY, true)
144
+ .withField('instrument.symbol.barchart', DataType.STRING, true)
145
+ .withField('instrument.symbol.display', DataType.STRING, true)
146
+ .withField('frame', DataType.forEnum(PositionSummaryFrame, 'PositionSummaryFrame'))
147
+ .withField('start.date', DataType.DAY)
148
+ .withField('start.sequence', DataType.NUMBER)
149
+ .withField('start.open', DataType.DECIMAL)
150
+ .withField('start.basis', DataType.DECIMAL)
151
+ .withField('start.value', DataType.DECIMAL)
152
+ .withField('end.date', DataType.DAY)
153
+ .withField('end.sequence', DataType.NUMBER)
154
+ .withField('end.open', DataType.DECIMAL)
155
+ .withField('end.basis', DataType.DECIMAL)
156
+ .withField('end.value', DataType.DECIMAL)
157
+ .withField('period.buys', DataType.DECIMAL)
158
+ .withField('period.sells', DataType.DECIMAL)
159
+ .withField('period.income', DataType.DECIMAL)
160
+ .withField('period.realized', DataType.DECIMAL)
161
+ .withField('period.unrealized', DataType.DECIMAL)
162
+ .withField('additional.name', DataType.STRING)
163
+ .withField('additional.close', DataType.NUMBER)
164
+ .schema
165
+ );
166
+
126
167
  return PositionSummarySchema;
127
168
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.32",
3
+ "version": "1.0.36",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -29,7 +29,7 @@ module.exports = (() => {
29
29
  getRanges(transactions) {
30
30
  assert.argumentIsArray(transactions, 'transactions');
31
31
 
32
- return this._rangeCalculator(transactions);
32
+ return this._rangeCalculator(getFilteredTransactions(transactions));
33
33
  }
34
34
 
35
35
  /**
@@ -143,10 +143,347 @@ module.exports = (() => {
143
143
  return ranges;
144
144
  }
145
145
 
146
+ function getFilteredTransactions(transactions) {
147
+ return transactions.reduce((filtered, transaction) => {
148
+ if (!transaction.snapshot.open.getIsZero() || transaction.type.closing) {
149
+ filtered.push(transaction);
150
+ }
151
+
152
+ return filtered;
153
+ }, [ ]);
154
+ }
155
+
146
156
  return PositionSummaryFrame;
147
157
  })();
148
158
 
149
- },{"@barchart/common-js/lang/Day":4,"@barchart/common-js/lang/Enum":6,"@barchart/common-js/lang/array":7,"@barchart/common-js/lang/assert":8,"@barchart/common-js/lang/is":9}],2:[function(require,module,exports){
159
+ },{"@barchart/common-js/lang/Day":5,"@barchart/common-js/lang/Enum":7,"@barchart/common-js/lang/array":8,"@barchart/common-js/lang/assert":9,"@barchart/common-js/lang/is":10}],2:[function(require,module,exports){
160
+ const assert = require('@barchart/common-js/lang/assert'),
161
+ Enum = require('@barchart/common-js/lang/Enum');
162
+
163
+ module.exports = (() => {
164
+ 'use strict';
165
+
166
+ /**
167
+ * An enumeration item that describes a type of transaction.
168
+ *
169
+ * @public
170
+ * @extends {Enum}
171
+ * @param {String} code
172
+ * @param {String} description
173
+ * @param {Boolean} purchase
174
+ * @param {Boolean} sale
175
+ * @param {Boolean} income
176
+ * @param {Boolean} opening
177
+ * @param {Boolean} closing
178
+ */
179
+ class TransactionType extends Enum {
180
+ constructor(code, description, purchase, sale, income, opening, closing) {
181
+ super(code, description);
182
+
183
+ assert.argumentIsRequired(purchase, 'purchase', Boolean);
184
+ assert.argumentIsRequired(sale, 'sale', Boolean);
185
+ assert.argumentIsRequired(income, 'income', Boolean);
186
+ assert.argumentIsRequired(opening, 'opening', Boolean);
187
+ assert.argumentIsRequired(closing, 'closing', Boolean);
188
+
189
+ this._purchase = purchase;
190
+ this._sale = sale;
191
+ this._income = income;
192
+ this._opening = opening;
193
+ this._closing = closing;
194
+ }
195
+
196
+ /**
197
+ * Indicates if the transaction was a trade.
198
+ *
199
+ * @public
200
+ * @returns {Boolean}
201
+ */
202
+ get trade() {
203
+ return this._purchase || this._sale;
204
+ }
205
+
206
+ /**
207
+ * Indicates if the trade was a purchase.
208
+ *
209
+ * @public
210
+ * @returns {Boolean}
211
+ */
212
+ get purchase() {
213
+ return this._purchase;
214
+ }
215
+
216
+ /**
217
+ * Indicates if the trade was a sale.
218
+ *
219
+ * @public
220
+ * @returns {Boolean}
221
+ */
222
+ get sale() {
223
+ return this._sale;
224
+ }
225
+
226
+ /**
227
+ * Indicates if the transaction was an income payment.
228
+ *
229
+ * @public
230
+ * @returns {Boolean}
231
+ */
232
+ get income() {
233
+ return this._income;
234
+ }
235
+
236
+ /**
237
+ * Indicates if the transactions opens the position (i.e. increases its
238
+ * magnitude).
239
+ *
240
+ * @public
241
+ * @returns {Boolean}
242
+ */
243
+ get opening() {
244
+ return this._opening;
245
+ }
246
+
247
+ /**
248
+ * Indicates if the transactions closes the position (i.e. decreases its
249
+ * magnitude).
250
+ *
251
+ * @public
252
+ * @returns {Boolean}
253
+ */
254
+ get closing() {
255
+ return this._closing;
256
+ }
257
+
258
+ /**
259
+ * A purchase.
260
+ *
261
+ * @public
262
+ * @static
263
+ * @returns {TransactionType}
264
+ */
265
+ static get BUY() {
266
+ return buy;
267
+ }
268
+
269
+ /**
270
+ * A sale.
271
+ *
272
+ * @public
273
+ * @static
274
+ * @returns {TransactionType}
275
+ */
276
+ static get SELL() {
277
+ return sell;
278
+ }
279
+
280
+ /**
281
+ * A purchase (in a short position).
282
+ *
283
+ * @public
284
+ * @static
285
+ * @returns {TransactionType}
286
+ */
287
+ static get BUY_SHORT() {
288
+ return buyShort;
289
+ }
290
+
291
+ /**
292
+ * A short sale.
293
+ *
294
+ * @public
295
+ * @static
296
+ * @returns {TransactionType}
297
+ */
298
+ static get SELL_SHORT() {
299
+ return sellShort;
300
+ }
301
+
302
+ /**
303
+ * A cash dividend.
304
+ *
305
+ * @public
306
+ * @static
307
+ * @returns {TransactionType}
308
+ */
309
+ static get DIVIDEND() {
310
+ return dividend;
311
+ }
312
+
313
+ /**
314
+ * A cash dividend, reinvested.
315
+ *
316
+ * @public
317
+ * @static
318
+ * @returns {TransactionType}
319
+ */
320
+ static get DIVIDEND_REINVEST() {
321
+ return dividendReinvest;
322
+ }
323
+
324
+ /**
325
+ * A stock dividend.
326
+ *
327
+ * @public
328
+ * @static
329
+ * @returns {TransactionType}
330
+ */
331
+ static get DIVIDEND_STOCK() {
332
+ return dividendStock;
333
+ }
334
+
335
+ /**
336
+ * A mutual fund distribution in cash.
337
+ *
338
+ * @public
339
+ * @static
340
+ * @returns {TransactionType}
341
+ */
342
+ static get DISTRIBUTION_CASH() {
343
+ return distributionCash;
344
+ }
345
+
346
+ /**
347
+ * A mutual fund distribution in units.
348
+ *
349
+ * @public
350
+ * @static
351
+ * @returns {TransactionType}
352
+ */
353
+ static get DISTRIBUTION_FUND() {
354
+ return distributionFund;
355
+ }
356
+
357
+ /**
358
+ * A split.
359
+ *
360
+ * @public
361
+ * @static
362
+ * @returns {TransactionType}
363
+ */
364
+ static get SPLIT() {
365
+ return split;
366
+ }
367
+
368
+ /**
369
+ * A fee.
370
+ *
371
+ * @public
372
+ * @static
373
+ * @returns {TransactionType}
374
+ */
375
+ static get FEE() {
376
+ return fee;
377
+ }
378
+
379
+ /**
380
+ * A mutual fund fee, which is paid in units.
381
+ *
382
+ * @public
383
+ * @static
384
+ * @returns {TransactionType}
385
+ */
386
+ static get FEE_UNITS() {
387
+ return feeUnits;
388
+ }
389
+
390
+ /**
391
+ * A deposit.
392
+ *
393
+ * @public
394
+ * @static
395
+ * @returns {TransactionType}
396
+ */
397
+ static get DEPOSIT() {
398
+ return deposit;
399
+ }
400
+
401
+ /**
402
+ * A withdrawal.
403
+ *
404
+ * @public
405
+ * @static
406
+ * @returns {TransactionType}
407
+ */
408
+ static get WITHDRAWAL() {
409
+ return withdrawal;
410
+ }
411
+
412
+ /**
413
+ * A system-generated withdrawal, arising from another transaction.
414
+ *
415
+ * @public
416
+ * @static
417
+ * @returns {TransactionType}
418
+ */
419
+ static get DEBIT() {
420
+ return debit;
421
+ }
422
+
423
+ /**
424
+ * A system-generated deposit, arising from another transaction.
425
+ *
426
+ * @public
427
+ * @static
428
+ * @returns {TransactionType}
429
+ */
430
+ static get CREDIT() {
431
+ return credit;
432
+ }
433
+
434
+ /**
435
+ * A valuation event.
436
+ *
437
+ * @public
438
+ * @static
439
+ * @returns {TransactionType}
440
+ */
441
+ static get VALUATION() {
442
+ return valuation;
443
+ }
444
+
445
+ /**
446
+ * Other Income.
447
+ *
448
+ * @public
449
+ * @static
450
+ * @returns {TransactionType}
451
+ */
452
+ static get INCOME() {
453
+ return income;
454
+ }
455
+
456
+ toString() {
457
+ return '[TransactionType]';
458
+ }
459
+ }
460
+
461
+ const buy = new TransactionType('B', 'Buy', true, false, false, true, false);
462
+ const sell = new TransactionType('S', 'Sell', false, true, false, false, true);
463
+ const buyShort = new TransactionType('BS', 'Buy To Cover', true, false, false, false, true);
464
+ const sellShort = new TransactionType('SS', 'Sell Short', false, true, false, true, false);
465
+ const dividend = new TransactionType('DV', 'Dividend', false, false, true, false, false);
466
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', false, false, false, true, false);
467
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', false, false, false, true, false);
468
+ const split = new TransactionType('SP', 'Split', false, false, false, true, false);
469
+ const fee = new TransactionType('F', 'Fee', false, false, false, true, false);
470
+ const feeUnits = new TransactionType('FU', 'Fee', false, false, false, false, false);
471
+
472
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', false, false, true, false, false);
473
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', false, false, false, true, false);
474
+
475
+ const deposit = new TransactionType('D', 'Deposit', false, false, false, true, false);
476
+ const withdrawal = new TransactionType('W', 'Withdrawal', false, false, false, false, true);
477
+ const debit = new TransactionType('DR', 'Debit', false, false, false, false, true);
478
+ const credit = new TransactionType('CR', 'Credit', false, false, false, true, false);
479
+
480
+ const valuation = new TransactionType('V', 'Valuation', false, false, false, false, false);
481
+ const income = new TransactionType('I', 'Income', false, false, true, false, false);
482
+
483
+ return TransactionType;
484
+ })();
485
+
486
+ },{"@barchart/common-js/lang/Enum":7,"@barchart/common-js/lang/assert":9}],3:[function(require,module,exports){
150
487
  'use strict';
151
488
 
152
489
  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; }; }();
@@ -290,7 +627,7 @@ module.exports = function () {
290
627
  return ComparatorBuilder;
291
628
  }();
292
629
 
293
- },{"./../../lang/assert":8,"./comparators":3}],3:[function(require,module,exports){
630
+ },{"./../../lang/assert":9,"./comparators":4}],4:[function(require,module,exports){
294
631
  'use strict';
295
632
 
296
633
  var assert = require('./../../lang/assert');
@@ -365,7 +702,7 @@ module.exports = function () {
365
702
  };
366
703
  }();
367
704
 
368
- },{"./../../lang/assert":8}],4:[function(require,module,exports){
705
+ },{"./../../lang/assert":9}],5:[function(require,module,exports){
369
706
  'use strict';
370
707
 
371
708
  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; }; }();
@@ -918,7 +1255,7 @@ module.exports = function () {
918
1255
  return Day;
919
1256
  }();
920
1257
 
921
- },{"./../collections/sorting/ComparatorBuilder":2,"./../collections/sorting/comparators":3,"./assert":8,"./is":9}],5:[function(require,module,exports){
1258
+ },{"./../collections/sorting/ComparatorBuilder":3,"./../collections/sorting/comparators":4,"./assert":9,"./is":10}],6:[function(require,module,exports){
922
1259
  'use strict';
923
1260
 
924
1261
  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; }; }();
@@ -1498,7 +1835,7 @@ module.exports = function () {
1498
1835
  return Decimal;
1499
1836
  }();
1500
1837
 
1501
- },{"./Enum":6,"./assert":8,"./is":9,"big.js":10}],6:[function(require,module,exports){
1838
+ },{"./Enum":7,"./assert":9,"./is":10,"big.js":11}],7:[function(require,module,exports){
1502
1839
  'use strict';
1503
1840
 
1504
1841
  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; }; }();
@@ -1640,7 +1977,7 @@ module.exports = function () {
1640
1977
  return Enum;
1641
1978
  }();
1642
1979
 
1643
- },{"./assert":8}],7:[function(require,module,exports){
1980
+ },{"./assert":9}],8:[function(require,module,exports){
1644
1981
  'use strict';
1645
1982
 
1646
1983
  var assert = require('./assert'),
@@ -2001,7 +2338,7 @@ module.exports = function () {
2001
2338
  };
2002
2339
  }();
2003
2340
 
2004
- },{"./assert":8,"./is":9}],8:[function(require,module,exports){
2341
+ },{"./assert":9,"./is":10}],9:[function(require,module,exports){
2005
2342
  'use strict';
2006
2343
 
2007
2344
  var is = require('./is');
@@ -2149,7 +2486,7 @@ module.exports = function () {
2149
2486
  };
2150
2487
  }();
2151
2488
 
2152
- },{"./is":9}],9:[function(require,module,exports){
2489
+ },{"./is":10}],10:[function(require,module,exports){
2153
2490
  'use strict';
2154
2491
 
2155
2492
  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; };
@@ -2372,7 +2709,7 @@ module.exports = function () {
2372
2709
  };
2373
2710
  }();
2374
2711
 
2375
- },{}],10:[function(require,module,exports){
2712
+ },{}],11:[function(require,module,exports){
2376
2713
  /*
2377
2714
  * big.js v5.0.3
2378
2715
  * A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
@@ -3313,11 +3650,12 @@ module.exports = function () {
3313
3650
  }
3314
3651
  })(this);
3315
3652
 
3316
- },{}],11:[function(require,module,exports){
3653
+ },{}],12:[function(require,module,exports){
3317
3654
  const Day = require('@barchart/common-js/lang/Day'),
3318
3655
  Decimal = require('@barchart/common-js/lang/Decimal');
3319
3656
 
3320
- const PositionSummaryFrame = require('./../../../lib/data/PositionSummaryFrame');
3657
+ const PositionSummaryFrame = require('./../../../lib/data/PositionSummaryFrame'),
3658
+ TransactionType = require('./../../../lib/data/TransactionType');
3321
3659
 
3322
3660
  describe('After the PositionSummaryFrame enumeration is initialized', () => {
3323
3661
  'use strict';
@@ -3328,13 +3666,18 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
3328
3666
  beforeEach(() => {
3329
3667
  const transactions = [
3330
3668
  {
3331
- date: new Day(2015, 10, 20)
3669
+ date: new Day(2015, 10, 20),
3670
+ snapshot: {
3671
+ open: new Decimal(1)
3672
+ },
3673
+ type: TransactionType.BUY
3332
3674
  },
3333
3675
  {
3334
3676
  date: new Day(2016, 11, 21),
3335
3677
  snapshot: {
3336
3678
  open: new Decimal(1)
3337
- }
3679
+ },
3680
+ type: TransactionType.BUY
3338
3681
  }
3339
3682
  ];
3340
3683
 
@@ -3367,13 +3710,18 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
3367
3710
  beforeEach(() => {
3368
3711
  const transactions = [
3369
3712
  {
3370
- date: new Day(2015, 10, 20)
3713
+ date: new Day(2015, 10, 20),
3714
+ snapshot: {
3715
+ open: new Decimal(1)
3716
+ },
3717
+ type: TransactionType.BUY
3371
3718
  },
3372
3719
  {
3373
3720
  date: new Day(2015, 11, 21),
3374
3721
  snapshot: {
3375
3722
  open: new Decimal(0)
3376
- }
3723
+ },
3724
+ type: TransactionType.SELL
3377
3725
  }
3378
3726
  ];
3379
3727
 
@@ -3396,13 +3744,18 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
3396
3744
  beforeEach(() => {
3397
3745
  const transactions = [
3398
3746
  {
3399
- date: new Day(2015, 10, 20)
3747
+ date: new Day(2015, 10, 20),
3748
+ snapshot: {
3749
+ open: new Decimal(1)
3750
+ },
3751
+ type: TransactionType.BUY
3400
3752
  },
3401
3753
  {
3402
3754
  date: new Day(2016, 11, 21),
3403
3755
  snapshot: {
3404
3756
  open: new Decimal(0)
3405
- }
3757
+ },
3758
+ type: TransactionType.SELL
3406
3759
  }
3407
3760
  ];
3408
3761
 
@@ -3430,13 +3783,18 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
3430
3783
  beforeEach(() => {
3431
3784
  const transactions = [
3432
3785
  {
3433
- date: new Day(2015, 10, 20)
3786
+ date: new Day(2015, 10, 20),
3787
+ snapshot: {
3788
+ open: new Decimal(1)
3789
+ },
3790
+ type: TransactionType.BUY
3434
3791
  },
3435
3792
  {
3436
3793
  date: new Day(2017, 11, 21),
3437
3794
  snapshot: {
3438
3795
  open: new Decimal(0)
3439
- }
3796
+ },
3797
+ type: TransactionType.SELL
3440
3798
  }
3441
3799
  ];
3442
3800
 
@@ -3463,19 +3821,77 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
3463
3821
  });
3464
3822
  });
3465
3823
 
3824
+ 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', () => {
3825
+ let ranges;
3826
+
3827
+ beforeEach(() => {
3828
+ const transactions = [
3829
+ {
3830
+ date: new Day(2015, 10, 20),
3831
+ snapshot: {
3832
+ open: new Decimal(1)
3833
+ },
3834
+ type: TransactionType.BUY
3835
+ },
3836
+ {
3837
+ date: new Day(2016, 11, 21),
3838
+ snapshot: {
3839
+ open: new Decimal(0)
3840
+ },
3841
+ type: TransactionType.SELL
3842
+ },
3843
+ {
3844
+ date: new Day(2017, 11, 21),
3845
+ snapshot: {
3846
+ open: new Decimal(0)
3847
+ },
3848
+ type: TransactionType.VALUATION
3849
+ },
3850
+ {
3851
+ date: new Day(2017, 11, 21),
3852
+ snapshot: {
3853
+ open: new Decimal(0)
3854
+ },
3855
+ type: TransactionType.VALUATION
3856
+ }
3857
+ ];
3858
+
3859
+ ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
3860
+ });
3861
+
3862
+ it('should have two ranges', () => {
3863
+ expect(ranges.length).toEqual(2);
3864
+ });
3865
+
3866
+ it('the first range should be from 12-31-2014 to 12-31-2015', () => {
3867
+ expect(ranges[0].start.format()).toEqual('2014-12-31');
3868
+ expect(ranges[0].end.format()).toEqual('2015-12-31');
3869
+ });
3870
+
3871
+ it('the second range should be from 12-31-2015 to 12-31-2016', () => {
3872
+ expect(ranges[1].start.format()).toEqual('2015-12-31');
3873
+ expect(ranges[1].end.format()).toEqual('2016-12-31');
3874
+ });
3875
+ });
3876
+
3466
3877
  describe('and a year-to-date position summary ranges are processed for a transaction set that closed last year', () => {
3467
3878
  let ranges;
3468
3879
 
3469
3880
  beforeEach(() => {
3470
3881
  const transactions = [
3471
3882
  {
3472
- date: new Day(2017, 1, 1)
3883
+ date: new Day(2017, 1, 1),
3884
+ snapshot: {
3885
+ open: new Decimal(1)
3886
+ },
3887
+ type: TransactionType.BUY
3473
3888
  },
3474
3889
  {
3475
3890
  date: new Day(2017, 1, 2),
3476
3891
  snapshot: {
3477
3892
  open: new Decimal(0)
3478
- }
3893
+ },
3894
+ type: TransactionType.SELL
3479
3895
  }
3480
3896
  ];
3481
3897
 
@@ -3495,8 +3911,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
3495
3911
  {
3496
3912
  date: new Day(2018, 1, 1),
3497
3913
  snapshot: {
3498
- open: new Decimal(0)
3499
- }
3914
+ open: new Decimal(100)
3915
+ },
3916
+ type: TransactionType.BUY
3500
3917
  }
3501
3918
  ];
3502
3919
 
@@ -3519,13 +3936,18 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
3519
3936
  beforeEach(() => {
3520
3937
  const transactions = [
3521
3938
  {
3522
- date: new Day(2018, 1, 1)
3939
+ date: new Day(2018, 1, 1),
3940
+ snapshot: {
3941
+ open: new Decimal(1)
3942
+ },
3943
+ type: TransactionType.BUY
3523
3944
  },
3524
3945
  {
3525
3946
  date: new Day(2018, 1, 2),
3526
3947
  snapshot: {
3527
3948
  open: new Decimal(0)
3528
- }
3949
+ },
3950
+ type: TransactionType.SELL
3529
3951
  }
3530
3952
  ];
3531
3953
 
@@ -3543,4 +3965,4 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
3543
3965
  });
3544
3966
  });
3545
3967
 
3546
- },{"./../../../lib/data/PositionSummaryFrame":1,"@barchart/common-js/lang/Day":4,"@barchart/common-js/lang/Decimal":5}]},{},[11]);
3968
+ },{"./../../../lib/data/PositionSummaryFrame":1,"./../../../lib/data/TransactionType":2,"@barchart/common-js/lang/Day":5,"@barchart/common-js/lang/Decimal":6}]},{},[12]);
@@ -1,7 +1,8 @@
1
1
  const Day = require('@barchart/common-js/lang/Day'),
2
2
  Decimal = require('@barchart/common-js/lang/Decimal');
3
3
 
4
- const PositionSummaryFrame = require('./../../../lib/data/PositionSummaryFrame');
4
+ const PositionSummaryFrame = require('./../../../lib/data/PositionSummaryFrame'),
5
+ TransactionType = require('./../../../lib/data/TransactionType');
5
6
 
6
7
  describe('After the PositionSummaryFrame enumeration is initialized', () => {
7
8
  'use strict';
@@ -12,13 +13,18 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
12
13
  beforeEach(() => {
13
14
  const transactions = [
14
15
  {
15
- date: new Day(2015, 10, 20)
16
+ date: new Day(2015, 10, 20),
17
+ snapshot: {
18
+ open: new Decimal(1)
19
+ },
20
+ type: TransactionType.BUY
16
21
  },
17
22
  {
18
23
  date: new Day(2016, 11, 21),
19
24
  snapshot: {
20
25
  open: new Decimal(1)
21
- }
26
+ },
27
+ type: TransactionType.BUY
22
28
  }
23
29
  ];
24
30
 
@@ -51,13 +57,18 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
51
57
  beforeEach(() => {
52
58
  const transactions = [
53
59
  {
54
- date: new Day(2015, 10, 20)
60
+ date: new Day(2015, 10, 20),
61
+ snapshot: {
62
+ open: new Decimal(1)
63
+ },
64
+ type: TransactionType.BUY
55
65
  },
56
66
  {
57
67
  date: new Day(2015, 11, 21),
58
68
  snapshot: {
59
69
  open: new Decimal(0)
60
- }
70
+ },
71
+ type: TransactionType.SELL
61
72
  }
62
73
  ];
63
74
 
@@ -80,13 +91,18 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
80
91
  beforeEach(() => {
81
92
  const transactions = [
82
93
  {
83
- date: new Day(2015, 10, 20)
94
+ date: new Day(2015, 10, 20),
95
+ snapshot: {
96
+ open: new Decimal(1)
97
+ },
98
+ type: TransactionType.BUY
84
99
  },
85
100
  {
86
101
  date: new Day(2016, 11, 21),
87
102
  snapshot: {
88
103
  open: new Decimal(0)
89
- }
104
+ },
105
+ type: TransactionType.SELL
90
106
  }
91
107
  ];
92
108
 
@@ -114,13 +130,18 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
114
130
  beforeEach(() => {
115
131
  const transactions = [
116
132
  {
117
- date: new Day(2015, 10, 20)
133
+ date: new Day(2015, 10, 20),
134
+ snapshot: {
135
+ open: new Decimal(1)
136
+ },
137
+ type: TransactionType.BUY
118
138
  },
119
139
  {
120
140
  date: new Day(2017, 11, 21),
121
141
  snapshot: {
122
142
  open: new Decimal(0)
123
- }
143
+ },
144
+ type: TransactionType.SELL
124
145
  }
125
146
  ];
126
147
 
@@ -147,19 +168,77 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
147
168
  });
148
169
  });
149
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', () => {
172
+ let ranges;
173
+
174
+ beforeEach(() => {
175
+ const transactions = [
176
+ {
177
+ date: new Day(2015, 10, 20),
178
+ snapshot: {
179
+ open: new Decimal(1)
180
+ },
181
+ type: TransactionType.BUY
182
+ },
183
+ {
184
+ date: new Day(2016, 11, 21),
185
+ snapshot: {
186
+ open: new Decimal(0)
187
+ },
188
+ type: TransactionType.SELL
189
+ },
190
+ {
191
+ date: new Day(2017, 11, 21),
192
+ snapshot: {
193
+ open: new Decimal(0)
194
+ },
195
+ type: TransactionType.VALUATION
196
+ },
197
+ {
198
+ date: new Day(2017, 11, 21),
199
+ snapshot: {
200
+ open: new Decimal(0)
201
+ },
202
+ type: TransactionType.VALUATION
203
+ }
204
+ ];
205
+
206
+ ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
207
+ });
208
+
209
+ it('should have two ranges', () => {
210
+ expect(ranges.length).toEqual(2);
211
+ });
212
+
213
+ it('the first range should be from 12-31-2014 to 12-31-2015', () => {
214
+ expect(ranges[0].start.format()).toEqual('2014-12-31');
215
+ expect(ranges[0].end.format()).toEqual('2015-12-31');
216
+ });
217
+
218
+ it('the second range should be from 12-31-2015 to 12-31-2016', () => {
219
+ expect(ranges[1].start.format()).toEqual('2015-12-31');
220
+ expect(ranges[1].end.format()).toEqual('2016-12-31');
221
+ });
222
+ });
223
+
150
224
  describe('and a year-to-date position summary ranges are processed for a transaction set that closed last year', () => {
151
225
  let ranges;
152
226
 
153
227
  beforeEach(() => {
154
228
  const transactions = [
155
229
  {
156
- date: new Day(2017, 1, 1)
230
+ date: new Day(2017, 1, 1),
231
+ snapshot: {
232
+ open: new Decimal(1)
233
+ },
234
+ type: TransactionType.BUY
157
235
  },
158
236
  {
159
237
  date: new Day(2017, 1, 2),
160
238
  snapshot: {
161
239
  open: new Decimal(0)
162
- }
240
+ },
241
+ type: TransactionType.SELL
163
242
  }
164
243
  ];
165
244
 
@@ -179,8 +258,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
179
258
  {
180
259
  date: new Day(2018, 1, 1),
181
260
  snapshot: {
182
- open: new Decimal(0)
183
- }
261
+ open: new Decimal(100)
262
+ },
263
+ type: TransactionType.BUY
184
264
  }
185
265
  ];
186
266
 
@@ -203,13 +283,18 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
203
283
  beforeEach(() => {
204
284
  const transactions = [
205
285
  {
206
- date: new Day(2018, 1, 1)
286
+ date: new Day(2018, 1, 1),
287
+ snapshot: {
288
+ open: new Decimal(1)
289
+ },
290
+ type: TransactionType.BUY
207
291
  },
208
292
  {
209
293
  date: new Day(2018, 1, 2),
210
294
  snapshot: {
211
295
  open: new Decimal(0)
212
- }
296
+ },
297
+ type: TransactionType.SELL
213
298
  }
214
299
  ];
215
300