@barchart/portfolio-api-common 1.2.125 → 1.2.129

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.
@@ -243,27 +243,31 @@ module.exports = (() => {
243
243
  function getMonthlyRanges(transactions) {
244
244
  const ranges = [ ];
245
245
 
246
- if (!transactions.length) {
247
- return ranges;
248
- }
246
+ if (transactions.length !== 0) {
247
+ const today = Day.getToday();
249
248
 
250
- const first = array.first(transactions);
251
- const last = array.last(transactions);
249
+ const first = array.first(transactions);
250
+ const last = array.last(transactions);
252
251
 
253
- const firstDate = first.date;
252
+ const firstDate = first.date;
254
253
 
255
- let lastDate;
254
+ let lastDate;
256
255
 
257
- if (last.snapshot.open.getIsZero()) {
258
- lastDate = new Day(last.date.year, last.date.month, last.date.day).addMonths(1);
259
- } else {
260
- lastDate = Day.getToday();
261
- }
256
+ if (last.snapshot.open.getIsZero()) {
257
+ lastDate = last.date;
258
+ } else {
259
+ lastDate = today;
260
+ }
262
261
 
263
- lastDate = lastDate.getEndOfMonth();
262
+ if (today.month === lastDate.month && today.year === lastDate.year) {
263
+ lastDate = lastDate.subtractMonths(1);
264
+ }
265
+
266
+ lastDate = lastDate.getEndOfMonth();
264
267
 
265
- for (let end = firstDate.getEndOfMonth(); end.format() <= lastDate.format(); end = end.addMonths(1).getEndOfMonth()) {
266
- ranges.push(getRange(end.subtractMonths(1).getEndOfMonth(), end));
268
+ for (let end = firstDate.getEndOfMonth(); !end.getIsAfter(lastDate); end = end.addMonths(1).getEndOfMonth()) {
269
+ ranges.push(getRange(end.subtractMonths(1).getEndOfMonth(), end));
270
+ }
267
271
  }
268
272
 
269
273
  return ranges;
@@ -22,9 +22,10 @@ module.exports = (() => {
22
22
  * @param {Boolean} corporateAction
23
23
  * @param {Boolean} initial
24
24
  * @param {Boolean} significant
25
+ * @param {Boolean} system
25
26
  */
26
27
  class TransactionType extends Enum {
27
- constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
28
+ constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant, system) {
28
29
  super(code, description);
29
30
 
30
31
  assert.argumentIsRequired(display, 'display', String);
@@ -38,6 +39,7 @@ module.exports = (() => {
38
39
  assert.argumentIsRequired(corporateAction, 'corporateAction', Boolean);
39
40
  assert.argumentIsRequired(initial, 'initial', Boolean);
40
41
  assert.argumentIsRequired(significant, 'significant', Boolean);
42
+ assert.argumentIsRequired(system, 'system', Boolean);
41
43
 
42
44
  this._display = display;
43
45
  this._sequence = sequence;
@@ -50,6 +52,7 @@ module.exports = (() => {
50
52
  this._corporateAction = corporateAction;
51
53
  this._initial = initial;
52
54
  this._significant = significant;
55
+ this._system = system;
53
56
  }
54
57
 
55
58
  /**
@@ -176,6 +179,16 @@ module.exports = (() => {
176
179
  return this._significant;
177
180
  }
178
181
 
182
+ /**
183
+ * System transactions are generated automatically.
184
+ *
185
+ * @public
186
+ * @returns {Boolean}
187
+ */
188
+ get system() {
189
+ return this._system;
190
+ }
191
+
179
192
  /**
180
193
  * A purchase.
181
194
  *
@@ -401,29 +414,29 @@ module.exports = (() => {
401
414
  }
402
415
  }
403
416
 
404
- const buy = new TransactionType('B', 'Buy', 'Buy', 0, true, false, false, true, false, false, false, true, true);
405
- const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
406
- const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
407
- const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true);
408
- const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
409
- const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
410
- const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
411
- const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
412
- const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false);
413
- const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false);
414
- const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, false);
415
-
416
- const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false);
417
- const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false);
418
- const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', 1, false, false, false, true, false, false, true, false, false);
419
-
420
- const deposit = new TransactionType('D', 'Deposit', 'Deposit', 0, false, false, false, false, false, false, false, true, true);
421
- const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', 0, false, false, false, false, false, false, false, true, true);
422
- const debit = new TransactionType('DR', 'Debit', 'Debit', 0, false, false, false, false, false, false, false, true, true);
423
- const credit = new TransactionType('CR', 'Credit', 'Credit', 0, false, false, false, false, false, false, false, true, true);
424
-
425
- const valuation = new TransactionType('V', 'Valuation', 'Valuation', 0, false, false, false, false, false, false, false, false, false);
426
- const income = new TransactionType('I', 'Income', 'Income', 0, false, false, true, false, false, false, false, false, false);
417
+ const buy = new TransactionType('B', 'Buy', 'Buy', 0, true, false, false, true, false, false, false, true, true, false);
418
+ const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true, false);
419
+ const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true, false);
420
+ const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true, false);
421
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false, true);
422
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false, true);
423
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false, true);
424
+ const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false, true);
425
+ const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false, false);
426
+ const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false, false);
427
+ const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, false, true);
428
+
429
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false, true);
430
+ const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false, true);
431
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', 1, false, false, false, true, false, false, true, false, false, true);
432
+
433
+ const deposit = new TransactionType('D', 'Deposit', 'Deposit', 0, false, false, false, false, false, false, false, true, true, false);
434
+ const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', 0, false, false, false, false, false, false, false, true, true, false);
435
+ const debit = new TransactionType('DR', 'Debit', 'Debit', 0, false, false, false, false, false, false, false, true, true, true);
436
+ const credit = new TransactionType('CR', 'Credit', 'Credit', 0, false, false, false, false, false, false, false, true, true, true);
437
+
438
+ const valuation = new TransactionType('V', 'Valuation', 'Valuation', 0, false, false, false, false, false, false, false, false, false, false);
439
+ const income = new TransactionType('I', 'Income', 'Income', 0, false, false, true, false, false, false, false, false, false, false);
427
440
 
428
441
  return TransactionType;
429
442
  })();
@@ -125,6 +125,7 @@ module.exports = (() => {
125
125
  f.date = t.date;
126
126
  f.type = t.type.display;
127
127
  f.code = t.type.code;
128
+ f.system = t.type.system;
128
129
  f.sequence = t.sequence;
129
130
  f.position = t.position;
130
131
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.125",
3
+ "version": "1.2.129",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -634,27 +634,31 @@ module.exports = (() => {
634
634
  function getMonthlyRanges(transactions) {
635
635
  const ranges = [ ];
636
636
 
637
- if (!transactions.length) {
638
- return ranges;
639
- }
637
+ if (transactions.length !== 0) {
638
+ const today = Day.getToday();
640
639
 
641
- const first = array.first(transactions);
642
- const last = array.last(transactions);
640
+ const first = array.first(transactions);
641
+ const last = array.last(transactions);
643
642
 
644
- const firstDate = first.date;
643
+ const firstDate = first.date;
645
644
 
646
- let lastDate;
645
+ let lastDate;
647
646
 
648
- if (last.snapshot.open.getIsZero()) {
649
- lastDate = new Day(last.date.year, last.date.month, last.date.day).addMonths(1);
650
- } else {
651
- lastDate = Day.getToday();
652
- }
647
+ if (last.snapshot.open.getIsZero()) {
648
+ lastDate = last.date;
649
+ } else {
650
+ lastDate = today;
651
+ }
653
652
 
654
- lastDate = lastDate.getEndOfMonth();
653
+ if (today.month === lastDate.month && today.year === lastDate.year) {
654
+ lastDate = lastDate.subtractMonths(1);
655
+ }
656
+
657
+ lastDate = lastDate.getEndOfMonth();
655
658
 
656
- for (let end = firstDate.getEndOfMonth(); end.format() <= lastDate.format(); end = end.addMonths(1).getEndOfMonth()) {
657
- ranges.push(getRange(end.subtractMonths(1).getEndOfMonth(), end));
659
+ for (let end = firstDate.getEndOfMonth(); !end.getIsAfter(lastDate); end = end.addMonths(1).getEndOfMonth()) {
660
+ ranges.push(getRange(end.subtractMonths(1).getEndOfMonth(), end));
661
+ }
658
662
  }
659
663
 
660
664
  return ranges;
@@ -759,9 +763,10 @@ module.exports = (() => {
759
763
  * @param {Boolean} corporateAction
760
764
  * @param {Boolean} initial
761
765
  * @param {Boolean} significant
766
+ * @param {Boolean} system
762
767
  */
763
768
  class TransactionType extends Enum {
764
- constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
769
+ constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant, system) {
765
770
  super(code, description);
766
771
 
767
772
  assert.argumentIsRequired(display, 'display', String);
@@ -775,6 +780,7 @@ module.exports = (() => {
775
780
  assert.argumentIsRequired(corporateAction, 'corporateAction', Boolean);
776
781
  assert.argumentIsRequired(initial, 'initial', Boolean);
777
782
  assert.argumentIsRequired(significant, 'significant', Boolean);
783
+ assert.argumentIsRequired(system, 'system', Boolean);
778
784
 
779
785
  this._display = display;
780
786
  this._sequence = sequence;
@@ -787,6 +793,7 @@ module.exports = (() => {
787
793
  this._corporateAction = corporateAction;
788
794
  this._initial = initial;
789
795
  this._significant = significant;
796
+ this._system = system;
790
797
  }
791
798
 
792
799
  /**
@@ -913,6 +920,16 @@ module.exports = (() => {
913
920
  return this._significant;
914
921
  }
915
922
 
923
+ /**
924
+ * System transactions are generated automatically.
925
+ *
926
+ * @public
927
+ * @returns {Boolean}
928
+ */
929
+ get system() {
930
+ return this._system;
931
+ }
932
+
916
933
  /**
917
934
  * A purchase.
918
935
  *
@@ -1138,29 +1155,29 @@ module.exports = (() => {
1138
1155
  }
1139
1156
  }
1140
1157
 
1141
- const buy = new TransactionType('B', 'Buy', 'Buy', 0, true, false, false, true, false, false, false, true, true);
1142
- const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
1143
- const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
1144
- const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true);
1145
- const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
1146
- const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
1147
- const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
1148
- const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
1149
- const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false);
1150
- const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false);
1151
- const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, false);
1152
-
1153
- const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false);
1154
- const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false);
1155
- const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', 1, false, false, false, true, false, false, true, false, false);
1156
-
1157
- const deposit = new TransactionType('D', 'Deposit', 'Deposit', 0, false, false, false, false, false, false, false, true, true);
1158
- const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', 0, false, false, false, false, false, false, false, true, true);
1159
- const debit = new TransactionType('DR', 'Debit', 'Debit', 0, false, false, false, false, false, false, false, true, true);
1160
- const credit = new TransactionType('CR', 'Credit', 'Credit', 0, false, false, false, false, false, false, false, true, true);
1161
-
1162
- const valuation = new TransactionType('V', 'Valuation', 'Valuation', 0, false, false, false, false, false, false, false, false, false);
1163
- const income = new TransactionType('I', 'Income', 'Income', 0, false, false, true, false, false, false, false, false, false);
1158
+ const buy = new TransactionType('B', 'Buy', 'Buy', 0, true, false, false, true, false, false, false, true, true, false);
1159
+ const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true, false);
1160
+ const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true, false);
1161
+ const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true, false);
1162
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false, true);
1163
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false, true);
1164
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false, true);
1165
+ const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false, true);
1166
+ const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false, false);
1167
+ const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false, false);
1168
+ const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, false, true);
1169
+
1170
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false, true);
1171
+ const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false, true);
1172
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', 1, false, false, false, true, false, false, true, false, false, true);
1173
+
1174
+ const deposit = new TransactionType('D', 'Deposit', 'Deposit', 0, false, false, false, false, false, false, false, true, true, false);
1175
+ const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', 0, false, false, false, false, false, false, false, true, true, false);
1176
+ const debit = new TransactionType('DR', 'Debit', 'Debit', 0, false, false, false, false, false, false, false, true, true, true);
1177
+ const credit = new TransactionType('CR', 'Credit', 'Credit', 0, false, false, false, false, false, false, false, true, true, true);
1178
+
1179
+ const valuation = new TransactionType('V', 'Valuation', 'Valuation', 0, false, false, false, false, false, false, false, false, false, false);
1180
+ const income = new TransactionType('I', 'Income', 'Income', 0, false, false, true, false, false, false, false, false, false, false);
1164
1181
 
1165
1182
  return TransactionType;
1166
1183
  })();
@@ -17860,7 +17877,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
17860
17877
  });
17861
17878
  });
17862
17879
 
17863
- describe('and yearly position summary ranges are processed for a transaction set that opens in 2019 and closes in 2016, but has after-the-fact superfluous valuations in 2017 and 2018', () => {
17880
+ describe('and yearly position summary ranges are processed for a transaction set that opens in 2015 and closes in 2016, but has after-the-fact superfluous valuations in 2017 and 2018', () => {
17864
17881
  let ranges;
17865
17882
 
17866
17883
  beforeEach(() => {
@@ -17913,6 +17930,164 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
17913
17930
  });
17914
17931
  });
17915
17932
 
17933
+ describe('and yearly position summary ranges are processed for a transaction set that opens in the current year', () => {
17934
+ let ranges;
17935
+
17936
+ beforeEach(() => {
17937
+ const transactions = [
17938
+ {
17939
+ date: Day.getToday(),
17940
+ snapshot: {
17941
+ open: new Decimal(1)
17942
+ },
17943
+ type: TransactionType.BUY
17944
+ }
17945
+ ];
17946
+
17947
+ ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
17948
+ });
17949
+
17950
+ it('should have zero ranges', () => {
17951
+ expect(ranges.length).toEqual(0);
17952
+ });
17953
+ });
17954
+
17955
+ describe('and monthly position summary ranges are processed for a transaction set that does not close', () => {
17956
+ let ranges;
17957
+
17958
+ beforeEach(() => {
17959
+ const transactions = [
17960
+ {
17961
+ date: new Day(2018, 12, 20),
17962
+ snapshot: {
17963
+ open: new Decimal(1)
17964
+ },
17965
+ type: TransactionType.BUY
17966
+ },
17967
+ {
17968
+ date: new Day(2019, 2, 21),
17969
+ snapshot: {
17970
+ open: new Decimal(1)
17971
+ },
17972
+ type: TransactionType.BUY
17973
+ }
17974
+ ];
17975
+
17976
+ ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
17977
+ });
17978
+
17979
+ it('should have at least two ranges', () => {
17980
+ expect(ranges.length > 1).toEqual(true);
17981
+ });
17982
+
17983
+ it('the first range should be from 11-30-2018 to 12-31-2018', () => {
17984
+ expect(ranges[0].start.format()).toEqual('2018-11-30');
17985
+ expect(ranges[0].end.format()).toEqual('2018-12-31');
17986
+ });
17987
+
17988
+ it('the last range should be for the previous month', () => {
17989
+ const today = Day.getToday();
17990
+
17991
+ expect(ranges[ranges.length - 1].start.format()).toEqual(today.subtractMonths(2).getEndOfMonth().format());
17992
+ expect(ranges[ranges.length - 1].end.format()).toEqual(today.subtractMonths(1).getEndOfMonth().format());
17993
+ });
17994
+ });
17995
+
17996
+ describe('and monthly position summary ranges are processed for a transaction set closes the same month', () => {
17997
+ let ranges;
17998
+
17999
+ beforeEach(() => {
18000
+ const transactions = [
18001
+ {
18002
+ date: new Day(2018, 12, 1),
18003
+ snapshot: {
18004
+ open: new Decimal(1)
18005
+ },
18006
+ type: TransactionType.BUY
18007
+ },
18008
+ {
18009
+ date: new Day(2018, 12, 31),
18010
+ snapshot: {
18011
+ open: new Decimal(0)
18012
+ },
18013
+ type: TransactionType.SELL
18014
+ }
18015
+ ];
18016
+
18017
+ ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
18018
+ });
18019
+
18020
+ it('should have one range', () => {
18021
+ expect(ranges.length).toEqual(1);
18022
+ });
18023
+
18024
+ it('the first range should be from 11-30-2018 to 12-31-2018', () => {
18025
+ expect(ranges[0].start.format()).toEqual('2018-11-30');
18026
+ expect(ranges[0].end.format()).toEqual('2018-12-31');
18027
+ });
18028
+ });
18029
+
18030
+ describe('and monthly position summary ranges are processed for a transaction set closes the next month', () => {
18031
+ let ranges;
18032
+
18033
+ beforeEach(() => {
18034
+ const transactions = [
18035
+ {
18036
+ date: new Day(2015, 10, 20),
18037
+ snapshot: {
18038
+ open: new Decimal(1)
18039
+ },
18040
+ type: TransactionType.BUY
18041
+ },
18042
+ {
18043
+ date: new Day(2015, 11, 20),
18044
+ snapshot: {
18045
+ open: new Decimal(0)
18046
+ },
18047
+ type: TransactionType.SELL
18048
+ }
18049
+ ];
18050
+
18051
+ ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
18052
+ });
18053
+
18054
+ it('should have two ranges', () => {
18055
+ expect(ranges.length).toEqual(2);
18056
+ });
18057
+
18058
+ it('the first range should be from 09-30-2015 to 10-31-2015', () => {
18059
+ expect(ranges[0].start.format()).toEqual('2015-09-30');
18060
+ expect(ranges[0].end.format()).toEqual('2015-10-31');
18061
+ });
18062
+
18063
+ it('the second range should be from 10-31-2015 to 11-30-2015', () => {
18064
+ expect(ranges[1].start.format()).toEqual('2015-10-31');
18065
+ expect(ranges[1].end.format()).toEqual('2015-11-30');
18066
+ });
18067
+ });
18068
+
18069
+ describe('and monthly position summary ranges are processed for a transaction set that opens in the current month', () => {
18070
+ let ranges;
18071
+
18072
+ beforeEach(() => {
18073
+ const transactions = [
18074
+ {
18075
+ date: Day.getToday(),
18076
+ snapshot: {
18077
+ open: new Decimal(1)
18078
+ },
18079
+ type: TransactionType.BUY
18080
+ }
18081
+ ];
18082
+
18083
+ ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
18084
+ });
18085
+
18086
+ it('should have zero ranges', () => {
18087
+ expect(ranges.length).toEqual(0);
18088
+ });
18089
+ });
18090
+
17916
18091
  describe('and a year-to-date position summary ranges are processed for a transaction set that closed in 2017', () => {
17917
18092
  let ranges;
17918
18093
 
@@ -18433,12 +18608,10 @@ describe('When a position container data is gathered', () => {
18433
18608
  });
18434
18609
 
18435
18610
  },{"./../../../lib/data/InstrumentType":1,"./../../../lib/data/PositionSummaryFrame":3,"./../../../lib/processing/PositionContainer":6,"./../../../lib/processing/definitions/PositionLevelDefinition":9,"./../../../lib/processing/definitions/PositionLevelType":10,"./../../../lib/processing/definitions/PositionTreeDefinition":11,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Decimal":22}],55:[function(require,module,exports){
18436
- const Currency = require('@barchart/common-js/lang/Currency'),
18437
- Day = require('@barchart/common-js/lang/Day'),
18611
+ const Day = require('@barchart/common-js/lang/Day'),
18438
18612
  Decimal = require('@barchart/common-js/lang/Decimal');
18439
18613
 
18440
- const InstrumentType = require('./../../../lib/data/InstrumentType'),
18441
- TransactionType = require('./../../../lib/data/TransactionType');
18614
+ const TransactionType = require('./../../../lib/data/TransactionType');
18442
18615
 
18443
18616
  const TransactionSchema = require('./../../../lib/serialization/TransactionSchema');
18444
18617
 
@@ -18501,4 +18674,4 @@ describe('When transactions are serialized', () => {
18501
18674
  });
18502
18675
  });
18503
18676
 
18504
- },{"./../../../lib/data/InstrumentType":1,"./../../../lib/data/TransactionType":4,"./../../../lib/serialization/TransactionSchema":12,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22}]},{},[52,53,54,55]);
18677
+ },{"./../../../lib/data/TransactionType":4,"./../../../lib/serialization/TransactionSchema":12,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22}]},{},[52,53,54,55]);
@@ -173,7 +173,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
173
173
  });
174
174
  });
175
175
 
176
- describe('and yearly position summary ranges are processed for a transaction set that opens in 2019 and closes in 2016, but has after-the-fact superfluous valuations in 2017 and 2018', () => {
176
+ describe('and yearly position summary ranges are processed for a transaction set that opens in 2015 and closes in 2016, but has after-the-fact superfluous valuations in 2017 and 2018', () => {
177
177
  let ranges;
178
178
 
179
179
  beforeEach(() => {
@@ -226,6 +226,164 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
226
226
  });
227
227
  });
228
228
 
229
+ describe('and yearly position summary ranges are processed for a transaction set that opens in the current year', () => {
230
+ let ranges;
231
+
232
+ beforeEach(() => {
233
+ const transactions = [
234
+ {
235
+ date: Day.getToday(),
236
+ snapshot: {
237
+ open: new Decimal(1)
238
+ },
239
+ type: TransactionType.BUY
240
+ }
241
+ ];
242
+
243
+ ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
244
+ });
245
+
246
+ it('should have zero ranges', () => {
247
+ expect(ranges.length).toEqual(0);
248
+ });
249
+ });
250
+
251
+ describe('and monthly position summary ranges are processed for a transaction set that does not close', () => {
252
+ let ranges;
253
+
254
+ beforeEach(() => {
255
+ const transactions = [
256
+ {
257
+ date: new Day(2018, 12, 20),
258
+ snapshot: {
259
+ open: new Decimal(1)
260
+ },
261
+ type: TransactionType.BUY
262
+ },
263
+ {
264
+ date: new Day(2019, 2, 21),
265
+ snapshot: {
266
+ open: new Decimal(1)
267
+ },
268
+ type: TransactionType.BUY
269
+ }
270
+ ];
271
+
272
+ ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
273
+ });
274
+
275
+ it('should have at least two ranges', () => {
276
+ expect(ranges.length > 1).toEqual(true);
277
+ });
278
+
279
+ it('the first range should be from 11-30-2018 to 12-31-2018', () => {
280
+ expect(ranges[0].start.format()).toEqual('2018-11-30');
281
+ expect(ranges[0].end.format()).toEqual('2018-12-31');
282
+ });
283
+
284
+ it('the last range should be for the previous month', () => {
285
+ const today = Day.getToday();
286
+
287
+ expect(ranges[ranges.length - 1].start.format()).toEqual(today.subtractMonths(2).getEndOfMonth().format());
288
+ expect(ranges[ranges.length - 1].end.format()).toEqual(today.subtractMonths(1).getEndOfMonth().format());
289
+ });
290
+ });
291
+
292
+ describe('and monthly position summary ranges are processed for a transaction set closes the same month', () => {
293
+ let ranges;
294
+
295
+ beforeEach(() => {
296
+ const transactions = [
297
+ {
298
+ date: new Day(2018, 12, 1),
299
+ snapshot: {
300
+ open: new Decimal(1)
301
+ },
302
+ type: TransactionType.BUY
303
+ },
304
+ {
305
+ date: new Day(2018, 12, 31),
306
+ snapshot: {
307
+ open: new Decimal(0)
308
+ },
309
+ type: TransactionType.SELL
310
+ }
311
+ ];
312
+
313
+ ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
314
+ });
315
+
316
+ it('should have one range', () => {
317
+ expect(ranges.length).toEqual(1);
318
+ });
319
+
320
+ it('the first range should be from 11-30-2018 to 12-31-2018', () => {
321
+ expect(ranges[0].start.format()).toEqual('2018-11-30');
322
+ expect(ranges[0].end.format()).toEqual('2018-12-31');
323
+ });
324
+ });
325
+
326
+ describe('and monthly position summary ranges are processed for a transaction set closes the next month', () => {
327
+ let ranges;
328
+
329
+ beforeEach(() => {
330
+ const transactions = [
331
+ {
332
+ date: new Day(2015, 10, 20),
333
+ snapshot: {
334
+ open: new Decimal(1)
335
+ },
336
+ type: TransactionType.BUY
337
+ },
338
+ {
339
+ date: new Day(2015, 11, 20),
340
+ snapshot: {
341
+ open: new Decimal(0)
342
+ },
343
+ type: TransactionType.SELL
344
+ }
345
+ ];
346
+
347
+ ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
348
+ });
349
+
350
+ it('should have two ranges', () => {
351
+ expect(ranges.length).toEqual(2);
352
+ });
353
+
354
+ it('the first range should be from 09-30-2015 to 10-31-2015', () => {
355
+ expect(ranges[0].start.format()).toEqual('2015-09-30');
356
+ expect(ranges[0].end.format()).toEqual('2015-10-31');
357
+ });
358
+
359
+ it('the second range should be from 10-31-2015 to 11-30-2015', () => {
360
+ expect(ranges[1].start.format()).toEqual('2015-10-31');
361
+ expect(ranges[1].end.format()).toEqual('2015-11-30');
362
+ });
363
+ });
364
+
365
+ describe('and monthly position summary ranges are processed for a transaction set that opens in the current month', () => {
366
+ let ranges;
367
+
368
+ beforeEach(() => {
369
+ const transactions = [
370
+ {
371
+ date: Day.getToday(),
372
+ snapshot: {
373
+ open: new Decimal(1)
374
+ },
375
+ type: TransactionType.BUY
376
+ }
377
+ ];
378
+
379
+ ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
380
+ });
381
+
382
+ it('should have zero ranges', () => {
383
+ expect(ranges.length).toEqual(0);
384
+ });
385
+ });
386
+
229
387
  describe('and a year-to-date position summary ranges are processed for a transaction set that closed in 2017', () => {
230
388
  let ranges;
231
389
 
@@ -1,9 +1,7 @@
1
- const Currency = require('@barchart/common-js/lang/Currency'),
2
- Day = require('@barchart/common-js/lang/Day'),
1
+ const Day = require('@barchart/common-js/lang/Day'),
3
2
  Decimal = require('@barchart/common-js/lang/Decimal');
4
3
 
5
- const InstrumentType = require('./../../../lib/data/InstrumentType'),
6
- TransactionType = require('./../../../lib/data/TransactionType');
4
+ const TransactionType = require('./../../../lib/data/TransactionType');
7
5
 
8
6
  const TransactionSchema = require('./../../../lib/serialization/TransactionSchema');
9
7