@barchart/portfolio-api-common 1.2.129 → 1.2.133

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.
@@ -11,9 +11,10 @@ module.exports = (() => {
11
11
  *
12
12
  * @public
13
13
  * @extends {Enum}
14
+ * @param {String} code
14
15
  * @param {String} description
15
16
  * @param {String} alternateDescription
16
- * @param {String} code
17
+ * @param {Boolean} canExistEmpty
17
18
  * @param {Boolean} canReinvest
18
19
  * @param {Boolean} canShort
19
20
  * @param {Boolean} canSwitchDirection
@@ -25,10 +26,11 @@ module.exports = (() => {
25
26
  * @param {Function} generator
26
27
  */
27
28
  class InstrumentType extends Enum {
28
- constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, roundQuantity, strictOrdering, generator) {
29
+ constructor(code, description, alternateDescription, canExistEmpty, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, roundQuantity, strictOrdering, generator) {
29
30
  super(code, description);
30
31
 
31
32
  assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
33
+ assert.argumentIsRequired(canExistEmpty, 'canExistEmpty', Boolean);
32
34
  assert.argumentIsRequired(canReinvest, 'canReinvest', Boolean);
33
35
  assert.argumentIsRequired(canShort, 'canShort', Boolean);
34
36
  assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
@@ -40,6 +42,8 @@ module.exports = (() => {
40
42
  assert.argumentIsRequired(generator, 'generator', Function);
41
43
 
42
44
  this._alternateDescription = alternateDescription;
45
+
46
+ this._canExistEmpty = canExistEmpty;
43
47
  this._canReinvest = canReinvest;
44
48
  this._canShort = canShort;
45
49
  this._canSwitchDirection = canSwitchDirection;
@@ -62,6 +66,16 @@ module.exports = (() => {
62
66
  return this._alternateDescription;
63
67
  }
64
68
 
69
+ /**
70
+ * Indicates if the position can exist without any associated transactions.
71
+ *
72
+ * @public
73
+ * @returns {Boolean}
74
+ */
75
+ get canExistEmpty() {
76
+ return this._canExistEmpty;
77
+ }
78
+
65
79
  /**
66
80
  * Indicates if the instrument type allows automatic reinvestment.
67
81
  *
@@ -242,10 +256,10 @@ module.exports = (() => {
242
256
  }
243
257
  }
244
258
 
245
- const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
246
- const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
247
- const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
248
- const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
259
+ const cash = new InstrumentType('CASH', 'cash', 'Cash', true, false, false, true, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
260
+ const equity = new InstrumentType('EQUITY', 'equity', 'Equities', false, true, true, false, true, true, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
261
+ const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', false, true, false, false, true, true, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
262
+ const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
249
263
 
250
264
  const map = { };
251
265
 
@@ -25,7 +25,7 @@ module.exports = (() => {
25
25
  * @param {Boolean} system
26
26
  */
27
27
  class TransactionType extends Enum {
28
- constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant, system) {
28
+ constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
29
29
  super(code, description);
30
30
 
31
31
  assert.argumentIsRequired(display, 'display', String);
@@ -39,7 +39,6 @@ module.exports = (() => {
39
39
  assert.argumentIsRequired(corporateAction, 'corporateAction', Boolean);
40
40
  assert.argumentIsRequired(initial, 'initial', Boolean);
41
41
  assert.argumentIsRequired(significant, 'significant', Boolean);
42
- assert.argumentIsRequired(system, 'system', Boolean);
43
42
 
44
43
  this._display = display;
45
44
  this._sequence = sequence;
@@ -52,7 +51,6 @@ module.exports = (() => {
52
51
  this._corporateAction = corporateAction;
53
52
  this._initial = initial;
54
53
  this._significant = significant;
55
- this._system = system;
56
54
  }
57
55
 
58
56
  /**
@@ -179,16 +177,6 @@ module.exports = (() => {
179
177
  return this._significant;
180
178
  }
181
179
 
182
- /**
183
- * System transactions are generated automatically.
184
- *
185
- * @public
186
- * @returns {Boolean}
187
- */
188
- get system() {
189
- return this._system;
190
- }
191
-
192
180
  /**
193
181
  * A purchase.
194
182
  *
@@ -414,29 +402,29 @@ module.exports = (() => {
414
402
  }
415
403
  }
416
404
 
417
- const buy = new TransactionType('B', 'Buy', 'Buy', 0, true, false, false, true, false, false, false, true, true, false);
418
- const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true, false);
419
- const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true, false);
420
- const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true, false);
421
- const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false, true);
422
- const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false, true);
423
- const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false, true);
424
- const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false, true);
425
- const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false, false);
426
- const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false, false);
427
- const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, false, true);
428
-
429
- const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false, true);
430
- const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false, true);
431
- const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', 1, false, false, false, true, false, false, true, false, false, true);
432
-
433
- const deposit = new TransactionType('D', 'Deposit', 'Deposit', 0, false, false, false, false, false, false, false, true, true, false);
434
- const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', 0, false, false, false, false, false, false, false, true, true, false);
435
- const debit = new TransactionType('DR', 'Debit', 'Debit', 0, false, false, false, false, false, false, false, true, true, true);
436
- const credit = new TransactionType('CR', 'Credit', 'Credit', 0, false, false, false, false, false, false, false, true, true, true);
437
-
438
- const valuation = new TransactionType('V', 'Valuation', 'Valuation', 0, false, false, false, false, false, false, false, false, false, false);
439
- const income = new TransactionType('I', 'Income', 'Income', 0, false, false, true, false, false, false, false, false, false, false);
405
+ const buy = new TransactionType('B', 'Buy', 'Buy', 0, true, false, false, true, false, false, false, true, true);
406
+ const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
407
+ const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
408
+ const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true);
409
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
410
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
411
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
412
+ const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
413
+ const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false);
414
+ const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false);
415
+ const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, false);
416
+
417
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false);
418
+ const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false);
419
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', 1, false, false, false, true, false, false, true, false, false);
420
+
421
+ const deposit = new TransactionType('D', 'Deposit', 'Deposit', 0, false, false, false, false, false, false, false, true, true);
422
+ const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', 0, false, false, false, false, false, false, false, true, true);
423
+ const debit = new TransactionType('DR', 'Debit', 'Debit', 0, false, false, false, false, false, false, false, true, true);
424
+ const credit = new TransactionType('CR', 'Credit', 'Credit', 0, false, false, false, false, false, false, false, true, true);
425
+
426
+ const valuation = new TransactionType('V', 'Valuation', 'Valuation', 0, false, false, false, false, false, false, false, false, false);
427
+ const income = new TransactionType('I', 'Income', 'Income', 0, false, false, true, false, false, false, false, false, false);
440
428
 
441
429
  return TransactionType;
442
430
  })();
@@ -125,7 +125,6 @@ module.exports = (() => {
125
125
  f.date = t.date;
126
126
  f.type = t.type.display;
127
127
  f.code = t.type.code;
128
- f.system = t.type.system;
129
128
  f.sequence = t.sequence;
130
129
  f.position = t.position;
131
130
  };
@@ -137,6 +137,9 @@ module.exports = (() => {
137
137
  this._dataActual.marketChange = null;
138
138
  this._dataActual.marketChangePercent = null;
139
139
  this._dataActual.cashTotal = null;
140
+ this._dataActual.periodDivisorCurrent = null;
141
+ this._dataActual.periodDivisorPrevious = null;
142
+ this._dataActual.periodDivisorPrevious2 = null;
140
143
 
141
144
  this._dataFormat.currentPrice = null;
142
145
  this._dataFormat.basis = null;
@@ -168,33 +171,25 @@ module.exports = (() => {
168
171
 
169
172
  this._dataActual.periodPrice = null;
170
173
  this._dataActual.periodPricePrevious = null;
171
- this._dataActual.periodRealized = null;
172
- this._dataActual.periodRealizedPrevious = null;
173
- this._dataActual.periodRealizedPrevious2 = null;
174
- this._dataActual.periodRealizedBasis = null;
175
- this._dataActual.periodRealizedBasisPrevious = null;
176
- this._dataActual.periodRealizedBasisPrevious2 = null;
177
- this._dataActual.periodUnrealized = null;
178
- this._dataActual.periodUnrealizedPrevious = null;
179
- this._dataActual.periodUnrealizedPrevious2 = null;
180
- this._dataActual.periodUnrealizedBasis = null;
181
- this._dataActual.periodUnrealizedBasisPrevious = null;
182
- this._dataActual.periodUnrealizedBasisPrevious2 = null;
183
- this._dataActual.periodIncome = null;
184
174
 
185
175
  this._dataFormat.periodPrice = null;
186
176
  this._dataFormat.periodPricePrevious = null;
177
+
178
+ this._dataActual.periodIncome = null;
179
+ this._dataActual.periodRealized = null;
180
+ this._dataActual.periodUnrealized = null;
181
+
182
+ this._dataFormat.periodIncome = null;
187
183
  this._dataFormat.periodRealized = null;
188
184
  this._dataFormat.periodUnrealized = null;
189
- this._dataFormat.periodIncome = null;
190
185
 
191
186
  this._dataActual.periodPercent = null;
192
- this._dataActual.periodPreviousPercent = null;
193
- this._dataActual.periodPrevious2Percent = null;
187
+ this._dataActual.periodPercentPrevious = null;
188
+ this._dataActual.periodPercentPrevious2 = null;
194
189
 
195
190
  this._dataFormat.periodPercent = null;
196
- this._dataFormat.periodPreviousPercent = null;
197
- this._dataFormat.periodPrevious2Percent = null;
191
+ this._dataFormat.periodPercentPrevious = null;
192
+ this._dataFormat.periodPercentPrevious2 = null;
198
193
 
199
194
  this._items.forEach((item) => {
200
195
  bindItem.call(this, item);
@@ -686,9 +681,9 @@ module.exports = (() => {
686
681
  updates.realized = updates.realized.add(translate(item, item.data.realized));
687
682
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
688
683
  updates.income = updates.income.add(translate(item, item.data.income));
689
- updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
690
- updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
691
- updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.summaryTotalPrevious2));
684
+ updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.periodGain));
685
+ updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.periodGainPrevious));
686
+ updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.periodGainPrevious2));
692
687
  updates.marketPrevious = updates.marketPrevious.add(translate(item, item.data.marketPrevious));
693
688
  updates.marketPrevious2 = updates.marketPrevious2.add(translate(item, item.data.marketPrevious2));
694
689
 
@@ -700,6 +695,10 @@ module.exports = (() => {
700
695
  updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
701
696
  }
702
697
 
698
+ updates.periodDivisorCurrent = updates.periodDivisorCurrent.add(translate(item, item.data.periodDivisor));
699
+ updates.periodDivisorPrevious = updates.periodDivisorPrevious.add(translate(item, item.data.periodDivisorPrevious));
700
+ updates.periodDivisorPrevious2 = updates.periodDivisorPrevious2.add(translate(item, item.data.periodDivisorPrevious2));
701
+
703
702
  return updates;
704
703
  }, {
705
704
  basis: Decimal.ZERO,
@@ -715,6 +714,9 @@ module.exports = (() => {
715
714
  periodUnrealized: Decimal.ZERO,
716
715
  periodIncome: Decimal.ZERO,
717
716
  cashTotal: Decimal.ZERO,
717
+ periodDivisorCurrent: Decimal.ZERO,
718
+ periodDivisorPrevious: Decimal.ZERO,
719
+ periodDivisorPrevious2: Decimal.ZERO
718
720
  });
719
721
 
720
722
  actual.basis = updates.basis;
@@ -730,12 +732,16 @@ module.exports = (() => {
730
732
  actual.periodUnrealized = updates.periodUnrealized;
731
733
  actual.periodIncome = updates.periodIncome;
732
734
  actual.cashTotal = updates.cashTotal;
735
+ actual.periodDivisorCurrent = updates.periodDivisorCurrent;
736
+ actual.periodDivisorPrevious = updates.periodDivisorPrevious;
737
+ actual.periodDivisorPrevious2 = updates.periodDivisorPrevious2;
733
738
 
734
739
  format.basis = formatCurrency(actual.basis, currency);
735
740
  format.realized = formatCurrency(actual.realized, currency);
736
741
  format.unrealized = formatCurrency(actual.unrealized, currency);
737
742
  format.income = formatCurrency(actual.income, currency);
738
743
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
744
+ format.summaryTotalCurrentNegative = updates.summaryTotalCurrent.getIsNegative();
739
745
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
740
746
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
741
747
  format.summaryTotalPrevious2 = formatCurrency(updates.summaryTotalPrevious2, currency);
@@ -770,25 +776,9 @@ module.exports = (() => {
770
776
  format.periodPrice = formatCurrency(actual.periodPrice, currency);
771
777
  format.periodPricePrevious = formatCurrency(actual.periodPricePrevious, currency);
772
778
 
773
- actual.periodRealized = item.data.periodRealized;
774
- actual.periodRealizedPrevious = item.data.periodRealizedPrevious;
775
- actual.periodRealizedPrevious2 = item.data.periodRealizedPrevious2;
776
-
777
- actual.periodRealizedBasis = item.data.periodRealizedBasis;
778
- actual.periodRealizedBasisPrevious = item.data.periodRealizedBasisPrevious;
779
- actual.periodRealizedBasisPrevious2 = item.data.periodRealizedBasisPrevious2;
780
-
781
- actual.periodUnrealized = item.data.periodUnrealized;
782
- actual.periodUnrealizedPrevious = item.data.periodUnrealizedPrevious;
783
- actual.periodUnrealizedPrevious2 = item.data.periodUnrealizedPrevious2;
784
-
785
- actual.periodUnrealizedBasis = item.data.periodUnrealizedBasis;
786
- actual.periodUnrealizedBasisPrevious = item.data.periodUnrealizedBasisPrevious;
787
- actual.periodUnrealizedBasisPrevious2 = item.data.periodUnrealizedBasisPrevious2;
788
-
789
- actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodRealizedBasis, actual.periodUnrealizedBasis);
790
- actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodRealizedBasisPrevious, actual.periodUnrealizedBasisPrevious);
791
- actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodRealizedBasisPrevious2, actual.periodUnrealizedBasisPrevious2);
779
+ actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
780
+ actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
781
+ actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
792
782
 
793
783
  format.periodPercent = formatPercent(actual.periodPercent, 2);
794
784
  format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
@@ -847,7 +837,7 @@ module.exports = (() => {
847
837
  updates.marketAbsolute = updates.marketAbsolute.add(translate(item, item.data.marketAbsolute));
848
838
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
849
839
  updates.unrealizedToday = updates.unrealizedToday.add(translate(item, item.data.unrealizedToday));
850
- updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
840
+ updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.periodGain));
851
841
 
852
842
  return updates;
853
843
  }, {
@@ -865,7 +855,7 @@ module.exports = (() => {
865
855
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
866
856
  unrealized: actual.unrealized.add(translate(item, item.data.unrealizedChange)),
867
857
  unrealizedToday: actual.unrealizedToday.add(translate(item, item.data.unrealizedTodayChange)),
868
- summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrentChange))
858
+ summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange))
869
859
  };
870
860
  }
871
861
 
@@ -921,7 +911,7 @@ module.exports = (() => {
921
911
  if (group.single && item) {
922
912
  actual.periodUnrealized = item.data.periodUnrealized;
923
913
 
924
- actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodRealizedBasis, actual.periodUnrealizedBasis);
914
+ actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
925
915
  format.periodPercent = formatPercent(actual.periodPercent, 2);
926
916
  }
927
917
  }
@@ -982,11 +972,8 @@ module.exports = (() => {
982
972
  }
983
973
  }
984
974
 
985
- function calculatePeriodPercent(periodSummaryTotal, realizedBasis, unrealizedBasis) {
986
- const numerator = periodSummaryTotal;
987
- const denominator = realizedBasis.add(unrealizedBasis);
988
-
989
- return denominator.getIsZero() ? Decimal.ZERO : numerator.divide(denominator);
975
+ function calculatePeriodPercent(periodSummaryTotal, periodDivisor) {
976
+ return periodDivisor.getIsZero() ? Decimal.ZERO : periodSummaryTotal.divide(periodDivisor);
990
977
  }
991
978
 
992
979
  const unchanged = { up: false, down: false };
@@ -62,12 +62,6 @@ module.exports = (() => {
62
62
  this._data.unrealized = null;
63
63
  this._data.unrealizedChange = null;
64
64
 
65
- this._data.summaryTotalCurrent = null;
66
- this._data.summaryTotalCurrentChange = null;
67
-
68
- this._data.summaryTotalPrevious = null;
69
- this._data.summaryTotalPrevious2 = null;
70
-
71
65
  this._data.marketPrevious = null;
72
66
  this._data.marketPrevious2 = null;
73
67
 
@@ -78,26 +72,24 @@ module.exports = (() => {
78
72
  this._data.income = null;
79
73
  this._data.basisPrice = null;
80
74
 
75
+ this._data.periodIncome = null;
81
76
  this._data.periodRealized = null;
82
- this._data.periodRealizedPrevious = null;
83
- this._data.periodRealizedPrevious2 = null;
77
+ this._data.periodUnrealized = null;
84
78
 
85
- this._data.periodRealizedBasis = null;
86
- this._data.periodRealizedBasisPrevious = null;
87
- this._data.periodRealizedBasisPrevious2 = null;
79
+ this._data.periodPrice = null;
80
+ this._data.periodPricePrevious = null;
88
81
 
89
- this._data.periodUnrealized = null;
90
- this._data.periodUnrealizedPrevious = null;
91
- this._data.periodUnrealizedPrevious2 = null;
82
+ this._data.periodGain = null;
83
+ this._data.periodGainChange = null;
92
84
 
93
- this._data.periodUnrealizedBasis = null;
94
- this._data.periodUnrealizedBasisPrevious = null;
95
- this._data.periodUnrealizedBasisPrevious2 = null;
85
+ this._data.periodGainPrevious = null;
86
+ this._data.periodGainPrevious2 = null;
96
87
 
97
- this._data.periodIncome = null;
88
+ this._data.periodDivisor = null;
89
+ this._data.periodDivisorChange = null;
98
90
 
99
- this._data.periodPrice = null;
100
- this._data.periodPricePrevious = null;
91
+ this._data.periodDivisorPrevious = null;
92
+ this._data.periodDivisorPrevious2 = null;
101
93
 
102
94
  this._data.newsExists = false;
103
95
  this._data.fundamental = { };
@@ -417,31 +409,21 @@ module.exports = (() => {
417
409
 
418
410
  data.income = snapshot.income;
419
411
 
420
- data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary, previousSummary1);
421
- data.summaryTotalPrevious = calculateSummaryTotal(previousSummary1, previousSummary2);
422
- data.summaryTotalPrevious2 = calculateSummaryTotal(previousSummary2, previousSummary3);
423
-
424
412
  data.marketPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.value;
425
413
  data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
426
414
  data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
427
415
 
428
- data.periodRealized = calculatePeriodRealized(item.currentSummary, previousSummary1);
429
- data.periodRealizedPrevious = calculatePeriodRealized(previousSummary1, previousSummary2);
430
- data.periodRealizedPrevious2 = calculatePeriodRealized(previousSummary2, previousSummary3);
431
-
432
- data.periodRealizedBasis = calculatePeriodRealizedBasis(item.currentSummary, previousSummary1);
433
- data.periodRealizedBasisPrevious = calculatePeriodRealizedBasis(previousSummary1, previousSummary2);
434
- data.periodRealizedBasisPrevious2 = calculatePeriodRealizedBasis(previousSummary2, previousSummary3);
435
-
436
- data.periodUnrealized = calculatePeriodUnrealized(item.currentSummary, previousSummary1);
437
- data.periodUnrealizedPrevious = calculatePeriodUnrealized(previousSummary1, previousSummary2);
438
- data.periodUnrealizedPrevious2 = calculatePeriodUnrealized(previousSummary2, previousSummary3);
439
-
440
- data.periodUnrealizedBasis = calculatePeriodUnrealizedBasis(item.currentSummary, previousSummary1);
441
- data.periodUnrealizedBasisPrevious = calculatePeriodUnrealizedBasis(previousSummary1, previousSummary2);
442
- data.periodUnrealizedBasisPrevious2 = calculatePeriodUnrealizedBasis(previousSummary2, previousSummary3);
443
-
444
- data.periodIncome = calculatePeriodIncome(item.currentSummary, previousSummary1);
416
+ data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
417
+ data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
418
+ data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
419
+
420
+ data.periodGain = calculatePeriodGain(currentSummary, previousSummary1);
421
+ data.periodGainPrevious = calculatePeriodGain(previousSummary1, previousSummary2);
422
+ data.periodGainPrevious2 = calculatePeriodGain(previousSummary2, previousSummary3);
423
+
424
+ data.periodDivisor = calculatePeriodDivisor(currentSummary, previousSummary1);
425
+ data.periodDivisorPrevious = calculatePeriodDivisor(previousSummary1, previousSummary2);
426
+ data.periodDivisorPrevious2 = calculatePeriodDivisor(previousSummary2, previousSummary3);
445
427
 
446
428
  if (snapshot.open.getIsZero()) {
447
429
  data.basisPrice = Decimal.ZERO;
@@ -465,7 +447,6 @@ module.exports = (() => {
465
447
  function calculatePriceData(item, price) {
466
448
  const position = item.position;
467
449
  const snapshot = getSnapshot(position, item.currentSummary, item._reporting);
468
- const previousSummaries = item.previousSummaries;
469
450
 
470
451
  const data = item._data;
471
452
 
@@ -526,10 +507,9 @@ module.exports = (() => {
526
507
  data.unrealizedTodayChange = unrealizedTodayChange;
527
508
 
528
509
  const currentSummary = item.currentSummary;
510
+ const previousSummary = getPreviousSummary(item.previousSummaries, 1);
529
511
 
530
512
  if (currentSummary && position.instrument.type !== InstrumentType.CASH) {
531
- const previousSummary = getPreviousSummary(previousSummaries, 1);
532
-
533
513
  let priceToUse;
534
514
 
535
515
  if (price) {
@@ -543,8 +523,6 @@ module.exports = (() => {
543
523
  }
544
524
 
545
525
  if (priceToUse !== null) {
546
- const period = currentSummary.period;
547
-
548
526
  let unrealized = currentSummary.end.open.multiply(priceToUse).add(currentSummary.end.basis);
549
527
  let unrealizedChange;
550
528
 
@@ -554,115 +532,79 @@ module.exports = (() => {
554
532
  unrealizedChange = Decimal.ZERO;
555
533
  }
556
534
 
557
- let summaryTotalCurrent = period.realized.add(period.income).add(unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
558
- let summaryTotalCurrentChange;
535
+ data.unrealized = unrealized;
536
+ data.unrealizedChange = unrealizedChange;
559
537
 
560
- if (data.summaryTotalCurrent !== null) {
561
- summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
538
+ let periodGain = calculatePeriodGain(currentSummary, previousSummary, priceToUse);
539
+ let periodGainChange;
540
+
541
+ if (data.periodGain !== null) {
542
+ periodGainChange = periodGain.subtract(data.periodGain);
562
543
  } else {
563
- summaryTotalCurrentChange = Decimal.ZERO;
544
+ periodGainChange = Decimal.ZERO;
564
545
  }
565
546
 
566
- data.summaryTotalCurrent = summaryTotalCurrent;
567
- data.summaryTotalCurrentChange = summaryTotalCurrentChange;
568
-
569
- data.unrealized = unrealized;
570
- data.unrealizedChange = unrealizedChange;
571
-
572
- data.periodUnrealized = calculatePeriodUnrealized(item.currentSummary, previousSummary, data.unrealized);
573
- data.periodUnrealizedChange = unrealizedChange;
547
+ data.periodGain = periodGain;
548
+ data.periodGainChange = periodGainChange;
574
549
  } else {
575
- data.summaryTotalCurrentChange = Decimal.ZERO;
576
-
577
550
  data.unrealized = Decimal.ZERO;
578
551
  data.unrealizedChange = Decimal.ZERO;
579
552
 
580
- data.periodUnrealizedChange = Decimal.ZERO;
553
+ data.periodGainChange = Decimal.ZERO;
581
554
  }
582
555
  } else {
583
- data.summaryTotalCurrentChange = Decimal.ZERO;
584
-
585
556
  data.unrealized = Decimal.ZERO;
586
557
  data.unrealizedChange = Decimal.ZERO;
587
- }
588
- }
589
-
590
- function calculateSummaryTotal(currentSummary, previousSummary) {
591
- let returnRef;
592
-
593
- if (currentSummary) {
594
- const period = currentSummary.period;
595
558
 
596
- returnRef = period.realized.add(period.income).add(period.unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
597
- } else {
598
- returnRef = Decimal.ZERO;
559
+ data.periodGainChange = Decimal.ZERO;
599
560
  }
600
-
601
- return returnRef;
602
561
  }
603
562
 
604
- function calculatePeriodRealized(currentSummary, previousSummary) {
563
+ function calculatePeriodGain(currentSummary, previousSummary, overridePrice) {
605
564
  let returnRef;
606
565
 
607
566
  if (currentSummary) {
608
- const period = currentSummary.period;
567
+ let startValue;
609
568
 
610
- returnRef = period.realized;
611
- } else {
612
- returnRef = Decimal.ZERO;
613
- }
569
+ if (previousSummary) {
570
+ startValue = previousSummary.end.value;
571
+ } else {
572
+ startValue = Decimal.ZERO;
573
+ }
614
574
 
615
- return returnRef;
616
- }
575
+ let endValue;
617
576
 
618
- function calculatePeriodRealizedBasis(currentSummary, previousSummary) {
619
- let returnRef;
577
+ if (overridePrice) {
578
+ endValue = currentSummary.end.open.multiply(overridePrice);
579
+ } else {
580
+ endValue = currentSummary.end.value;
581
+ }
620
582
 
621
- if (currentSummary) {
622
- const period = currentSummary.period;
583
+ const valueChange = endValue.subtract(startValue);
584
+ const tradeChange = currentSummary.period.sells.subtract(currentSummary.period.buys);
585
+ const incomeChange = currentSummary.period.income;
623
586
 
624
- returnRef = period.sells.subtract(calculatePeriodRealized(currentSummary, previousSummary));
587
+ returnRef = valueChange.add(tradeChange).add(incomeChange);
625
588
  } else {
626
589
  returnRef = Decimal.ZERO;
627
590
  }
628
591
 
629
592
  return returnRef;
630
593
  }
631
-
632
- function calculatePeriodUnrealized(currentSummary, previousSummary, override) {
633
- let returnRef;
634
-
635
- if (currentSummary) {
636
- const period = currentSummary.period;
637
- const unrealized = override || period.unrealized;
638
-
639
- returnRef = unrealized.subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
640
- } else {
641
- returnRef = Decimal.ZERO;
642
- }
643
594
 
644
- return returnRef;
645
- }
646
-
647
- function calculatePeriodUnrealizedBasis(currentSummary, previousSummary) {
595
+ function calculatePeriodDivisor(currentSummary, previousSummary) {
648
596
  let returnRef;
649
597
 
650
598
  if (currentSummary) {
651
- returnRef = currentSummary.end.basis.absolute();
652
- } else {
653
- returnRef = Decimal.ZERO;
654
- }
599
+ let startValue;
655
600
 
656
- return returnRef;
657
- }
658
-
659
- function calculatePeriodIncome(currentSummary, previousSummary) {
660
- let returnRef;
661
-
662
- if (currentSummary) {
663
- const period = currentSummary.period;
601
+ if (previousSummary) {
602
+ startValue = previousSummary.end.value;
603
+ } else {
604
+ startValue = Decimal.ZERO;
605
+ }
664
606
 
665
- returnRef = period.income;
607
+ returnRef = startValue.add(currentSummary.period.buys);
666
608
  } else {
667
609
  returnRef = Decimal.ZERO;
668
610
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.129",
3
+ "version": "1.2.133",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -12,9 +12,10 @@ module.exports = (() => {
12
12
  *
13
13
  * @public
14
14
  * @extends {Enum}
15
+ * @param {String} code
15
16
  * @param {String} description
16
17
  * @param {String} alternateDescription
17
- * @param {String} code
18
+ * @param {Boolean} canExistEmpty
18
19
  * @param {Boolean} canReinvest
19
20
  * @param {Boolean} canShort
20
21
  * @param {Boolean} canSwitchDirection
@@ -26,10 +27,11 @@ module.exports = (() => {
26
27
  * @param {Function} generator
27
28
  */
28
29
  class InstrumentType extends Enum {
29
- constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, roundQuantity, strictOrdering, generator) {
30
+ constructor(code, description, alternateDescription, canExistEmpty, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, roundQuantity, strictOrdering, generator) {
30
31
  super(code, description);
31
32
 
32
33
  assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
34
+ assert.argumentIsRequired(canExistEmpty, 'canExistEmpty', Boolean);
33
35
  assert.argumentIsRequired(canReinvest, 'canReinvest', Boolean);
34
36
  assert.argumentIsRequired(canShort, 'canShort', Boolean);
35
37
  assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
@@ -41,6 +43,8 @@ module.exports = (() => {
41
43
  assert.argumentIsRequired(generator, 'generator', Function);
42
44
 
43
45
  this._alternateDescription = alternateDescription;
46
+
47
+ this._canExistEmpty = canExistEmpty;
44
48
  this._canReinvest = canReinvest;
45
49
  this._canShort = canShort;
46
50
  this._canSwitchDirection = canSwitchDirection;
@@ -63,6 +67,16 @@ module.exports = (() => {
63
67
  return this._alternateDescription;
64
68
  }
65
69
 
70
+ /**
71
+ * Indicates if the position can exist without any associated transactions.
72
+ *
73
+ * @public
74
+ * @returns {Boolean}
75
+ */
76
+ get canExistEmpty() {
77
+ return this._canExistEmpty;
78
+ }
79
+
66
80
  /**
67
81
  * Indicates if the instrument type allows automatic reinvestment.
68
82
  *
@@ -243,10 +257,10 @@ module.exports = (() => {
243
257
  }
244
258
  }
245
259
 
246
- const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
247
- const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
248
- const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
249
- const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
260
+ const cash = new InstrumentType('CASH', 'cash', 'Cash', true, false, false, true, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
261
+ const equity = new InstrumentType('EQUITY', 'equity', 'Equities', false, true, true, false, true, true, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
262
+ const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', false, true, false, false, true, true, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
263
+ const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
250
264
 
251
265
  const map = { };
252
266
 
@@ -766,7 +780,7 @@ module.exports = (() => {
766
780
  * @param {Boolean} system
767
781
  */
768
782
  class TransactionType extends Enum {
769
- constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant, system) {
783
+ constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
770
784
  super(code, description);
771
785
 
772
786
  assert.argumentIsRequired(display, 'display', String);
@@ -780,7 +794,6 @@ module.exports = (() => {
780
794
  assert.argumentIsRequired(corporateAction, 'corporateAction', Boolean);
781
795
  assert.argumentIsRequired(initial, 'initial', Boolean);
782
796
  assert.argumentIsRequired(significant, 'significant', Boolean);
783
- assert.argumentIsRequired(system, 'system', Boolean);
784
797
 
785
798
  this._display = display;
786
799
  this._sequence = sequence;
@@ -793,7 +806,6 @@ module.exports = (() => {
793
806
  this._corporateAction = corporateAction;
794
807
  this._initial = initial;
795
808
  this._significant = significant;
796
- this._system = system;
797
809
  }
798
810
 
799
811
  /**
@@ -920,16 +932,6 @@ module.exports = (() => {
920
932
  return this._significant;
921
933
  }
922
934
 
923
- /**
924
- * System transactions are generated automatically.
925
- *
926
- * @public
927
- * @returns {Boolean}
928
- */
929
- get system() {
930
- return this._system;
931
- }
932
-
933
935
  /**
934
936
  * A purchase.
935
937
  *
@@ -1155,29 +1157,29 @@ module.exports = (() => {
1155
1157
  }
1156
1158
  }
1157
1159
 
1158
- const buy = new TransactionType('B', 'Buy', 'Buy', 0, true, false, false, true, false, false, false, true, true, false);
1159
- const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true, false);
1160
- const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true, false);
1161
- const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true, false);
1162
- const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false, true);
1163
- const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false, true);
1164
- const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false, true);
1165
- const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false, true);
1166
- const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false, false);
1167
- const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false, false);
1168
- const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, false, true);
1169
-
1170
- const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false, true);
1171
- const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false, true);
1172
- const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', 1, false, false, false, true, false, false, true, false, false, true);
1173
-
1174
- const deposit = new TransactionType('D', 'Deposit', 'Deposit', 0, false, false, false, false, false, false, false, true, true, false);
1175
- const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', 0, false, false, false, false, false, false, false, true, true, false);
1176
- const debit = new TransactionType('DR', 'Debit', 'Debit', 0, false, false, false, false, false, false, false, true, true, true);
1177
- const credit = new TransactionType('CR', 'Credit', 'Credit', 0, false, false, false, false, false, false, false, true, true, true);
1178
-
1179
- const valuation = new TransactionType('V', 'Valuation', 'Valuation', 0, false, false, false, false, false, false, false, false, false, false);
1180
- const income = new TransactionType('I', 'Income', 'Income', 0, false, false, true, false, false, false, false, false, false, false);
1160
+ const buy = new TransactionType('B', 'Buy', 'Buy', 0, true, false, false, true, false, false, false, true, true);
1161
+ const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
1162
+ const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
1163
+ const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true);
1164
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
1165
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
1166
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
1167
+ const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
1168
+ const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false);
1169
+ const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false);
1170
+ const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, false);
1171
+
1172
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false);
1173
+ const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false);
1174
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', 1, false, false, false, true, false, false, true, false, false);
1175
+
1176
+ const deposit = new TransactionType('D', 'Deposit', 'Deposit', 0, false, false, false, false, false, false, false, true, true);
1177
+ const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', 0, false, false, false, false, false, false, false, true, true);
1178
+ const debit = new TransactionType('DR', 'Debit', 'Debit', 0, false, false, false, false, false, false, false, true, true);
1179
+ const credit = new TransactionType('CR', 'Credit', 'Credit', 0, false, false, false, false, false, false, false, true, true);
1180
+
1181
+ const valuation = new TransactionType('V', 'Valuation', 'Valuation', 0, false, false, false, false, false, false, false, false, false);
1182
+ const income = new TransactionType('I', 'Income', 'Income', 0, false, false, true, false, false, false, false, false, false);
1181
1183
 
1182
1184
  return TransactionType;
1183
1185
  })();
@@ -2657,6 +2659,9 @@ module.exports = (() => {
2657
2659
  this._dataActual.marketChange = null;
2658
2660
  this._dataActual.marketChangePercent = null;
2659
2661
  this._dataActual.cashTotal = null;
2662
+ this._dataActual.periodDivisorCurrent = null;
2663
+ this._dataActual.periodDivisorPrevious = null;
2664
+ this._dataActual.periodDivisorPrevious2 = null;
2660
2665
 
2661
2666
  this._dataFormat.currentPrice = null;
2662
2667
  this._dataFormat.basis = null;
@@ -2688,33 +2693,25 @@ module.exports = (() => {
2688
2693
 
2689
2694
  this._dataActual.periodPrice = null;
2690
2695
  this._dataActual.periodPricePrevious = null;
2691
- this._dataActual.periodRealized = null;
2692
- this._dataActual.periodRealizedPrevious = null;
2693
- this._dataActual.periodRealizedPrevious2 = null;
2694
- this._dataActual.periodRealizedBasis = null;
2695
- this._dataActual.periodRealizedBasisPrevious = null;
2696
- this._dataActual.periodRealizedBasisPrevious2 = null;
2697
- this._dataActual.periodUnrealized = null;
2698
- this._dataActual.periodUnrealizedPrevious = null;
2699
- this._dataActual.periodUnrealizedPrevious2 = null;
2700
- this._dataActual.periodUnrealizedBasis = null;
2701
- this._dataActual.periodUnrealizedBasisPrevious = null;
2702
- this._dataActual.periodUnrealizedBasisPrevious2 = null;
2703
- this._dataActual.periodIncome = null;
2704
2696
 
2705
2697
  this._dataFormat.periodPrice = null;
2706
2698
  this._dataFormat.periodPricePrevious = null;
2699
+
2700
+ this._dataActual.periodIncome = null;
2701
+ this._dataActual.periodRealized = null;
2702
+ this._dataActual.periodUnrealized = null;
2703
+
2704
+ this._dataFormat.periodIncome = null;
2707
2705
  this._dataFormat.periodRealized = null;
2708
2706
  this._dataFormat.periodUnrealized = null;
2709
- this._dataFormat.periodIncome = null;
2710
2707
 
2711
2708
  this._dataActual.periodPercent = null;
2712
- this._dataActual.periodPreviousPercent = null;
2713
- this._dataActual.periodPrevious2Percent = null;
2709
+ this._dataActual.periodPercentPrevious = null;
2710
+ this._dataActual.periodPercentPrevious2 = null;
2714
2711
 
2715
2712
  this._dataFormat.periodPercent = null;
2716
- this._dataFormat.periodPreviousPercent = null;
2717
- this._dataFormat.periodPrevious2Percent = null;
2713
+ this._dataFormat.periodPercentPrevious = null;
2714
+ this._dataFormat.periodPercentPrevious2 = null;
2718
2715
 
2719
2716
  this._items.forEach((item) => {
2720
2717
  bindItem.call(this, item);
@@ -3206,9 +3203,9 @@ module.exports = (() => {
3206
3203
  updates.realized = updates.realized.add(translate(item, item.data.realized));
3207
3204
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
3208
3205
  updates.income = updates.income.add(translate(item, item.data.income));
3209
- updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
3210
- updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
3211
- updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.summaryTotalPrevious2));
3206
+ updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.periodGain));
3207
+ updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.periodGainPrevious));
3208
+ updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.periodGainPrevious2));
3212
3209
  updates.marketPrevious = updates.marketPrevious.add(translate(item, item.data.marketPrevious));
3213
3210
  updates.marketPrevious2 = updates.marketPrevious2.add(translate(item, item.data.marketPrevious2));
3214
3211
 
@@ -3220,6 +3217,10 @@ module.exports = (() => {
3220
3217
  updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
3221
3218
  }
3222
3219
 
3220
+ updates.periodDivisorCurrent = updates.periodDivisorCurrent.add(translate(item, item.data.periodDivisor));
3221
+ updates.periodDivisorPrevious = updates.periodDivisorPrevious.add(translate(item, item.data.periodDivisorPrevious));
3222
+ updates.periodDivisorPrevious2 = updates.periodDivisorPrevious2.add(translate(item, item.data.periodDivisorPrevious2));
3223
+
3223
3224
  return updates;
3224
3225
  }, {
3225
3226
  basis: Decimal.ZERO,
@@ -3235,6 +3236,9 @@ module.exports = (() => {
3235
3236
  periodUnrealized: Decimal.ZERO,
3236
3237
  periodIncome: Decimal.ZERO,
3237
3238
  cashTotal: Decimal.ZERO,
3239
+ periodDivisorCurrent: Decimal.ZERO,
3240
+ periodDivisorPrevious: Decimal.ZERO,
3241
+ periodDivisorPrevious2: Decimal.ZERO
3238
3242
  });
3239
3243
 
3240
3244
  actual.basis = updates.basis;
@@ -3250,12 +3254,16 @@ module.exports = (() => {
3250
3254
  actual.periodUnrealized = updates.periodUnrealized;
3251
3255
  actual.periodIncome = updates.periodIncome;
3252
3256
  actual.cashTotal = updates.cashTotal;
3257
+ actual.periodDivisorCurrent = updates.periodDivisorCurrent;
3258
+ actual.periodDivisorPrevious = updates.periodDivisorPrevious;
3259
+ actual.periodDivisorPrevious2 = updates.periodDivisorPrevious2;
3253
3260
 
3254
3261
  format.basis = formatCurrency(actual.basis, currency);
3255
3262
  format.realized = formatCurrency(actual.realized, currency);
3256
3263
  format.unrealized = formatCurrency(actual.unrealized, currency);
3257
3264
  format.income = formatCurrency(actual.income, currency);
3258
3265
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
3266
+ format.summaryTotalCurrentNegative = updates.summaryTotalCurrent.getIsNegative();
3259
3267
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
3260
3268
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
3261
3269
  format.summaryTotalPrevious2 = formatCurrency(updates.summaryTotalPrevious2, currency);
@@ -3290,25 +3298,9 @@ module.exports = (() => {
3290
3298
  format.periodPrice = formatCurrency(actual.periodPrice, currency);
3291
3299
  format.periodPricePrevious = formatCurrency(actual.periodPricePrevious, currency);
3292
3300
 
3293
- actual.periodRealized = item.data.periodRealized;
3294
- actual.periodRealizedPrevious = item.data.periodRealizedPrevious;
3295
- actual.periodRealizedPrevious2 = item.data.periodRealizedPrevious2;
3296
-
3297
- actual.periodRealizedBasis = item.data.periodRealizedBasis;
3298
- actual.periodRealizedBasisPrevious = item.data.periodRealizedBasisPrevious;
3299
- actual.periodRealizedBasisPrevious2 = item.data.periodRealizedBasisPrevious2;
3300
-
3301
- actual.periodUnrealized = item.data.periodUnrealized;
3302
- actual.periodUnrealizedPrevious = item.data.periodUnrealizedPrevious;
3303
- actual.periodUnrealizedPrevious2 = item.data.periodUnrealizedPrevious2;
3304
-
3305
- actual.periodUnrealizedBasis = item.data.periodUnrealizedBasis;
3306
- actual.periodUnrealizedBasisPrevious = item.data.periodUnrealizedBasisPrevious;
3307
- actual.periodUnrealizedBasisPrevious2 = item.data.periodUnrealizedBasisPrevious2;
3308
-
3309
- actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodRealizedBasis, actual.periodUnrealizedBasis);
3310
- actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodRealizedBasisPrevious, actual.periodUnrealizedBasisPrevious);
3311
- actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodRealizedBasisPrevious2, actual.periodUnrealizedBasisPrevious2);
3301
+ actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
3302
+ actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
3303
+ actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
3312
3304
 
3313
3305
  format.periodPercent = formatPercent(actual.periodPercent, 2);
3314
3306
  format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
@@ -3367,7 +3359,7 @@ module.exports = (() => {
3367
3359
  updates.marketAbsolute = updates.marketAbsolute.add(translate(item, item.data.marketAbsolute));
3368
3360
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
3369
3361
  updates.unrealizedToday = updates.unrealizedToday.add(translate(item, item.data.unrealizedToday));
3370
- updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
3362
+ updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.periodGain));
3371
3363
 
3372
3364
  return updates;
3373
3365
  }, {
@@ -3385,7 +3377,7 @@ module.exports = (() => {
3385
3377
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
3386
3378
  unrealized: actual.unrealized.add(translate(item, item.data.unrealizedChange)),
3387
3379
  unrealizedToday: actual.unrealizedToday.add(translate(item, item.data.unrealizedTodayChange)),
3388
- summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrentChange))
3380
+ summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange))
3389
3381
  };
3390
3382
  }
3391
3383
 
@@ -3441,7 +3433,7 @@ module.exports = (() => {
3441
3433
  if (group.single && item) {
3442
3434
  actual.periodUnrealized = item.data.periodUnrealized;
3443
3435
 
3444
- actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodRealizedBasis, actual.periodUnrealizedBasis);
3436
+ actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
3445
3437
  format.periodPercent = formatPercent(actual.periodPercent, 2);
3446
3438
  }
3447
3439
  }
@@ -3502,11 +3494,8 @@ module.exports = (() => {
3502
3494
  }
3503
3495
  }
3504
3496
 
3505
- function calculatePeriodPercent(periodSummaryTotal, realizedBasis, unrealizedBasis) {
3506
- const numerator = periodSummaryTotal;
3507
- const denominator = realizedBasis.add(unrealizedBasis);
3508
-
3509
- return denominator.getIsZero() ? Decimal.ZERO : numerator.divide(denominator);
3497
+ function calculatePeriodPercent(periodSummaryTotal, periodDivisor) {
3498
+ return periodDivisor.getIsZero() ? Decimal.ZERO : periodSummaryTotal.divide(periodDivisor);
3510
3499
  }
3511
3500
 
3512
3501
  const unchanged = { up: false, down: false };
@@ -3579,12 +3568,6 @@ module.exports = (() => {
3579
3568
  this._data.unrealized = null;
3580
3569
  this._data.unrealizedChange = null;
3581
3570
 
3582
- this._data.summaryTotalCurrent = null;
3583
- this._data.summaryTotalCurrentChange = null;
3584
-
3585
- this._data.summaryTotalPrevious = null;
3586
- this._data.summaryTotalPrevious2 = null;
3587
-
3588
3571
  this._data.marketPrevious = null;
3589
3572
  this._data.marketPrevious2 = null;
3590
3573
 
@@ -3595,26 +3578,24 @@ module.exports = (() => {
3595
3578
  this._data.income = null;
3596
3579
  this._data.basisPrice = null;
3597
3580
 
3581
+ this._data.periodIncome = null;
3598
3582
  this._data.periodRealized = null;
3599
- this._data.periodRealizedPrevious = null;
3600
- this._data.periodRealizedPrevious2 = null;
3583
+ this._data.periodUnrealized = null;
3601
3584
 
3602
- this._data.periodRealizedBasis = null;
3603
- this._data.periodRealizedBasisPrevious = null;
3604
- this._data.periodRealizedBasisPrevious2 = null;
3585
+ this._data.periodPrice = null;
3586
+ this._data.periodPricePrevious = null;
3605
3587
 
3606
- this._data.periodUnrealized = null;
3607
- this._data.periodUnrealizedPrevious = null;
3608
- this._data.periodUnrealizedPrevious2 = null;
3588
+ this._data.periodGain = null;
3589
+ this._data.periodGainChange = null;
3609
3590
 
3610
- this._data.periodUnrealizedBasis = null;
3611
- this._data.periodUnrealizedBasisPrevious = null;
3612
- this._data.periodUnrealizedBasisPrevious2 = null;
3591
+ this._data.periodGainPrevious = null;
3592
+ this._data.periodGainPrevious2 = null;
3613
3593
 
3614
- this._data.periodIncome = null;
3594
+ this._data.periodDivisor = null;
3595
+ this._data.periodDivisorChange = null;
3615
3596
 
3616
- this._data.periodPrice = null;
3617
- this._data.periodPricePrevious = null;
3597
+ this._data.periodDivisorPrevious = null;
3598
+ this._data.periodDivisorPrevious2 = null;
3618
3599
 
3619
3600
  this._data.newsExists = false;
3620
3601
  this._data.fundamental = { };
@@ -3934,31 +3915,21 @@ module.exports = (() => {
3934
3915
 
3935
3916
  data.income = snapshot.income;
3936
3917
 
3937
- data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary, previousSummary1);
3938
- data.summaryTotalPrevious = calculateSummaryTotal(previousSummary1, previousSummary2);
3939
- data.summaryTotalPrevious2 = calculateSummaryTotal(previousSummary2, previousSummary3);
3940
-
3941
3918
  data.marketPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.value;
3942
3919
  data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
3943
3920
  data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
3944
3921
 
3945
- data.periodRealized = calculatePeriodRealized(item.currentSummary, previousSummary1);
3946
- data.periodRealizedPrevious = calculatePeriodRealized(previousSummary1, previousSummary2);
3947
- data.periodRealizedPrevious2 = calculatePeriodRealized(previousSummary2, previousSummary3);
3948
-
3949
- data.periodRealizedBasis = calculatePeriodRealizedBasis(item.currentSummary, previousSummary1);
3950
- data.periodRealizedBasisPrevious = calculatePeriodRealizedBasis(previousSummary1, previousSummary2);
3951
- data.periodRealizedBasisPrevious2 = calculatePeriodRealizedBasis(previousSummary2, previousSummary3);
3952
-
3953
- data.periodUnrealized = calculatePeriodUnrealized(item.currentSummary, previousSummary1);
3954
- data.periodUnrealizedPrevious = calculatePeriodUnrealized(previousSummary1, previousSummary2);
3955
- data.periodUnrealizedPrevious2 = calculatePeriodUnrealized(previousSummary2, previousSummary3);
3922
+ data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
3923
+ data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
3924
+ data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
3956
3925
 
3957
- data.periodUnrealizedBasis = calculatePeriodUnrealizedBasis(item.currentSummary, previousSummary1);
3958
- data.periodUnrealizedBasisPrevious = calculatePeriodUnrealizedBasis(previousSummary1, previousSummary2);
3959
- data.periodUnrealizedBasisPrevious2 = calculatePeriodUnrealizedBasis(previousSummary2, previousSummary3);
3960
-
3961
- data.periodIncome = calculatePeriodIncome(item.currentSummary, previousSummary1);
3926
+ data.periodGain = calculatePeriodGain(currentSummary, previousSummary1);
3927
+ data.periodGainPrevious = calculatePeriodGain(previousSummary1, previousSummary2);
3928
+ data.periodGainPrevious2 = calculatePeriodGain(previousSummary2, previousSummary3);
3929
+
3930
+ data.periodDivisor = calculatePeriodDivisor(currentSummary, previousSummary1);
3931
+ data.periodDivisorPrevious = calculatePeriodDivisor(previousSummary1, previousSummary2);
3932
+ data.periodDivisorPrevious2 = calculatePeriodDivisor(previousSummary2, previousSummary3);
3962
3933
 
3963
3934
  if (snapshot.open.getIsZero()) {
3964
3935
  data.basisPrice = Decimal.ZERO;
@@ -3982,7 +3953,6 @@ module.exports = (() => {
3982
3953
  function calculatePriceData(item, price) {
3983
3954
  const position = item.position;
3984
3955
  const snapshot = getSnapshot(position, item.currentSummary, item._reporting);
3985
- const previousSummaries = item.previousSummaries;
3986
3956
 
3987
3957
  const data = item._data;
3988
3958
 
@@ -4043,10 +4013,9 @@ module.exports = (() => {
4043
4013
  data.unrealizedTodayChange = unrealizedTodayChange;
4044
4014
 
4045
4015
  const currentSummary = item.currentSummary;
4016
+ const previousSummary = getPreviousSummary(item.previousSummaries, 1);
4046
4017
 
4047
4018
  if (currentSummary && position.instrument.type !== InstrumentType.CASH) {
4048
- const previousSummary = getPreviousSummary(previousSummaries, 1);
4049
-
4050
4019
  let priceToUse;
4051
4020
 
4052
4021
  if (price) {
@@ -4060,8 +4029,6 @@ module.exports = (() => {
4060
4029
  }
4061
4030
 
4062
4031
  if (priceToUse !== null) {
4063
- const period = currentSummary.period;
4064
-
4065
4032
  let unrealized = currentSummary.end.open.multiply(priceToUse).add(currentSummary.end.basis);
4066
4033
  let unrealizedChange;
4067
4034
 
@@ -4071,115 +4038,79 @@ module.exports = (() => {
4071
4038
  unrealizedChange = Decimal.ZERO;
4072
4039
  }
4073
4040
 
4074
- let summaryTotalCurrent = period.realized.add(period.income).add(unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
4075
- let summaryTotalCurrentChange;
4041
+ data.unrealized = unrealized;
4042
+ data.unrealizedChange = unrealizedChange;
4043
+
4044
+ let periodGain = calculatePeriodGain(currentSummary, previousSummary, priceToUse);
4045
+ let periodGainChange;
4076
4046
 
4077
- if (data.summaryTotalCurrent !== null) {
4078
- summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
4047
+ if (data.periodGain !== null) {
4048
+ periodGainChange = periodGain.subtract(data.periodGain);
4079
4049
  } else {
4080
- summaryTotalCurrentChange = Decimal.ZERO;
4050
+ periodGainChange = Decimal.ZERO;
4081
4051
  }
4082
4052
 
4083
- data.summaryTotalCurrent = summaryTotalCurrent;
4084
- data.summaryTotalCurrentChange = summaryTotalCurrentChange;
4085
-
4086
- data.unrealized = unrealized;
4087
- data.unrealizedChange = unrealizedChange;
4088
-
4089
- data.periodUnrealized = calculatePeriodUnrealized(item.currentSummary, previousSummary, data.unrealized);
4090
- data.periodUnrealizedChange = unrealizedChange;
4053
+ data.periodGain = periodGain;
4054
+ data.periodGainChange = periodGainChange;
4091
4055
  } else {
4092
- data.summaryTotalCurrentChange = Decimal.ZERO;
4093
-
4094
4056
  data.unrealized = Decimal.ZERO;
4095
4057
  data.unrealizedChange = Decimal.ZERO;
4096
4058
 
4097
- data.periodUnrealizedChange = Decimal.ZERO;
4059
+ data.periodGainChange = Decimal.ZERO;
4098
4060
  }
4099
4061
  } else {
4100
- data.summaryTotalCurrentChange = Decimal.ZERO;
4101
-
4102
4062
  data.unrealized = Decimal.ZERO;
4103
4063
  data.unrealizedChange = Decimal.ZERO;
4104
- }
4105
- }
4106
-
4107
- function calculateSummaryTotal(currentSummary, previousSummary) {
4108
- let returnRef;
4109
-
4110
- if (currentSummary) {
4111
- const period = currentSummary.period;
4112
4064
 
4113
- returnRef = period.realized.add(period.income).add(period.unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
4114
- } else {
4115
- returnRef = Decimal.ZERO;
4065
+ data.periodGainChange = Decimal.ZERO;
4116
4066
  }
4117
-
4118
- return returnRef;
4119
4067
  }
4120
4068
 
4121
- function calculatePeriodRealized(currentSummary, previousSummary) {
4069
+ function calculatePeriodGain(currentSummary, previousSummary, overridePrice) {
4122
4070
  let returnRef;
4123
4071
 
4124
4072
  if (currentSummary) {
4125
- const period = currentSummary.period;
4073
+ let startValue;
4126
4074
 
4127
- returnRef = period.realized;
4128
- } else {
4129
- returnRef = Decimal.ZERO;
4130
- }
4075
+ if (previousSummary) {
4076
+ startValue = previousSummary.end.value;
4077
+ } else {
4078
+ startValue = Decimal.ZERO;
4079
+ }
4131
4080
 
4132
- return returnRef;
4133
- }
4081
+ let endValue;
4134
4082
 
4135
- function calculatePeriodRealizedBasis(currentSummary, previousSummary) {
4136
- let returnRef;
4083
+ if (overridePrice) {
4084
+ endValue = currentSummary.end.open.multiply(overridePrice);
4085
+ } else {
4086
+ endValue = currentSummary.end.value;
4087
+ }
4137
4088
 
4138
- if (currentSummary) {
4139
- const period = currentSummary.period;
4089
+ const valueChange = endValue.subtract(startValue);
4090
+ const tradeChange = currentSummary.period.sells.subtract(currentSummary.period.buys);
4091
+ const incomeChange = currentSummary.period.income;
4140
4092
 
4141
- returnRef = period.sells.subtract(calculatePeriodRealized(currentSummary, previousSummary));
4093
+ returnRef = valueChange.add(tradeChange).add(incomeChange);
4142
4094
  } else {
4143
4095
  returnRef = Decimal.ZERO;
4144
4096
  }
4145
4097
 
4146
4098
  return returnRef;
4147
4099
  }
4148
-
4149
- function calculatePeriodUnrealized(currentSummary, previousSummary, override) {
4150
- let returnRef;
4151
-
4152
- if (currentSummary) {
4153
- const period = currentSummary.period;
4154
- const unrealized = override || period.unrealized;
4155
4100
 
4156
- returnRef = unrealized.subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
4157
- } else {
4158
- returnRef = Decimal.ZERO;
4159
- }
4160
-
4161
- return returnRef;
4162
- }
4163
-
4164
- function calculatePeriodUnrealizedBasis(currentSummary, previousSummary) {
4101
+ function calculatePeriodDivisor(currentSummary, previousSummary) {
4165
4102
  let returnRef;
4166
4103
 
4167
4104
  if (currentSummary) {
4168
- returnRef = currentSummary.end.basis.absolute();
4169
- } else {
4170
- returnRef = Decimal.ZERO;
4171
- }
4172
-
4173
- return returnRef;
4174
- }
4175
-
4176
- function calculatePeriodIncome(currentSummary, previousSummary) {
4177
- let returnRef;
4105
+ let startValue;
4178
4106
 
4179
- if (currentSummary) {
4180
- const period = currentSummary.period;
4107
+ if (previousSummary) {
4108
+ startValue = previousSummary.end.value;
4109
+ } else {
4110
+ startValue = Decimal.ZERO;
4111
+ }
4181
4112
 
4182
- returnRef = period.income;
4113
+ returnRef = startValue.add(currentSummary.period.buys);
4183
4114
  } else {
4184
4115
  returnRef = Decimal.ZERO;
4185
4116
  }