@barchart/portfolio-api-common 1.2.95 → 1.2.96
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.
|
@@ -42,20 +42,22 @@ module.exports = (() => {
|
|
|
42
42
|
* @param {Array.<Object>} portfolios - The portfolios.
|
|
43
43
|
* @param {Array.<Object>} positions - The positions (for all of the portfolios).
|
|
44
44
|
* @param {Array.<Object>} summaries - The positions summaries (for all of the positions).
|
|
45
|
-
* @param {PositionSummaryFrame=} - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
|
|
45
|
+
* @param {PositionSummaryFrame=} reportFrame - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
|
|
46
46
|
*/
|
|
47
47
|
class PositionContainer {
|
|
48
|
-
constructor(definitions, portfolios, positions, summaries,
|
|
48
|
+
constructor(definitions, portfolios, positions, summaries, reportFrame) {
|
|
49
49
|
assert.argumentIsArray(definitions, 'definitions', PositionTreeDefinition, 'PositionTreeDefinition');
|
|
50
50
|
assert.argumentIsArray(portfolios, 'portfolios');
|
|
51
51
|
assert.argumentIsArray(positions, 'positions');
|
|
52
52
|
assert.argumentIsArray(summaries, 'summaries');
|
|
53
|
-
assert.argumentIsOptional(
|
|
53
|
+
assert.argumentIsOptional(reportFrame, 'reportFrame', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
54
54
|
|
|
55
55
|
this._definitions = definitions;
|
|
56
56
|
|
|
57
57
|
this._groupBindings = { };
|
|
58
58
|
|
|
59
|
+
this._reporting = reportFrame instanceof PositionSummaryFrame;
|
|
60
|
+
|
|
59
61
|
this._positionSymbolAddedEvent = new Event(this);
|
|
60
62
|
this._positionSymbolRemovedEvent = new Event(this);
|
|
61
63
|
|
|
@@ -65,10 +67,10 @@ module.exports = (() => {
|
|
|
65
67
|
return map;
|
|
66
68
|
}, { });
|
|
67
69
|
|
|
68
|
-
this._currentSummaryFrame =
|
|
70
|
+
this._currentSummaryFrame = reportFrame || PositionSummaryFrame.YTD;
|
|
69
71
|
this._currentSummaryRange = array.last(this._currentSummaryFrame.getRecentRanges(0));
|
|
70
72
|
|
|
71
|
-
this._previousSummaryFrame =
|
|
73
|
+
this._previousSummaryFrame = reportFrame || PositionSummaryFrame.YEARLY;
|
|
72
74
|
this._previousSummaryRanges = this._previousSummaryFrame.getRecentRanges(3);
|
|
73
75
|
|
|
74
76
|
if (this._currentSummaryFrame === this._previousSummaryFrame) {
|
|
@@ -942,7 +944,7 @@ module.exports = (() => {
|
|
|
942
944
|
const currentSummary = this._summariesCurrent[ position.position ] || null;
|
|
943
945
|
const previousSummaries = this._summariesPrevious[ position.position ] || getSummaryArray(this._previousSummaryRanges);
|
|
944
946
|
|
|
945
|
-
returnRef = new PositionItem(portfolio, position, currentSummary, previousSummaries);
|
|
947
|
+
returnRef = new PositionItem(portfolio, position, currentSummary, previousSummaries, this._reporting);
|
|
946
948
|
} else {
|
|
947
949
|
returnRef = null;
|
|
948
950
|
}
|
|
@@ -20,9 +20,10 @@ module.exports = (() => {
|
|
|
20
20
|
* @param {Object} position
|
|
21
21
|
* @param {Object} currentSummary
|
|
22
22
|
* @param {Array.<Object>} previousSummaries
|
|
23
|
+
* @param {Boolean} reporting
|
|
23
24
|
*/
|
|
24
25
|
class PositionItem extends Disposable {
|
|
25
|
-
constructor(portfolio, position, currentSummary, previousSummaries) {
|
|
26
|
+
constructor(portfolio, position, currentSummary, previousSummaries, reporting) {
|
|
26
27
|
super();
|
|
27
28
|
|
|
28
29
|
this._portfolio = portfolio;
|
|
@@ -36,6 +37,8 @@ module.exports = (() => {
|
|
|
36
37
|
this._currentSummary = currentSummary || null;
|
|
37
38
|
this._previousSummaries = previousSummaries || [ ];
|
|
38
39
|
|
|
40
|
+
this._reporting = reporting;
|
|
41
|
+
|
|
39
42
|
this._data = { };
|
|
40
43
|
|
|
41
44
|
this._data.basis = null;
|
|
@@ -364,7 +367,7 @@ module.exports = (() => {
|
|
|
364
367
|
|
|
365
368
|
function calculateStaticData(item) {
|
|
366
369
|
const position = item.position;
|
|
367
|
-
const snapshot = item.
|
|
370
|
+
const snapshot = getSnapshot(position, item.currentSummary, item._reporting);
|
|
368
371
|
const previousSummaries = item.previousSummaries;
|
|
369
372
|
|
|
370
373
|
const data = item._data;
|
|
@@ -408,7 +411,7 @@ module.exports = (() => {
|
|
|
408
411
|
|
|
409
412
|
function calculatePriceData(item, price) {
|
|
410
413
|
const position = item.position;
|
|
411
|
-
const snapshot = item.
|
|
414
|
+
const snapshot = getSnapshot(position, item.currentSummary, item._reporting);
|
|
412
415
|
const previousSummaries = item.previousSummaries;
|
|
413
416
|
|
|
414
417
|
const data = item._data;
|
|
@@ -560,5 +563,27 @@ module.exports = (() => {
|
|
|
560
563
|
return is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
|
|
561
564
|
}
|
|
562
565
|
|
|
566
|
+
function getSnapshot(position, currentSummary, reporting) {
|
|
567
|
+
let snapshot;
|
|
568
|
+
|
|
569
|
+
if (reporting) {
|
|
570
|
+
snapshot = { };
|
|
571
|
+
|
|
572
|
+
snapshot.date = currentSummary.end.date;
|
|
573
|
+
snapshot.open = currentSummary.end.open;
|
|
574
|
+
snapshot.direction = currentSummary.end.direction;
|
|
575
|
+
snapshot.buys = currentSummary.period.buys;
|
|
576
|
+
snapshot.sells = currentSummary.period.sells;
|
|
577
|
+
snapshot.gain = currentSummary.period.realized;
|
|
578
|
+
snapshot.basis = currentSummary.end.basis;
|
|
579
|
+
snapshot.income = currentSummary.period.income;
|
|
580
|
+
snapshot.value = currentSummary.end.value;
|
|
581
|
+
} else {
|
|
582
|
+
snapshot = position.snapshot;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
return snapshot;
|
|
586
|
+
}
|
|
587
|
+
|
|
563
588
|
return PositionItem;
|
|
564
589
|
})();
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -1466,20 +1466,22 @@ module.exports = (() => {
|
|
|
1466
1466
|
* @param {Array.<Object>} portfolios - The portfolios.
|
|
1467
1467
|
* @param {Array.<Object>} positions - The positions (for all of the portfolios).
|
|
1468
1468
|
* @param {Array.<Object>} summaries - The positions summaries (for all of the positions).
|
|
1469
|
-
* @param {PositionSummaryFrame=} - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
|
|
1469
|
+
* @param {PositionSummaryFrame=} reportFrame - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
|
|
1470
1470
|
*/
|
|
1471
1471
|
class PositionContainer {
|
|
1472
|
-
constructor(definitions, portfolios, positions, summaries,
|
|
1472
|
+
constructor(definitions, portfolios, positions, summaries, reportFrame) {
|
|
1473
1473
|
assert.argumentIsArray(definitions, 'definitions', PositionTreeDefinition, 'PositionTreeDefinition');
|
|
1474
1474
|
assert.argumentIsArray(portfolios, 'portfolios');
|
|
1475
1475
|
assert.argumentIsArray(positions, 'positions');
|
|
1476
1476
|
assert.argumentIsArray(summaries, 'summaries');
|
|
1477
|
-
assert.argumentIsOptional(
|
|
1477
|
+
assert.argumentIsOptional(reportFrame, 'reportFrame', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
1478
1478
|
|
|
1479
1479
|
this._definitions = definitions;
|
|
1480
1480
|
|
|
1481
1481
|
this._groupBindings = { };
|
|
1482
1482
|
|
|
1483
|
+
this._reporting = reportFrame instanceof PositionSummaryFrame;
|
|
1484
|
+
|
|
1483
1485
|
this._positionSymbolAddedEvent = new Event(this);
|
|
1484
1486
|
this._positionSymbolRemovedEvent = new Event(this);
|
|
1485
1487
|
|
|
@@ -1489,10 +1491,10 @@ module.exports = (() => {
|
|
|
1489
1491
|
return map;
|
|
1490
1492
|
}, { });
|
|
1491
1493
|
|
|
1492
|
-
this._currentSummaryFrame =
|
|
1494
|
+
this._currentSummaryFrame = reportFrame || PositionSummaryFrame.YTD;
|
|
1493
1495
|
this._currentSummaryRange = array.last(this._currentSummaryFrame.getRecentRanges(0));
|
|
1494
1496
|
|
|
1495
|
-
this._previousSummaryFrame =
|
|
1497
|
+
this._previousSummaryFrame = reportFrame || PositionSummaryFrame.YEARLY;
|
|
1496
1498
|
this._previousSummaryRanges = this._previousSummaryFrame.getRecentRanges(3);
|
|
1497
1499
|
|
|
1498
1500
|
if (this._currentSummaryFrame === this._previousSummaryFrame) {
|
|
@@ -2366,7 +2368,7 @@ module.exports = (() => {
|
|
|
2366
2368
|
const currentSummary = this._summariesCurrent[ position.position ] || null;
|
|
2367
2369
|
const previousSummaries = this._summariesPrevious[ position.position ] || getSummaryArray(this._previousSummaryRanges);
|
|
2368
2370
|
|
|
2369
|
-
returnRef = new PositionItem(portfolio, position, currentSummary, previousSummaries);
|
|
2371
|
+
returnRef = new PositionItem(portfolio, position, currentSummary, previousSummaries, this._reporting);
|
|
2370
2372
|
} else {
|
|
2371
2373
|
returnRef = null;
|
|
2372
2374
|
}
|
|
@@ -3360,9 +3362,10 @@ module.exports = (() => {
|
|
|
3360
3362
|
* @param {Object} position
|
|
3361
3363
|
* @param {Object} currentSummary
|
|
3362
3364
|
* @param {Array.<Object>} previousSummaries
|
|
3365
|
+
* @param {Boolean} reporting
|
|
3363
3366
|
*/
|
|
3364
3367
|
class PositionItem extends Disposable {
|
|
3365
|
-
constructor(portfolio, position, currentSummary, previousSummaries) {
|
|
3368
|
+
constructor(portfolio, position, currentSummary, previousSummaries, reporting) {
|
|
3366
3369
|
super();
|
|
3367
3370
|
|
|
3368
3371
|
this._portfolio = portfolio;
|
|
@@ -3376,6 +3379,8 @@ module.exports = (() => {
|
|
|
3376
3379
|
this._currentSummary = currentSummary || null;
|
|
3377
3380
|
this._previousSummaries = previousSummaries || [ ];
|
|
3378
3381
|
|
|
3382
|
+
this._reporting = reporting;
|
|
3383
|
+
|
|
3379
3384
|
this._data = { };
|
|
3380
3385
|
|
|
3381
3386
|
this._data.basis = null;
|
|
@@ -3704,7 +3709,7 @@ module.exports = (() => {
|
|
|
3704
3709
|
|
|
3705
3710
|
function calculateStaticData(item) {
|
|
3706
3711
|
const position = item.position;
|
|
3707
|
-
const snapshot = item.
|
|
3712
|
+
const snapshot = getSnapshot(position, item.currentSummary, item._reporting);
|
|
3708
3713
|
const previousSummaries = item.previousSummaries;
|
|
3709
3714
|
|
|
3710
3715
|
const data = item._data;
|
|
@@ -3748,7 +3753,7 @@ module.exports = (() => {
|
|
|
3748
3753
|
|
|
3749
3754
|
function calculatePriceData(item, price) {
|
|
3750
3755
|
const position = item.position;
|
|
3751
|
-
const snapshot = item.
|
|
3756
|
+
const snapshot = getSnapshot(position, item.currentSummary, item._reporting);
|
|
3752
3757
|
const previousSummaries = item.previousSummaries;
|
|
3753
3758
|
|
|
3754
3759
|
const data = item._data;
|
|
@@ -3900,6 +3905,28 @@ module.exports = (() => {
|
|
|
3900
3905
|
return is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
|
|
3901
3906
|
}
|
|
3902
3907
|
|
|
3908
|
+
function getSnapshot(position, currentSummary, reporting) {
|
|
3909
|
+
let snapshot;
|
|
3910
|
+
|
|
3911
|
+
if (reporting) {
|
|
3912
|
+
snapshot = { };
|
|
3913
|
+
|
|
3914
|
+
snapshot.date = currentSummary.end.date;
|
|
3915
|
+
snapshot.open = currentSummary.end.open;
|
|
3916
|
+
snapshot.direction = currentSummary.end.direction;
|
|
3917
|
+
snapshot.buys = currentSummary.period.buys;
|
|
3918
|
+
snapshot.sells = currentSummary.period.sells;
|
|
3919
|
+
snapshot.gain = currentSummary.period.realized;
|
|
3920
|
+
snapshot.basis = currentSummary.end.basis;
|
|
3921
|
+
snapshot.income = currentSummary.period.income;
|
|
3922
|
+
snapshot.value = currentSummary.end.value;
|
|
3923
|
+
} else {
|
|
3924
|
+
snapshot = position.snapshot;
|
|
3925
|
+
}
|
|
3926
|
+
|
|
3927
|
+
return snapshot;
|
|
3928
|
+
}
|
|
3929
|
+
|
|
3903
3930
|
return PositionItem;
|
|
3904
3931
|
})();
|
|
3905
3932
|
|