@barchart/portfolio-api-common 1.2.92 → 1.2.93
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.
|
@@ -94,22 +94,44 @@ module.exports = (() => {
|
|
|
94
94
|
* @return {Array.<PositionSummaryRange>}
|
|
95
95
|
*/
|
|
96
96
|
getRangesFromDate(date) {
|
|
97
|
+
assert.argumentIsRequired(date, 'date', Day, 'Day');
|
|
98
|
+
|
|
97
99
|
const transaction = { date: date, snapshot: { open: Decimal.ONE } };
|
|
98
100
|
|
|
99
101
|
return this.getRanges([ transaction ]);
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Returns the range immediately prior to the range containing the
|
|
106
|
+
* date supplied.
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
* @param {Day} date
|
|
110
|
+
* @param {Number} periods
|
|
111
|
+
*/
|
|
112
|
+
getPriorRanges(date, periods) {
|
|
113
|
+
assert.argumentIsRequired(date, 'date', Day, 'Day');
|
|
114
|
+
assert.argumentIsRequired(periods, 'periods', Number, 'Number');
|
|
115
|
+
|
|
116
|
+
const transactionOne = { date: this.getStartDate((periods - 1), date), snapshot: { open: Decimal.ONE } };
|
|
117
|
+
const transactionTwo = { date: date, snapshot: { open: Decimal.ZERO } };
|
|
118
|
+
|
|
119
|
+
return this._rangeCalculator([ transactionOne, transactionTwo ]);
|
|
120
|
+
}
|
|
121
|
+
|
|
102
122
|
/**
|
|
103
123
|
* Returns the start date for a frame, a given number of periods ago.
|
|
104
124
|
*
|
|
105
125
|
* @public
|
|
106
126
|
* @param {Number} periods
|
|
127
|
+
* @param {Day=} start
|
|
107
128
|
* @returns {Day}
|
|
108
129
|
*/
|
|
109
|
-
getStartDate(periods) {
|
|
130
|
+
getStartDate(periods, start) {
|
|
110
131
|
assert.argumentIsRequired(periods, 'periods', Number);
|
|
132
|
+
assert.argumentIsOptional(start, 'start', Day, 'Day');
|
|
111
133
|
|
|
112
|
-
return this._startDateCalculator(periods);
|
|
134
|
+
return this._startDateCalculator(periods, start);
|
|
113
135
|
}
|
|
114
136
|
|
|
115
137
|
/**
|
|
@@ -242,24 +264,24 @@ module.exports = (() => {
|
|
|
242
264
|
return ranges;
|
|
243
265
|
}
|
|
244
266
|
|
|
245
|
-
function getYearlyStartDate(periods) {
|
|
246
|
-
const today = Day.getToday();
|
|
267
|
+
function getYearlyStartDate(periods, date) {
|
|
268
|
+
const today = date || Day.getToday();
|
|
247
269
|
|
|
248
|
-
return
|
|
270
|
+
return today
|
|
249
271
|
.subtractMonths(today.month - 1)
|
|
250
272
|
.subtractDays(today.day)
|
|
251
273
|
.subtractYears(periods);
|
|
252
274
|
}
|
|
253
275
|
|
|
254
|
-
function getQuarterlyStartDate(periods) {
|
|
276
|
+
function getQuarterlyStartDate(periods, date) {
|
|
255
277
|
return null;
|
|
256
278
|
}
|
|
257
279
|
|
|
258
|
-
function getMonthlyStartDate(periods) {
|
|
280
|
+
function getMonthlyStartDate(periods, date) {
|
|
259
281
|
return null;
|
|
260
282
|
}
|
|
261
283
|
|
|
262
|
-
function getYearToDateStartDate(periods) {
|
|
284
|
+
function getYearToDateStartDate(periods, date) {
|
|
263
285
|
return null;
|
|
264
286
|
}
|
|
265
287
|
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -485,22 +485,44 @@ module.exports = (() => {
|
|
|
485
485
|
* @return {Array.<PositionSummaryRange>}
|
|
486
486
|
*/
|
|
487
487
|
getRangesFromDate(date) {
|
|
488
|
+
assert.argumentIsRequired(date, 'date', Day, 'Day');
|
|
489
|
+
|
|
488
490
|
const transaction = { date: date, snapshot: { open: Decimal.ONE } };
|
|
489
491
|
|
|
490
492
|
return this.getRanges([ transaction ]);
|
|
491
493
|
}
|
|
492
494
|
|
|
495
|
+
/**
|
|
496
|
+
* Returns the range immediately prior to the range containing the
|
|
497
|
+
* date supplied.
|
|
498
|
+
*
|
|
499
|
+
* @public
|
|
500
|
+
* @param {Day} date
|
|
501
|
+
* @param {Number} periods
|
|
502
|
+
*/
|
|
503
|
+
getPriorRanges(date, periods) {
|
|
504
|
+
assert.argumentIsRequired(date, 'date', Day, 'Day');
|
|
505
|
+
assert.argumentIsRequired(periods, 'periods', Number, 'Number');
|
|
506
|
+
|
|
507
|
+
const transactionOne = { date: this.getStartDate((periods - 1), date), snapshot: { open: Decimal.ONE } };
|
|
508
|
+
const transactionTwo = { date: date, snapshot: { open: Decimal.ZERO } };
|
|
509
|
+
|
|
510
|
+
return this._rangeCalculator([ transactionOne, transactionTwo ]);
|
|
511
|
+
}
|
|
512
|
+
|
|
493
513
|
/**
|
|
494
514
|
* Returns the start date for a frame, a given number of periods ago.
|
|
495
515
|
*
|
|
496
516
|
* @public
|
|
497
517
|
* @param {Number} periods
|
|
518
|
+
* @param {Day=} start
|
|
498
519
|
* @returns {Day}
|
|
499
520
|
*/
|
|
500
|
-
getStartDate(periods) {
|
|
521
|
+
getStartDate(periods, start) {
|
|
501
522
|
assert.argumentIsRequired(periods, 'periods', Number);
|
|
523
|
+
assert.argumentIsOptional(start, 'start', Day, 'Day');
|
|
502
524
|
|
|
503
|
-
return this._startDateCalculator(periods);
|
|
525
|
+
return this._startDateCalculator(periods, start);
|
|
504
526
|
}
|
|
505
527
|
|
|
506
528
|
/**
|
|
@@ -633,24 +655,24 @@ module.exports = (() => {
|
|
|
633
655
|
return ranges;
|
|
634
656
|
}
|
|
635
657
|
|
|
636
|
-
function getYearlyStartDate(periods) {
|
|
637
|
-
const today = Day.getToday();
|
|
658
|
+
function getYearlyStartDate(periods, date) {
|
|
659
|
+
const today = date || Day.getToday();
|
|
638
660
|
|
|
639
|
-
return
|
|
661
|
+
return today
|
|
640
662
|
.subtractMonths(today.month - 1)
|
|
641
663
|
.subtractDays(today.day)
|
|
642
664
|
.subtractYears(periods);
|
|
643
665
|
}
|
|
644
666
|
|
|
645
|
-
function getQuarterlyStartDate(periods) {
|
|
667
|
+
function getQuarterlyStartDate(periods, date) {
|
|
646
668
|
return null;
|
|
647
669
|
}
|
|
648
670
|
|
|
649
|
-
function getMonthlyStartDate(periods) {
|
|
671
|
+
function getMonthlyStartDate(periods, date) {
|
|
650
672
|
return null;
|
|
651
673
|
}
|
|
652
674
|
|
|
653
|
-
function getYearToDateStartDate(periods) {
|
|
675
|
+
function getYearToDateStartDate(periods, date) {
|
|
654
676
|
return null;
|
|
655
677
|
}
|
|
656
678
|
|
|
@@ -17632,6 +17654,38 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17632
17654
|
});
|
|
17633
17655
|
});
|
|
17634
17656
|
});
|
|
17657
|
+
|
|
17658
|
+
describe('and prior ranges are calculated', () => {
|
|
17659
|
+
describe('for YEARLY ranges', () => {
|
|
17660
|
+
describe('from 2017-10-10, including one previous ranges', () => {
|
|
17661
|
+
let ranges;
|
|
17662
|
+
|
|
17663
|
+
beforeEach(() => {
|
|
17664
|
+
ranges = PositionSummaryFrame.YEARLY.getPriorRanges(new Day(2015, 4, 20), 1);
|
|
17665
|
+
});
|
|
17666
|
+
|
|
17667
|
+
it('should return two ranges', () => {
|
|
17668
|
+
expect(ranges.length).toEqual(2);
|
|
17669
|
+
});
|
|
17670
|
+
|
|
17671
|
+
it('the first range should begin on 2013-12-31', () => {
|
|
17672
|
+
expect(ranges[0].start.getIsEqual(new Day(2013, 12, 31))).toEqual(true);
|
|
17673
|
+
});
|
|
17674
|
+
|
|
17675
|
+
it('the first range should end on 2014-12-31', () => {
|
|
17676
|
+
expect(ranges[0].end.getIsEqual(new Day(2014, 12, 31))).toEqual(true);
|
|
17677
|
+
});
|
|
17678
|
+
|
|
17679
|
+
it('the second range should begin on 2014-12-31', () => {
|
|
17680
|
+
expect(ranges[1].start.getIsEqual(new Day(2014, 12, 31))).toEqual(true);
|
|
17681
|
+
});
|
|
17682
|
+
|
|
17683
|
+
it('the second range should end on 2015-12-31', () => {
|
|
17684
|
+
expect(ranges[1].end.getIsEqual(new Day(2015, 12, 31))).toEqual(true);
|
|
17685
|
+
});
|
|
17686
|
+
});
|
|
17687
|
+
});
|
|
17688
|
+
});
|
|
17635
17689
|
});
|
|
17636
17690
|
|
|
17637
17691
|
},{"./../../../lib/data/PositionSummaryFrame":3,"./../../../lib/data/TransactionType":4,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22}],53:[function(require,module,exports){
|
|
@@ -422,4 +422,36 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
422
422
|
});
|
|
423
423
|
});
|
|
424
424
|
});
|
|
425
|
+
|
|
426
|
+
describe('and prior ranges are calculated', () => {
|
|
427
|
+
describe('for YEARLY ranges', () => {
|
|
428
|
+
describe('from 2017-10-10, including one previous ranges', () => {
|
|
429
|
+
let ranges;
|
|
430
|
+
|
|
431
|
+
beforeEach(() => {
|
|
432
|
+
ranges = PositionSummaryFrame.YEARLY.getPriorRanges(new Day(2015, 4, 20), 1);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('should return two ranges', () => {
|
|
436
|
+
expect(ranges.length).toEqual(2);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('the first range should begin on 2013-12-31', () => {
|
|
440
|
+
expect(ranges[0].start.getIsEqual(new Day(2013, 12, 31))).toEqual(true);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
it('the first range should end on 2014-12-31', () => {
|
|
444
|
+
expect(ranges[0].end.getIsEqual(new Day(2014, 12, 31))).toEqual(true);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('the second range should begin on 2014-12-31', () => {
|
|
448
|
+
expect(ranges[1].start.getIsEqual(new Day(2014, 12, 31))).toEqual(true);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it('the second range should end on 2015-12-31', () => {
|
|
452
|
+
expect(ranges[1].end.getIsEqual(new Day(2015, 12, 31))).toEqual(true);
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
});
|
|
425
457
|
});
|