@barchart/portfolio-api-common 1.2.126 → 1.2.127
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 =
|
|
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();
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -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 =
|
|
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();
|
|
@@ -17911,13 +17917,35 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17911
17917
|
});
|
|
17912
17918
|
});
|
|
17913
17919
|
|
|
17920
|
+
describe('and yearly position summary ranges are processed for a transaction set that opens in the current year', () => {
|
|
17921
|
+
let ranges;
|
|
17922
|
+
|
|
17923
|
+
beforeEach(() => {
|
|
17924
|
+
const transactions = [
|
|
17925
|
+
{
|
|
17926
|
+
date: Day.getToday(),
|
|
17927
|
+
snapshot: {
|
|
17928
|
+
open: new Decimal(1)
|
|
17929
|
+
},
|
|
17930
|
+
type: TransactionType.BUY
|
|
17931
|
+
}
|
|
17932
|
+
];
|
|
17933
|
+
|
|
17934
|
+
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
17935
|
+
});
|
|
17936
|
+
|
|
17937
|
+
it('should have zero ranges', () => {
|
|
17938
|
+
expect(ranges.length).toEqual(0);
|
|
17939
|
+
});
|
|
17940
|
+
});
|
|
17941
|
+
|
|
17914
17942
|
describe('and monthly position summary ranges are processed for a transaction set that does not close', () => {
|
|
17915
17943
|
let ranges;
|
|
17916
17944
|
|
|
17917
17945
|
beforeEach(() => {
|
|
17918
17946
|
const transactions = [
|
|
17919
17947
|
{
|
|
17920
|
-
date: new Day(
|
|
17948
|
+
date: new Day(2018, 12, 20),
|
|
17921
17949
|
snapshot: {
|
|
17922
17950
|
open: new Decimal(1)
|
|
17923
17951
|
},
|
|
@@ -17939,16 +17967,16 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17939
17967
|
expect(ranges.length > 1).toEqual(true);
|
|
17940
17968
|
});
|
|
17941
17969
|
|
|
17942
|
-
it('the first range should be from
|
|
17943
|
-
expect(ranges[0].start.format()).toEqual('2018-
|
|
17944
|
-
expect(ranges[0].end.format()).toEqual('
|
|
17970
|
+
it('the first range should be from 11-30-2018 to 12-31-2018', () => {
|
|
17971
|
+
expect(ranges[0].start.format()).toEqual('2018-11-30');
|
|
17972
|
+
expect(ranges[0].end.format()).toEqual('2018-12-31');
|
|
17945
17973
|
});
|
|
17946
17974
|
|
|
17947
|
-
it('the last range should be for the
|
|
17975
|
+
it('the last range should be for the previous month', () => {
|
|
17948
17976
|
const today = Day.getToday();
|
|
17949
17977
|
|
|
17950
|
-
expect(ranges[ranges.length - 1].start.format()).toEqual(today.
|
|
17951
|
-
expect(ranges[ranges.length - 1].end.format()).toEqual(today.getEndOfMonth().format());
|
|
17978
|
+
expect(ranges[ranges.length - 1].start.format()).toEqual(today.subtractMonths(2).getEndOfMonth().format());
|
|
17979
|
+
expect(ranges[ranges.length - 1].end.format()).toEqual(today.subtractMonths(1).getEndOfMonth().format());
|
|
17952
17980
|
});
|
|
17953
17981
|
});
|
|
17954
17982
|
|
|
@@ -18025,6 +18053,28 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
18025
18053
|
});
|
|
18026
18054
|
});
|
|
18027
18055
|
|
|
18056
|
+
describe('and monthly position summary ranges are processed for a transaction set that opens in the current month', () => {
|
|
18057
|
+
let ranges;
|
|
18058
|
+
|
|
18059
|
+
beforeEach(() => {
|
|
18060
|
+
const transactions = [
|
|
18061
|
+
{
|
|
18062
|
+
date: Day.getToday(),
|
|
18063
|
+
snapshot: {
|
|
18064
|
+
open: new Decimal(1)
|
|
18065
|
+
},
|
|
18066
|
+
type: TransactionType.BUY
|
|
18067
|
+
}
|
|
18068
|
+
];
|
|
18069
|
+
|
|
18070
|
+
ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
|
|
18071
|
+
});
|
|
18072
|
+
|
|
18073
|
+
it('should have zero ranges', () => {
|
|
18074
|
+
expect(ranges.length).toEqual(0);
|
|
18075
|
+
});
|
|
18076
|
+
});
|
|
18077
|
+
|
|
18028
18078
|
describe('and a year-to-date position summary ranges are processed for a transaction set that closed in 2017', () => {
|
|
18029
18079
|
let ranges;
|
|
18030
18080
|
|
|
@@ -18545,12 +18595,10 @@ describe('When a position container data is gathered', () => {
|
|
|
18545
18595
|
});
|
|
18546
18596
|
|
|
18547
18597
|
},{"./../../../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
|
|
18549
|
-
Day = require('@barchart/common-js/lang/Day'),
|
|
18598
|
+
const Day = require('@barchart/common-js/lang/Day'),
|
|
18550
18599
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
18551
18600
|
|
|
18552
|
-
const
|
|
18553
|
-
TransactionType = require('./../../../lib/data/TransactionType');
|
|
18601
|
+
const TransactionType = require('./../../../lib/data/TransactionType');
|
|
18554
18602
|
|
|
18555
18603
|
const TransactionSchema = require('./../../../lib/serialization/TransactionSchema');
|
|
18556
18604
|
|
|
@@ -18613,4 +18661,4 @@ describe('When transactions are serialized', () => {
|
|
|
18613
18661
|
});
|
|
18614
18662
|
});
|
|
18615
18663
|
|
|
18616
|
-
},{"./../../../lib/data/
|
|
18664
|
+
},{"./../../../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(
|
|
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
|
|
258
|
-
expect(ranges[0].start.format()).toEqual('2018-
|
|
259
|
-
expect(ranges[0].end.format()).toEqual('
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
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
|
|