@barchart/portfolio-api-common 1.0.89 → 1.0.90

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.
@@ -37,12 +37,13 @@ module.exports = (() => {
37
37
  * start and end dates.
38
38
  *
39
39
  * @public
40
- * @param {Day} startDate
41
- * @param {Day} endDate
40
+ * @return {PositionSummaryRange} range
42
41
  * @return {String}
43
42
  */
44
- describeRange(startDate, endDate) {
45
- return this._descriptionCalculator(startDate, endDate);
43
+ describeRange(range) {
44
+ console.log('range: ', range);
45
+
46
+ return this._descriptionCalculator(range.start, range.end);
46
47
  }
47
48
 
48
49
  /**
@@ -226,20 +227,20 @@ module.exports = (() => {
226
227
  return null;
227
228
  }
228
229
 
229
- function getYearlyRangeDescription(startDate, endDate) {
230
- return endDate.year.toString();
230
+ function getYearlyRangeDescription(start, end) {
231
+ return end.year.toString();
231
232
  }
232
233
 
233
- function getQuarterlyRangeDescription(startDate, endDate) {
234
+ function getQuarterlyRangeDescription(start, end) {
234
235
  return '';
235
236
  }
236
237
 
237
- function getMonthlyRangeDescription(startDate, endDate) {
238
+ function getMonthlyRangeDescription(start, end) {
238
239
  return '';
239
240
  }
240
241
 
241
- function getYearToDateRangeDescription(startDate, endDate) {
242
- return `${endDate.year.toString()} YTD`;
242
+ function getYearToDateRangeDescription(start, end) {
243
+ return `${end.year.toString()} YTD`;
243
244
  }
244
245
 
245
246
  function getFilteredTransactions(transactions) {
@@ -18,12 +18,18 @@ module.exports = (() => {
18
18
  * @public
19
19
  */
20
20
  class PositionContainer {
21
- constructor(portfolios, positions, summaries, definitions, defaultCurrency, summaryFrameType) {
21
+ constructor(portfolios, positions, summaries, definitions, defaultCurrency, summaryFrame) {
22
22
  this._definitions = definitions;
23
23
  this._defaultCurrency = defaultCurrency || Currency.CAD;
24
+
25
+ const previousSummaryFrame = summaryFrame || PositionSummaryFrame.YEARLY;
26
+ const previousSummaryRanges = previousSummaryFrame.getRecentRanges(0);
24
27
 
25
- this._summaryFrame = summaryFrameType || PositionSummaryFrame.YEARLY;
26
- this._summaryRanges = this._summaryFrame.getRecentRanges(1);
28
+ const currentSummaryFrame = PositionSummaryFrame.YTD;
29
+ const currentSummaryRange = array.last(currentSummaryFrame.getRecentRanges(0));
30
+
31
+ this._summaryDescriptionCurrent = previousSummaryFrame.describeRange(array.last(previousSummaryRanges));
32
+ this._summaryDescriptionPrevious = currentSummaryFrame.describeRange(currentSummaryRange);
27
33
 
28
34
  this._portfolios = portfolios.reduce((map, portfolio) => {
29
35
  map[portfolio.portfolio] = portfolio;
@@ -31,15 +37,25 @@ module.exports = (() => {
31
37
  return map;
32
38
  }, { });
33
39
 
34
- this._summaries = summaries.reduce((map, summary) => {
35
- if (this._summaryFrame === summary.frame) {
40
+ this._summariesCurrent = summaries.reduce((map, summary) => {
41
+ if (summary.frame === currentSummaryFrame && currentSummaryRange.start.getIsEqual(summary.start.date) && currentSummaryRange.end.getIsEqual(summary.end.date)) {
42
+ const key = summary.position;
43
+
44
+ map[key] = summary;
45
+ }
46
+
47
+ return map;
48
+ }, { });
49
+
50
+ this._summariesPrevious = summaries.reduce((map, summary) => {
51
+ if (summary.frame === previousSummaryFrame) {
36
52
  const key = summary.position;
37
53
 
38
54
  if (!map.hasOwnProperty(key)) {
39
- map[key] = getSummaryArray(this._summaryRanges);
55
+ map[key] = getSummaryArray(previousSummaryRanges);
40
56
  }
41
57
 
42
- const index = this._summaryRanges.findIndex(r => r.start.getIsEqual(summary.start.date) && r.end.getIsEqual(summary.end.date));
58
+ const index = previousSummaryRanges.findIndex(r => r.start.getIsEqual(summary.start.date) && r.end.getIsEqual(summary.end.date));
43
59
 
44
60
  if (!(index < 0)) {
45
61
  map[key][index] = summary;
@@ -53,9 +69,10 @@ module.exports = (() => {
53
69
  const portfolio = this._portfolios[position.portfolio];
54
70
 
55
71
  if (position) {
56
- const summaries = this._summaries[position.position] || getSummaryArray(this._summaryRanges);
72
+ const currentSummary = this._summariesCurrent[position.position] || null;
73
+ const previousSummaries = this._summariesPrevious[position.position] || getSummaryArray(previousSummaryRanges);
57
74
 
58
- items.push(new PositionItem(portfolio, position, summaries));
75
+ items.push(new PositionItem(portfolio, position, currentSummary, previousSummaries));
59
76
  }
60
77
 
61
78
  return items;
@@ -167,7 +184,25 @@ module.exports = (() => {
167
184
  get defaultCurrency() {
168
185
  return this._defaultCurrency;
169
186
  }
187
+
188
+ getCurrentSummaryDescription() {
189
+ return this._summaryDescriptionCurrent;
190
+ }
191
+
192
+ getPreviousSummaryDescription() {
193
+ return this._summaryDescriptionPrevious;
194
+ }
195
+
196
+ startTransaction(executor) {
197
+ assert.argumentIsRequired(executor, 'executor', Function);
198
+
199
+ this._tree.walk(group => group.setSuspended(true), false, false);
170
200
 
201
+ executor(this);
202
+
203
+ this._tree.walk(group => group.setSuspended(false), false, false);
204
+ }
205
+
171
206
  getSymbols() {
172
207
  return Object.keys(this._symbols);
173
208
  }
@@ -194,16 +229,6 @@ module.exports = (() => {
194
229
 
195
230
  }
196
231
 
197
- startTransaction(executor) {
198
- assert.argumentIsRequired(executor, 'executor', Function);
199
-
200
- this._tree.walk(group => group.setSuspended(true), false, false);
201
-
202
- executor(this);
203
-
204
- this._tree.walk(group => group.setSuspended(false), false, false);
205
- }
206
-
207
232
  getGroup(keys) {
208
233
  const node = keys.reduce((tree, key) => {
209
234
  tree = tree.findChild(group => group.description === key);
@@ -42,8 +42,8 @@ module.exports = (() => {
42
42
  this._dataActual.marketPercent = null;
43
43
  this._dataActual.unrealizedToday = null;
44
44
  this._dataActual.total = null;
45
- this._dataActual.summaryOneTotal = null;
46
- this._dataActual.summaryTwoTotal = null;
45
+ this._dataActual.summaryTotalCurrent = null;
46
+ this._dataActual.summaryTotalPrevious = null;
47
47
 
48
48
  this._dataFormat.currentPrice = null;
49
49
  this._dataFormat.previousPrice = null;
@@ -57,8 +57,8 @@ module.exports = (() => {
57
57
  this._dataFormat.unrealizedTodayNegative = false;
58
58
  this._dataFormat.total = null;
59
59
  this._dataFormat.totalNegative = false;
60
- this._dataFormat.summaryOneTotal = null;
61
- this._dataFormat.summaryTwoTotal = null;
60
+ this._dataFormat.summaryTotalCurrent = null;
61
+ this._dataFormat.summaryTotalPrevious = null;
62
62
 
63
63
  this._dataFormat.unrealizedTodayNegative = false;
64
64
 
@@ -187,29 +187,29 @@ module.exports = (() => {
187
187
  updates.basis = updates.basis.add(item.data.basis);
188
188
  updates.realized = updates.realized.add(item.data.realized);
189
189
  updates.income = updates.income.add(item.data.income);
190
- updates.summaryOneTotal = updates.summaryOneTotal.add(item.data.summaryOneTotal);
191
- updates.summaryTwoTotal = updates.summaryTwoTotal.add(item.data.summaryTwoTotal);
190
+ updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(item.data.summaryTotalCurrent);
191
+ updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(item.data.summaryTotalPrevious);
192
192
 
193
193
  return updates;
194
194
  }, {
195
195
  basis: Decimal.ZERO,
196
196
  realized: Decimal.ZERO,
197
197
  income: Decimal.ZERO,
198
- summaryOneTotal: Decimal.ZERO,
199
- summaryTwoTotal: Decimal.ZERO
198
+ summaryTotalCurrent: Decimal.ZERO,
199
+ summaryTotalPrevious: Decimal.ZERO
200
200
  });
201
201
 
202
202
  actual.basis = updates.basis;
203
203
  actual.realized = updates.realized;
204
204
  actual.income = updates.income;
205
- actual.summaryOneTotal = updates.summaryOneTotal;
206
- actual.summaryTwoTotal = updates.summaryTwoTotal;
205
+ actual.summaryTotalCurrent = updates.summaryTotalCurrent;
206
+ actual.summaryTotalPrevious = updates.summaryTotalPrevious;
207
207
 
208
208
  format.basis = formatCurrency(actual.basis, currency);
209
209
  format.realized = formatCurrency(actual.basis, currency);
210
210
  format.income = formatCurrency(actual.income, currency);
211
- format.summaryOneTotal = formatCurrency(updates.summaryOneTotal, currency);
212
- format.summaryTwoTotal = formatCurrency(updates.summaryTwoTotal, currency);
211
+ format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
212
+ format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
213
213
  }
214
214
 
215
215
  function calculatePriceData(group, item, forceRefresh) {
@@ -1,4 +1,5 @@
1
- const assert = require('@barchart/common-js/lang/assert'),
1
+ const array = require('@barchart/common-js/lang/array'),
2
+ assert = require('@barchart/common-js/lang/assert'),
2
3
  Decimal = require('@barchart/common-js/lang/Decimal'),
3
4
  Event = require('@barchart/common-js/messaging/Event'),
4
5
  is = require('@barchart/common-js/lang/is');
@@ -12,10 +13,12 @@ module.exports = (() => {
12
13
  * @public
13
14
  */
14
15
  class PositionItem {
15
- constructor(portfolio, position, summaries) {
16
+ constructor(portfolio, position, currentSummary, previousSummaries) {
16
17
  this._portfolio = portfolio;
17
18
  this._position = position;
18
- this._summaries = summaries || [ ];
19
+
20
+ this._currentSummary = currentSummary || null;
21
+ this._previousSummaries = previousSummaries || [ ];
19
22
 
20
23
  this._data = { };
21
24
 
@@ -32,6 +35,9 @@ module.exports = (() => {
32
35
 
33
36
  this._data.realized = null;
34
37
  this._data.income = null;
38
+
39
+ this._data.summaryTotalCurrent = null;
40
+ this._data.summaryTotalPrevious = null;
35
41
 
36
42
  this._excluded = false;
37
43
 
@@ -50,8 +56,12 @@ module.exports = (() => {
50
56
  return this._position;
51
57
  }
52
58
 
53
- get summaries() {
54
- return this._summaries;
59
+ get currentSummary() {
60
+ return this._currentSummary;
61
+ }
62
+
63
+ get previousSummaries() {
64
+ return this._previousSummaries;
55
65
  }
56
66
 
57
67
  get data() {
@@ -96,7 +106,7 @@ module.exports = (() => {
96
106
  function calculateStaticData(item) {
97
107
  const position = item.position;
98
108
  const snapshot = item.position.snapshot;
99
- const summaries = item.summaries;
109
+ const previousSummaries = item.previousSummaries;
100
110
 
101
111
  const data = item._data;
102
112
 
@@ -115,22 +125,8 @@ module.exports = (() => {
115
125
  data.realized = snapshot.gain;
116
126
  data.income = snapshot.income;
117
127
 
118
- const getSummaryTotal = (index) => {
119
- let summaryTotal;
120
-
121
- if (summaries.length > index && summaries[index] !== null) {
122
- const period = summaries[index].period;
123
-
124
- summaryTotal = period.realized.add(period.unrealized).add(period.income);
125
- } else {
126
- summaryTotal = Decimal.ZERO;
127
- }
128
-
129
- return summaryTotal;
130
- };
131
-
132
- data.summaryOneTotal = getSummaryTotal(0);
133
- data.summaryTwoTotal = getSummaryTotal(1);
128
+ data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary);
129
+ data.summaryTotalPrevious = calculateSummaryTotal(array.last(previousSummaries));
134
130
  }
135
131
 
136
132
  function calculatePriceData(item, price) {
@@ -183,6 +179,20 @@ module.exports = (() => {
183
179
  data.unrealizedToday = unrealizedToday;
184
180
  data.unrealizedTodayChange = unrealizedTodayChange;
185
181
  }
182
+
183
+ function calculateSummaryTotal(summary) {
184
+ let returnRef;
185
+
186
+ if (summary) {
187
+ const period = summary.period;
188
+
189
+ returnRef = period.realized.add(period.unrealized).add(period.income);
190
+ } else {
191
+ returnRef = Decimal.ZERO;
192
+ }
193
+
194
+ return returnRef;
195
+ }
186
196
 
187
197
  return PositionItem;
188
198
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.89",
3
+ "version": "1.0.90",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -156,12 +156,13 @@ module.exports = (() => {
156
156
  * start and end dates.
157
157
  *
158
158
  * @public
159
- * @param {Day} startDate
160
- * @param {Day} endDate
159
+ * @return {PositionSummaryRange} range
161
160
  * @return {String}
162
161
  */
163
- describeRange(startDate, endDate) {
164
- return this._descriptionCalculator(startDate, endDate);
162
+ describeRange(range) {
163
+ console.log('range: ', range);
164
+
165
+ return this._descriptionCalculator(range.start, range.end);
165
166
  }
166
167
 
167
168
  /**
@@ -345,20 +346,20 @@ module.exports = (() => {
345
346
  return null;
346
347
  }
347
348
 
348
- function getYearlyRangeDescription(startDate, endDate) {
349
- return endDate.year.toString();
349
+ function getYearlyRangeDescription(start, end) {
350
+ return end.year.toString();
350
351
  }
351
352
 
352
- function getQuarterlyRangeDescription(startDate, endDate) {
353
+ function getQuarterlyRangeDescription(start, end) {
353
354
  return '';
354
355
  }
355
356
 
356
- function getMonthlyRangeDescription(startDate, endDate) {
357
+ function getMonthlyRangeDescription(start, end) {
357
358
  return '';
358
359
  }
359
360
 
360
- function getYearToDateRangeDescription(startDate, endDate) {
361
- return `${endDate.year.toString()} YTD`;
361
+ function getYearToDateRangeDescription(start, end) {
362
+ return `${end.year.toString()} YTD`;
362
363
  }
363
364
 
364
365
  function getFilteredTransactions(transactions) {
@@ -735,12 +736,18 @@ module.exports = (() => {
735
736
  * @public
736
737
  */
737
738
  class PositionContainer {
738
- constructor(portfolios, positions, summaries, definitions, defaultCurrency, summaryFrameType) {
739
+ constructor(portfolios, positions, summaries, definitions, defaultCurrency, summaryFrame) {
739
740
  this._definitions = definitions;
740
741
  this._defaultCurrency = defaultCurrency || Currency.CAD;
742
+
743
+ const previousSummaryFrame = summaryFrame || PositionSummaryFrame.YEARLY;
744
+ const previousSummaryRanges = previousSummaryFrame.getRecentRanges(0);
741
745
 
742
- this._summaryFrame = summaryFrameType || PositionSummaryFrame.YEARLY;
743
- this._summaryRanges = this._summaryFrame.getRecentRanges(1);
746
+ const currentSummaryFrame = PositionSummaryFrame.YTD;
747
+ const currentSummaryRange = array.last(currentSummaryFrame.getRecentRanges(0));
748
+
749
+ this._summaryDescriptionCurrent = previousSummaryFrame.describeRange(array.last(previousSummaryRanges));
750
+ this._summaryDescriptionPrevious = currentSummaryFrame.describeRange(currentSummaryRange);
744
751
 
745
752
  this._portfolios = portfolios.reduce((map, portfolio) => {
746
753
  map[portfolio.portfolio] = portfolio;
@@ -748,15 +755,25 @@ module.exports = (() => {
748
755
  return map;
749
756
  }, { });
750
757
 
751
- this._summaries = summaries.reduce((map, summary) => {
752
- if (this._summaryFrame === summary.frame) {
758
+ this._summariesCurrent = summaries.reduce((map, summary) => {
759
+ if (summary.frame === currentSummaryFrame && currentSummaryRange.start.getIsEqual(summary.start.date) && currentSummaryRange.end.getIsEqual(summary.end.date)) {
760
+ const key = summary.position;
761
+
762
+ map[key] = summary;
763
+ }
764
+
765
+ return map;
766
+ }, { });
767
+
768
+ this._summariesPrevious = summaries.reduce((map, summary) => {
769
+ if (summary.frame === previousSummaryFrame) {
753
770
  const key = summary.position;
754
771
 
755
772
  if (!map.hasOwnProperty(key)) {
756
- map[key] = getSummaryArray(this._summaryRanges);
773
+ map[key] = getSummaryArray(previousSummaryRanges);
757
774
  }
758
775
 
759
- const index = this._summaryRanges.findIndex(r => r.start.getIsEqual(summary.start.date) && r.end.getIsEqual(summary.end.date));
776
+ const index = previousSummaryRanges.findIndex(r => r.start.getIsEqual(summary.start.date) && r.end.getIsEqual(summary.end.date));
760
777
 
761
778
  if (!(index < 0)) {
762
779
  map[key][index] = summary;
@@ -770,9 +787,10 @@ module.exports = (() => {
770
787
  const portfolio = this._portfolios[position.portfolio];
771
788
 
772
789
  if (position) {
773
- const summaries = this._summaries[position.position] || getSummaryArray(this._summaryRanges);
790
+ const currentSummary = this._summariesCurrent[position.position] || null;
791
+ const previousSummaries = this._summariesPrevious[position.position] || getSummaryArray(previousSummaryRanges);
774
792
 
775
- items.push(new PositionItem(portfolio, position, summaries));
793
+ items.push(new PositionItem(portfolio, position, currentSummary, previousSummaries));
776
794
  }
777
795
 
778
796
  return items;
@@ -884,7 +902,25 @@ module.exports = (() => {
884
902
  get defaultCurrency() {
885
903
  return this._defaultCurrency;
886
904
  }
905
+
906
+ getCurrentSummaryDescription() {
907
+ return this._summaryDescriptionCurrent;
908
+ }
909
+
910
+ getPreviousSummaryDescription() {
911
+ return this._summaryDescriptionPrevious;
912
+ }
887
913
 
914
+ startTransaction(executor) {
915
+ assert.argumentIsRequired(executor, 'executor', Function);
916
+
917
+ this._tree.walk(group => group.setSuspended(true), false, false);
918
+
919
+ executor(this);
920
+
921
+ this._tree.walk(group => group.setSuspended(false), false, false);
922
+ }
923
+
888
924
  getSymbols() {
889
925
  return Object.keys(this._symbols);
890
926
  }
@@ -911,16 +947,6 @@ module.exports = (() => {
911
947
 
912
948
  }
913
949
 
914
- startTransaction(executor) {
915
- assert.argumentIsRequired(executor, 'executor', Function);
916
-
917
- this._tree.walk(group => group.setSuspended(true), false, false);
918
-
919
- executor(this);
920
-
921
- this._tree.walk(group => group.setSuspended(false), false, false);
922
- }
923
-
924
950
  getGroup(keys) {
925
951
  const node = keys.reduce((tree, key) => {
926
952
  tree = tree.findChild(group => group.description === key);
@@ -998,8 +1024,8 @@ module.exports = (() => {
998
1024
  this._dataActual.marketPercent = null;
999
1025
  this._dataActual.unrealizedToday = null;
1000
1026
  this._dataActual.total = null;
1001
- this._dataActual.summaryOneTotal = null;
1002
- this._dataActual.summaryTwoTotal = null;
1027
+ this._dataActual.summaryTotalCurrent = null;
1028
+ this._dataActual.summaryTotalPrevious = null;
1003
1029
 
1004
1030
  this._dataFormat.currentPrice = null;
1005
1031
  this._dataFormat.previousPrice = null;
@@ -1013,8 +1039,8 @@ module.exports = (() => {
1013
1039
  this._dataFormat.unrealizedTodayNegative = false;
1014
1040
  this._dataFormat.total = null;
1015
1041
  this._dataFormat.totalNegative = false;
1016
- this._dataFormat.summaryOneTotal = null;
1017
- this._dataFormat.summaryTwoTotal = null;
1042
+ this._dataFormat.summaryTotalCurrent = null;
1043
+ this._dataFormat.summaryTotalPrevious = null;
1018
1044
 
1019
1045
  this._dataFormat.unrealizedTodayNegative = false;
1020
1046
 
@@ -1143,29 +1169,29 @@ module.exports = (() => {
1143
1169
  updates.basis = updates.basis.add(item.data.basis);
1144
1170
  updates.realized = updates.realized.add(item.data.realized);
1145
1171
  updates.income = updates.income.add(item.data.income);
1146
- updates.summaryOneTotal = updates.summaryOneTotal.add(item.data.summaryOneTotal);
1147
- updates.summaryTwoTotal = updates.summaryTwoTotal.add(item.data.summaryTwoTotal);
1172
+ updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(item.data.summaryTotalCurrent);
1173
+ updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(item.data.summaryTotalPrevious);
1148
1174
 
1149
1175
  return updates;
1150
1176
  }, {
1151
1177
  basis: Decimal.ZERO,
1152
1178
  realized: Decimal.ZERO,
1153
1179
  income: Decimal.ZERO,
1154
- summaryOneTotal: Decimal.ZERO,
1155
- summaryTwoTotal: Decimal.ZERO
1180
+ summaryTotalCurrent: Decimal.ZERO,
1181
+ summaryTotalPrevious: Decimal.ZERO
1156
1182
  });
1157
1183
 
1158
1184
  actual.basis = updates.basis;
1159
1185
  actual.realized = updates.realized;
1160
1186
  actual.income = updates.income;
1161
- actual.summaryOneTotal = updates.summaryOneTotal;
1162
- actual.summaryTwoTotal = updates.summaryTwoTotal;
1187
+ actual.summaryTotalCurrent = updates.summaryTotalCurrent;
1188
+ actual.summaryTotalPrevious = updates.summaryTotalPrevious;
1163
1189
 
1164
1190
  format.basis = formatCurrency(actual.basis, currency);
1165
1191
  format.realized = formatCurrency(actual.basis, currency);
1166
1192
  format.income = formatCurrency(actual.income, currency);
1167
- format.summaryOneTotal = formatCurrency(updates.summaryOneTotal, currency);
1168
- format.summaryTwoTotal = formatCurrency(updates.summaryTwoTotal, currency);
1193
+ format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
1194
+ format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
1169
1195
  }
1170
1196
 
1171
1197
  function calculatePriceData(group, item, forceRefresh) {
@@ -1326,7 +1352,8 @@ module.exports = (() => {
1326
1352
  })();
1327
1353
 
1328
1354
  },{"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19}],7:[function(require,module,exports){
1329
- const assert = require('@barchart/common-js/lang/assert'),
1355
+ const array = require('@barchart/common-js/lang/array'),
1356
+ assert = require('@barchart/common-js/lang/assert'),
1330
1357
  Decimal = require('@barchart/common-js/lang/Decimal'),
1331
1358
  Event = require('@barchart/common-js/messaging/Event'),
1332
1359
  is = require('@barchart/common-js/lang/is');
@@ -1340,10 +1367,12 @@ module.exports = (() => {
1340
1367
  * @public
1341
1368
  */
1342
1369
  class PositionItem {
1343
- constructor(portfolio, position, summaries) {
1370
+ constructor(portfolio, position, currentSummary, previousSummaries) {
1344
1371
  this._portfolio = portfolio;
1345
1372
  this._position = position;
1346
- this._summaries = summaries || [ ];
1373
+
1374
+ this._currentSummary = currentSummary || null;
1375
+ this._previousSummaries = previousSummaries || [ ];
1347
1376
 
1348
1377
  this._data = { };
1349
1378
 
@@ -1360,6 +1389,9 @@ module.exports = (() => {
1360
1389
 
1361
1390
  this._data.realized = null;
1362
1391
  this._data.income = null;
1392
+
1393
+ this._data.summaryTotalCurrent = null;
1394
+ this._data.summaryTotalPrevious = null;
1363
1395
 
1364
1396
  this._excluded = false;
1365
1397
 
@@ -1378,8 +1410,12 @@ module.exports = (() => {
1378
1410
  return this._position;
1379
1411
  }
1380
1412
 
1381
- get summaries() {
1382
- return this._summaries;
1413
+ get currentSummary() {
1414
+ return this._currentSummary;
1415
+ }
1416
+
1417
+ get previousSummaries() {
1418
+ return this._previousSummaries;
1383
1419
  }
1384
1420
 
1385
1421
  get data() {
@@ -1424,7 +1460,7 @@ module.exports = (() => {
1424
1460
  function calculateStaticData(item) {
1425
1461
  const position = item.position;
1426
1462
  const snapshot = item.position.snapshot;
1427
- const summaries = item.summaries;
1463
+ const previousSummaries = item.previousSummaries;
1428
1464
 
1429
1465
  const data = item._data;
1430
1466
 
@@ -1443,22 +1479,8 @@ module.exports = (() => {
1443
1479
  data.realized = snapshot.gain;
1444
1480
  data.income = snapshot.income;
1445
1481
 
1446
- const getSummaryTotal = (index) => {
1447
- let summaryTotal;
1448
-
1449
- if (summaries.length > index && summaries[index] !== null) {
1450
- const period = summaries[index].period;
1451
-
1452
- summaryTotal = period.realized.add(period.unrealized).add(period.income);
1453
- } else {
1454
- summaryTotal = Decimal.ZERO;
1455
- }
1456
-
1457
- return summaryTotal;
1458
- };
1459
-
1460
- data.summaryOneTotal = getSummaryTotal(0);
1461
- data.summaryTwoTotal = getSummaryTotal(1);
1482
+ data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary);
1483
+ data.summaryTotalPrevious = calculateSummaryTotal(array.last(previousSummaries));
1462
1484
  }
1463
1485
 
1464
1486
  function calculatePriceData(item, price) {
@@ -1511,11 +1533,25 @@ module.exports = (() => {
1511
1533
  data.unrealizedToday = unrealizedToday;
1512
1534
  data.unrealizedTodayChange = unrealizedTodayChange;
1513
1535
  }
1536
+
1537
+ function calculateSummaryTotal(summary) {
1538
+ let returnRef;
1539
+
1540
+ if (summary) {
1541
+ const period = summary.period;
1542
+
1543
+ returnRef = period.realized.add(period.unrealized).add(period.income);
1544
+ } else {
1545
+ returnRef = Decimal.ZERO;
1546
+ }
1547
+
1548
+ return returnRef;
1549
+ }
1514
1550
 
1515
1551
  return PositionItem;
1516
1552
  })();
1517
1553
 
1518
- },{"./../data/InstrumentType":1,"@barchart/common-js/lang/Decimal":13,"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19,"@barchart/common-js/messaging/Event":20}],8:[function(require,module,exports){
1554
+ },{"./../data/InstrumentType":1,"@barchart/common-js/lang/Decimal":13,"@barchart/common-js/lang/array":16,"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19,"@barchart/common-js/messaging/Event":20}],8:[function(require,module,exports){
1519
1555
  'use strict';
1520
1556
 
1521
1557
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();