@barchart/portfolio-api-common 1.2.98 → 1.2.99

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.
@@ -43,15 +43,20 @@ module.exports = (() => {
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
45
  * @param {PositionSummaryFrame=} reportFrame - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
46
+ * @param {Day=} reportDate - The end date for the report frame.
46
47
  */
47
48
  class PositionContainer {
48
- constructor(definitions, portfolios, positions, summaries, reportFrame) {
49
+ constructor(definitions, portfolios, positions, summaries, reportFrame, reportDate) {
49
50
  assert.argumentIsArray(definitions, 'definitions', PositionTreeDefinition, 'PositionTreeDefinition');
50
51
  assert.argumentIsArray(portfolios, 'portfolios');
51
52
  assert.argumentIsArray(positions, 'positions');
52
53
  assert.argumentIsArray(summaries, 'summaries');
53
54
  assert.argumentIsOptional(reportFrame, 'reportFrame', PositionSummaryFrame, 'PositionSummaryFrame');
54
55
 
56
+ if (reportFrame) {
57
+ assert.argumentIsRequired(reportDate, 'reportDate', Day, 'Day');
58
+ }
59
+
55
60
  this._definitions = definitions;
56
61
 
57
62
  this._groupBindings = { };
@@ -67,15 +72,21 @@ module.exports = (() => {
67
72
  return map;
68
73
  }, { });
69
74
 
70
- this._currentSummaryFrame = reportFrame || PositionSummaryFrame.YTD;
71
- this._currentSummaryRange = array.last(this._currentSummaryFrame.getRecentRanges(0));
75
+ if (reportFrame) {
76
+ this._currentSummaryFrame = reportFrame;
77
+ this._currentSummaryRange = array.last(this._currentSummaryFrame.getPriorRanges(reportDate, 0));
72
78
 
73
- this._previousSummaryFrame = reportFrame || PositionSummaryFrame.YEARLY;
74
- this._previousSummaryRanges = this._previousSummaryFrame.getRecentRanges(3);
79
+ this._previousSummaryFrame = reportFrame;
80
+ this._previousSummaryRanges = this._currentSummaryFrame.getPriorRanges(reportDate, 3);
75
81
 
76
- if (this._currentSummaryFrame === this._previousSummaryFrame) {
77
82
  this._previousSummaryRanges.pop();
78
83
  } else {
84
+ this._currentSummaryFrame = PositionSummaryFrame.YTD;
85
+ this._currentSummaryRange = array.first(this._currentSummaryFrame.getRecentRanges(0));
86
+
87
+ this._previousSummaryFrame = PositionSummaryFrame.YEARLY;
88
+ this._previousSummaryRanges = this._previousSummaryFrame.getRecentRanges(3);
89
+
79
90
  this._previousSummaryRanges.shift();
80
91
  }
81
92
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.98",
3
+ "version": "1.2.99",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1467,15 +1467,20 @@ module.exports = (() => {
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
1469
  * @param {PositionSummaryFrame=} reportFrame - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
1470
+ * @param {Day=} reportDate - The end date for the report frame.
1470
1471
  */
1471
1472
  class PositionContainer {
1472
- constructor(definitions, portfolios, positions, summaries, reportFrame) {
1473
+ constructor(definitions, portfolios, positions, summaries, reportFrame, reportDate) {
1473
1474
  assert.argumentIsArray(definitions, 'definitions', PositionTreeDefinition, 'PositionTreeDefinition');
1474
1475
  assert.argumentIsArray(portfolios, 'portfolios');
1475
1476
  assert.argumentIsArray(positions, 'positions');
1476
1477
  assert.argumentIsArray(summaries, 'summaries');
1477
1478
  assert.argumentIsOptional(reportFrame, 'reportFrame', PositionSummaryFrame, 'PositionSummaryFrame');
1478
1479
 
1480
+ if (reportFrame) {
1481
+ assert.argumentIsRequired(reportDate, 'reportDate', Day, 'Day');
1482
+ }
1483
+
1479
1484
  this._definitions = definitions;
1480
1485
 
1481
1486
  this._groupBindings = { };
@@ -1491,15 +1496,21 @@ module.exports = (() => {
1491
1496
  return map;
1492
1497
  }, { });
1493
1498
 
1494
- this._currentSummaryFrame = reportFrame || PositionSummaryFrame.YTD;
1495
- this._currentSummaryRange = array.last(this._currentSummaryFrame.getRecentRanges(0));
1499
+ if (reportFrame) {
1500
+ this._currentSummaryFrame = reportFrame;
1501
+ this._currentSummaryRange = array.last(this._currentSummaryFrame.getPriorRanges(reportDate, 0));
1496
1502
 
1497
- this._previousSummaryFrame = reportFrame || PositionSummaryFrame.YEARLY;
1498
- this._previousSummaryRanges = this._previousSummaryFrame.getRecentRanges(3);
1503
+ this._previousSummaryFrame = reportFrame;
1504
+ this._previousSummaryRanges = this._currentSummaryFrame.getPriorRanges(reportDate, 3);
1499
1505
 
1500
- if (this._currentSummaryFrame === this._previousSummaryFrame) {
1501
1506
  this._previousSummaryRanges.pop();
1502
1507
  } else {
1508
+ this._currentSummaryFrame = PositionSummaryFrame.YTD;
1509
+ this._currentSummaryRange = array.first(this._currentSummaryFrame.getRecentRanges(0));
1510
+
1511
+ this._previousSummaryFrame = PositionSummaryFrame.YEARLY;
1512
+ this._previousSummaryRanges = this._previousSummaryFrame.getRecentRanges(3);
1513
+
1503
1514
  this._previousSummaryRanges.shift();
1504
1515
  }
1505
1516