@barchart/portfolio-api-common 1.2.126 → 1.2.130

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.
@@ -244,6 +244,8 @@ module.exports = (() => {
244
244
  const ranges = [ ];
245
245
 
246
246
  if (transactions.length !== 0) {
247
+ const today = Day.getToday();
248
+
247
249
  const first = array.first(transactions);
248
250
  const last = array.last(transactions);
249
251
 
@@ -254,7 +256,11 @@ module.exports = (() => {
254
256
  if (last.snapshot.open.getIsZero()) {
255
257
  lastDate = last.date;
256
258
  } else {
257
- lastDate = Day.getToday();
259
+ lastDate = today;
260
+ }
261
+
262
+ if (today.month === lastDate.month && today.year === lastDate.year) {
263
+ lastDate = lastDate.subtractMonths(1);
258
264
  }
259
265
 
260
266
  lastDate = lastDate.getEndOfMonth();
@@ -22,6 +22,7 @@ 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
28
  constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.126",
3
+ "version": "1.2.130",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -635,6 +635,8 @@ module.exports = (() => {
635
635
  const ranges = [ ];
636
636
 
637
637
  if (transactions.length !== 0) {
638
+ const today = Day.getToday();
639
+
638
640
  const first = array.first(transactions);
639
641
  const last = array.last(transactions);
640
642
 
@@ -645,7 +647,11 @@ module.exports = (() => {
645
647
  if (last.snapshot.open.getIsZero()) {
646
648
  lastDate = last.date;
647
649
  } else {
648
- lastDate = Day.getToday();
650
+ lastDate = today;
651
+ }
652
+
653
+ if (today.month === lastDate.month && today.year === lastDate.year) {
654
+ lastDate = lastDate.subtractMonths(1);
649
655
  }
650
656
 
651
657
  lastDate = lastDate.getEndOfMonth();
@@ -757,6 +763,7 @@ module.exports = (() => {
757
763
  * @param {Boolean} corporateAction
758
764
  * @param {Boolean} initial
759
765
  * @param {Boolean} significant
766
+ * @param {Boolean} system
760
767
  */
761
768
  class TransactionType extends Enum {
762
769
  constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
@@ -17911,13 +17918,35 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
17911
17918
  });
17912
17919
  });
17913
17920
 
17921
+ describe('and yearly position summary ranges are processed for a transaction set that opens in the current year', () => {
17922
+ let ranges;
17923
+
17924
+ beforeEach(() => {
17925
+ const transactions = [
17926
+ {
17927
+ date: Day.getToday(),
17928
+ snapshot: {
17929
+ open: new Decimal(1)
17930
+ },
17931
+ type: TransactionType.BUY
17932
+ }
17933
+ ];
17934
+
17935
+ ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
17936
+ });
17937
+
17938
+ it('should have zero ranges', () => {
17939
+ expect(ranges.length).toEqual(0);
17940
+ });
17941
+ });
17942
+
17914
17943
  describe('and monthly position summary ranges are processed for a transaction set that does not close', () => {
17915
17944
  let ranges;
17916
17945
 
17917
17946
  beforeEach(() => {
17918
17947
  const transactions = [
17919
17948
  {
17920
- date: new Day(2019, 1, 20),
17949
+ date: new Day(2018, 12, 20),
17921
17950
  snapshot: {
17922
17951
  open: new Decimal(1)
17923
17952
  },
@@ -17939,16 +17968,16 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
17939
17968
  expect(ranges.length > 1).toEqual(true);
17940
17969
  });
17941
17970
 
17942
- it('the first range should be from 12-31-2018 to 01-31-2019', () => {
17943
- expect(ranges[0].start.format()).toEqual('2018-12-31');
17944
- expect(ranges[0].end.format()).toEqual('2019-01-31');
17971
+ it('the first range should be from 11-30-2018 to 12-31-2018', () => {
17972
+ expect(ranges[0].start.format()).toEqual('2018-11-30');
17973
+ expect(ranges[0].end.format()).toEqual('2018-12-31');
17945
17974
  });
17946
17975
 
17947
- it('the last range should be for the current month', () => {
17976
+ it('the last range should be for the previous month', () => {
17948
17977
  const today = Day.getToday();
17949
17978
 
17950
- expect(ranges[ranges.length - 1].start.format()).toEqual(today.getEndOfMonth().subtractMonths(1).getEndOfMonth().format());
17951
- expect(ranges[ranges.length - 1].end.format()).toEqual(today.getEndOfMonth().format());
17979
+ expect(ranges[ranges.length - 1].start.format()).toEqual(today.subtractMonths(2).getEndOfMonth().format());
17980
+ expect(ranges[ranges.length - 1].end.format()).toEqual(today.subtractMonths(1).getEndOfMonth().format());
17952
17981
  });
17953
17982
  });
17954
17983
 
@@ -18025,6 +18054,28 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
18025
18054
  });
18026
18055
  });
18027
18056
 
18057
+ describe('and monthly position summary ranges are processed for a transaction set that opens in the current month', () => {
18058
+ let ranges;
18059
+
18060
+ beforeEach(() => {
18061
+ const transactions = [
18062
+ {
18063
+ date: Day.getToday(),
18064
+ snapshot: {
18065
+ open: new Decimal(1)
18066
+ },
18067
+ type: TransactionType.BUY
18068
+ }
18069
+ ];
18070
+
18071
+ ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
18072
+ });
18073
+
18074
+ it('should have zero ranges', () => {
18075
+ expect(ranges.length).toEqual(0);
18076
+ });
18077
+ });
18078
+
18028
18079
  describe('and a year-to-date position summary ranges are processed for a transaction set that closed in 2017', () => {
18029
18080
  let ranges;
18030
18081
 
@@ -18545,12 +18596,10 @@ describe('When a position container data is gathered', () => {
18545
18596
  });
18546
18597
 
18547
18598
  },{"./../../../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){
18548
- const Currency = require('@barchart/common-js/lang/Currency'),
18549
- Day = require('@barchart/common-js/lang/Day'),
18599
+ const Day = require('@barchart/common-js/lang/Day'),
18550
18600
  Decimal = require('@barchart/common-js/lang/Decimal');
18551
18601
 
18552
- const InstrumentType = require('./../../../lib/data/InstrumentType'),
18553
- TransactionType = require('./../../../lib/data/TransactionType');
18602
+ const TransactionType = require('./../../../lib/data/TransactionType');
18554
18603
 
18555
18604
  const TransactionSchema = require('./../../../lib/serialization/TransactionSchema');
18556
18605
 
@@ -18613,4 +18662,4 @@ describe('When transactions are serialized', () => {
18613
18662
  });
18614
18663
  });
18615
18664
 
18616
- },{"./../../../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]);
18665
+ },{"./../../../lib/data/TransactionType":4,"./../../../lib/serialization/TransactionSchema":12,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22}]},{},[52,53,54,55]);
@@ -226,13 +226,35 @@ 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
+
229
251
  describe('and monthly position summary ranges are processed for a transaction set that does not close', () => {
230
252
  let ranges;
231
253
 
232
254
  beforeEach(() => {
233
255
  const transactions = [
234
256
  {
235
- date: new Day(2019, 1, 20),
257
+ date: new Day(2018, 12, 20),
236
258
  snapshot: {
237
259
  open: new Decimal(1)
238
260
  },
@@ -254,16 +276,16 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
254
276
  expect(ranges.length > 1).toEqual(true);
255
277
  });
256
278
 
257
- it('the first range should be from 12-31-2018 to 01-31-2019', () => {
258
- expect(ranges[0].start.format()).toEqual('2018-12-31');
259
- expect(ranges[0].end.format()).toEqual('2019-01-31');
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');
260
282
  });
261
283
 
262
- it('the last range should be for the current month', () => {
284
+ it('the last range should be for the previous month', () => {
263
285
  const today = Day.getToday();
264
286
 
265
- expect(ranges[ranges.length - 1].start.format()).toEqual(today.getEndOfMonth().subtractMonths(1).getEndOfMonth().format());
266
- expect(ranges[ranges.length - 1].end.format()).toEqual(today.getEndOfMonth().format());
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());
267
289
  });
268
290
  });
269
291
 
@@ -340,6 +362,28 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
340
362
  });
341
363
  });
342
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
+
343
387
  describe('and a year-to-date position summary ranges are processed for a transaction set that closed in 2017', () => {
344
388
  let ranges;
345
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