@barchart/portfolio-api-common 1.2.123 → 1.2.124
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.
- package/lib/data/PositionSummaryFrame.js +23 -23
- package/package.json +1 -1
- package/test/SpecRunner.js +23 -23
|
@@ -64,7 +64,7 @@ module.exports = (() => {
|
|
|
64
64
|
*
|
|
65
65
|
* @public
|
|
66
66
|
* @param {Number} periods
|
|
67
|
-
* @returns {
|
|
67
|
+
* @returns {PositionSummaryRange[]}
|
|
68
68
|
*/
|
|
69
69
|
getRecentRanges(periods) {
|
|
70
70
|
const startDate = this.getStartDate(periods);
|
|
@@ -77,8 +77,8 @@ module.exports = (() => {
|
|
|
77
77
|
* Returns the ranges for the set of {@link Transaction} objects.
|
|
78
78
|
*
|
|
79
79
|
* @public
|
|
80
|
-
* @param {
|
|
81
|
-
* @returns {
|
|
80
|
+
* @param {Transaction[]} transactions
|
|
81
|
+
* @returns {PositionSummaryRange[]}
|
|
82
82
|
*/
|
|
83
83
|
getRanges(transactions) {
|
|
84
84
|
assert.argumentIsArray(transactions, 'transactions');
|
|
@@ -91,7 +91,7 @@ module.exports = (() => {
|
|
|
91
91
|
*
|
|
92
92
|
* @public
|
|
93
93
|
* @param {Day} date
|
|
94
|
-
* @return {
|
|
94
|
+
* @return {PositionSummaryRange[]}
|
|
95
95
|
*/
|
|
96
96
|
getRangesFromDate(date) {
|
|
97
97
|
assert.argumentIsRequired(date, 'date', Day, 'Day');
|
|
@@ -180,8 +180,8 @@ module.exports = (() => {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
const yearly = new PositionSummaryFrame('YEARLY', 'year', false, getYearlyRanges, getYearlyStartDate, getYearlyRangeDescription);
|
|
183
|
-
const quarterly = new PositionSummaryFrame('
|
|
184
|
-
const monthly = new PositionSummaryFrame('
|
|
183
|
+
const quarterly = new PositionSummaryFrame('QUARTERLY', 'quarter', false, getQuarterlyRanges, getQuarterlyStartDate, getQuarterlyRangeDescription);
|
|
184
|
+
const monthly = new PositionSummaryFrame('MONTHLY', 'month', false, getMonthlyRanges, getMonthlyStartDate, getMonthlyRangeDescription);
|
|
185
185
|
const ytd = new PositionSummaryFrame('YTD', 'year-to-date', true, getYearToDateRanges, getYearToDateStartDate, getYearToDateRangeDescription);
|
|
186
186
|
|
|
187
187
|
/**
|
|
@@ -241,32 +241,32 @@ module.exports = (() => {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
function getMonthlyRanges(transactions) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
244
|
+
const ranges = [ ];
|
|
245
|
+
|
|
246
|
+
if (!transactions.length) {
|
|
247
|
+
return ranges;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
const first = array.first(transactions);
|
|
251
251
|
const last = array.last(transactions);
|
|
252
252
|
|
|
253
253
|
const firstDate = first.date;
|
|
254
|
+
|
|
254
255
|
let lastDate;
|
|
255
256
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
+
}
|
|
262
|
+
|
|
259
263
|
lastDate = lastDate.getEndOfMonth();
|
|
260
264
|
|
|
261
|
-
for (
|
|
262
|
-
let end = firstDate.getEndOfMonth();
|
|
263
|
-
end.format() <= lastDate.format();
|
|
264
|
-
end = end.addMonths(1).getEndOfMonth()
|
|
265
|
-
) {
|
|
265
|
+
for (let end = firstDate.getEndOfMonth(); end.format() <= lastDate.format(); end = end.addMonths(1).getEndOfMonth()) {
|
|
266
266
|
ranges.push(getRange(end.subtractMonths(1).getEndOfMonth(), end));
|
|
267
267
|
}
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
|
|
269
|
+
return ranges;
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
function getYearToDateRanges(transactions) {
|
|
@@ -303,8 +303,8 @@ module.exports = (() => {
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
function getMonthlyStartDate(periods, date) {
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
const today = date || Day.getToday();
|
|
307
|
+
|
|
308
308
|
return today
|
|
309
309
|
.subtractMonths(periods)
|
|
310
310
|
.subtractDays(today.day);
|
|
@@ -323,7 +323,7 @@ module.exports = (() => {
|
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
function getMonthlyRangeDescription(start, end) {
|
|
326
|
-
return
|
|
326
|
+
return `Month ended ${end.format()}`;
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
function getYearToDateRangeDescription(start, end) {
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -455,7 +455,7 @@ module.exports = (() => {
|
|
|
455
455
|
*
|
|
456
456
|
* @public
|
|
457
457
|
* @param {Number} periods
|
|
458
|
-
* @returns {
|
|
458
|
+
* @returns {PositionSummaryRange[]}
|
|
459
459
|
*/
|
|
460
460
|
getRecentRanges(periods) {
|
|
461
461
|
const startDate = this.getStartDate(periods);
|
|
@@ -468,8 +468,8 @@ module.exports = (() => {
|
|
|
468
468
|
* Returns the ranges for the set of {@link Transaction} objects.
|
|
469
469
|
*
|
|
470
470
|
* @public
|
|
471
|
-
* @param {
|
|
472
|
-
* @returns {
|
|
471
|
+
* @param {Transaction[]} transactions
|
|
472
|
+
* @returns {PositionSummaryRange[]}
|
|
473
473
|
*/
|
|
474
474
|
getRanges(transactions) {
|
|
475
475
|
assert.argumentIsArray(transactions, 'transactions');
|
|
@@ -482,7 +482,7 @@ module.exports = (() => {
|
|
|
482
482
|
*
|
|
483
483
|
* @public
|
|
484
484
|
* @param {Day} date
|
|
485
|
-
* @return {
|
|
485
|
+
* @return {PositionSummaryRange[]}
|
|
486
486
|
*/
|
|
487
487
|
getRangesFromDate(date) {
|
|
488
488
|
assert.argumentIsRequired(date, 'date', Day, 'Day');
|
|
@@ -571,8 +571,8 @@ module.exports = (() => {
|
|
|
571
571
|
}
|
|
572
572
|
|
|
573
573
|
const yearly = new PositionSummaryFrame('YEARLY', 'year', false, getYearlyRanges, getYearlyStartDate, getYearlyRangeDescription);
|
|
574
|
-
const quarterly = new PositionSummaryFrame('
|
|
575
|
-
const monthly = new PositionSummaryFrame('
|
|
574
|
+
const quarterly = new PositionSummaryFrame('QUARTERLY', 'quarter', false, getQuarterlyRanges, getQuarterlyStartDate, getQuarterlyRangeDescription);
|
|
575
|
+
const monthly = new PositionSummaryFrame('MONTHLY', 'month', false, getMonthlyRanges, getMonthlyStartDate, getMonthlyRangeDescription);
|
|
576
576
|
const ytd = new PositionSummaryFrame('YTD', 'year-to-date', true, getYearToDateRanges, getYearToDateStartDate, getYearToDateRangeDescription);
|
|
577
577
|
|
|
578
578
|
/**
|
|
@@ -632,32 +632,32 @@ module.exports = (() => {
|
|
|
632
632
|
}
|
|
633
633
|
|
|
634
634
|
function getMonthlyRanges(transactions) {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
635
|
+
const ranges = [ ];
|
|
636
|
+
|
|
637
|
+
if (!transactions.length) {
|
|
638
|
+
return ranges;
|
|
639
639
|
}
|
|
640
640
|
|
|
641
641
|
const first = array.first(transactions);
|
|
642
642
|
const last = array.last(transactions);
|
|
643
643
|
|
|
644
644
|
const firstDate = first.date;
|
|
645
|
+
|
|
645
646
|
let lastDate;
|
|
646
647
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
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
|
+
}
|
|
653
|
+
|
|
650
654
|
lastDate = lastDate.getEndOfMonth();
|
|
651
655
|
|
|
652
|
-
for (
|
|
653
|
-
let end = firstDate.getEndOfMonth();
|
|
654
|
-
end.format() <= lastDate.format();
|
|
655
|
-
end = end.addMonths(1).getEndOfMonth()
|
|
656
|
-
) {
|
|
656
|
+
for (let end = firstDate.getEndOfMonth(); end.format() <= lastDate.format(); end = end.addMonths(1).getEndOfMonth()) {
|
|
657
657
|
ranges.push(getRange(end.subtractMonths(1).getEndOfMonth(), end));
|
|
658
658
|
}
|
|
659
|
-
|
|
660
|
-
|
|
659
|
+
|
|
660
|
+
return ranges;
|
|
661
661
|
}
|
|
662
662
|
|
|
663
663
|
function getYearToDateRanges(transactions) {
|
|
@@ -694,8 +694,8 @@ module.exports = (() => {
|
|
|
694
694
|
}
|
|
695
695
|
|
|
696
696
|
function getMonthlyStartDate(periods, date) {
|
|
697
|
-
|
|
698
|
-
|
|
697
|
+
const today = date || Day.getToday();
|
|
698
|
+
|
|
699
699
|
return today
|
|
700
700
|
.subtractMonths(periods)
|
|
701
701
|
.subtractDays(today.day);
|
|
@@ -714,7 +714,7 @@ module.exports = (() => {
|
|
|
714
714
|
}
|
|
715
715
|
|
|
716
716
|
function getMonthlyRangeDescription(start, end) {
|
|
717
|
-
return
|
|
717
|
+
return `Month ended ${end.format()}`;
|
|
718
718
|
}
|
|
719
719
|
|
|
720
720
|
function getYearToDateRangeDescription(start, end) {
|