@barchart/portfolio-api-common 1.2.131 → 1.2.132

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.
@@ -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 = { };
@@ -393,7 +385,6 @@ module.exports = (() => {
393
385
 
394
386
  const previousSummary1 = getPreviousSummary(item.previousSummaries, 1);
395
387
  const previousSummary2 = getPreviousSummary(item.previousSummaries, 2);
396
- const previousSummary3 = getPreviousSummary(item.previousSummaries, 3);
397
388
 
398
389
  const snapshot = getSnapshot(position, currentSummary, item._reporting);
399
390
 
@@ -417,31 +408,21 @@ module.exports = (() => {
417
408
 
418
409
  data.income = snapshot.income;
419
410
 
420
- data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary, previousSummary1);
421
- data.summaryTotalPrevious = calculateSummaryTotal(previousSummary1, previousSummary2);
422
- data.summaryTotalPrevious2 = calculateSummaryTotal(previousSummary2, previousSummary3);
423
-
424
411
  data.marketPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.value;
425
412
  data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
426
413
  data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
427
414
 
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);
415
+ data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
416
+ data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
417
+ data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
418
+
419
+ data.periodGain = calculatePeriodGain(currentSummary);
420
+ data.periodGainPrevious = calculatePeriodGain(previousSummary1);
421
+ data.periodGainPrevious2 = calculatePeriodGain(previousSummary2);
422
+
423
+ data.periodDivisor = calculatePeriodDivisor(currentSummary);
424
+ data.periodDivisorPrevious = calculatePeriodDivisor(previousSummary1);
425
+ data.periodDivisorPrevious2 = calculatePeriodDivisor(previousSummary2);
445
426
 
446
427
  if (snapshot.open.getIsZero()) {
447
428
  data.basisPrice = Decimal.ZERO;
@@ -465,7 +446,6 @@ module.exports = (() => {
465
446
  function calculatePriceData(item, price) {
466
447
  const position = item.position;
467
448
  const snapshot = getSnapshot(position, item.currentSummary, item._reporting);
468
- const previousSummaries = item.previousSummaries;
469
449
 
470
450
  const data = item._data;
471
451
 
@@ -528,8 +508,6 @@ module.exports = (() => {
528
508
  const currentSummary = item.currentSummary;
529
509
 
530
510
  if (currentSummary && position.instrument.type !== InstrumentType.CASH) {
531
- const previousSummary = getPreviousSummary(previousSummaries, 1);
532
-
533
511
  let priceToUse;
534
512
 
535
513
  if (price) {
@@ -543,8 +521,6 @@ module.exports = (() => {
543
521
  }
544
522
 
545
523
  if (priceToUse !== null) {
546
- const period = currentSummary.period;
547
-
548
524
  let unrealized = currentSummary.end.open.multiply(priceToUse).add(currentSummary.end.basis);
549
525
  let unrealizedChange;
550
526
 
@@ -554,101 +530,51 @@ module.exports = (() => {
554
530
  unrealizedChange = Decimal.ZERO;
555
531
  }
556
532
 
557
- let summaryTotalCurrent = period.realized.add(period.income).add(unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
558
- let summaryTotalCurrentChange;
533
+ data.unrealized = unrealized;
534
+ data.unrealizedChange = unrealizedChange;
559
535
 
560
- if (data.summaryTotalCurrent !== null) {
561
- summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
536
+ let periodGain = calculatePeriodGain(currentSummary, priceToUse);
537
+ let periodGainChange;
538
+
539
+ if (data.periodGain !== null) {
540
+ periodGainChange = periodGain.subtract(data.periodGain);
562
541
  } else {
563
- summaryTotalCurrentChange = Decimal.ZERO;
542
+ periodGainChange = Decimal.ZERO;
564
543
  }
565
544
 
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;
545
+ data.periodGain = periodGain;
546
+ data.periodGainChange = periodGainChange;
574
547
  } else {
575
- data.summaryTotalCurrentChange = Decimal.ZERO;
576
-
577
548
  data.unrealized = Decimal.ZERO;
578
549
  data.unrealizedChange = Decimal.ZERO;
579
550
 
580
- data.periodUnrealizedChange = Decimal.ZERO;
551
+ data.periodGainChange = Decimal.ZERO;
581
552
  }
582
553
  } else {
583
- data.summaryTotalCurrentChange = Decimal.ZERO;
584
-
585
554
  data.unrealized = Decimal.ZERO;
586
555
  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
556
 
596
- returnRef = period.realized.add(period.income).add(period.unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
597
- } else {
598
- returnRef = Decimal.ZERO;
557
+ data.periodGainChange = Decimal.ZERO;
599
558
  }
600
-
601
- return returnRef;
602
- }
603
-
604
- function calculatePeriodRealized(currentSummary, previousSummary) {
605
- let returnRef;
606
-
607
- if (currentSummary) {
608
- const period = currentSummary.period;
609
-
610
- returnRef = period.realized;
611
- } else {
612
- returnRef = Decimal.ZERO;
613
- }
614
-
615
- return returnRef;
616
559
  }
617
560
 
618
- function calculatePeriodRealizedBasis(currentSummary, previousSummary) {
619
- let returnRef;
620
-
621
- if (currentSummary) {
622
- const period = currentSummary.period;
623
-
624
- returnRef = period.sells.subtract(calculatePeriodRealized(currentSummary, previousSummary));
625
- } else {
626
- returnRef = Decimal.ZERO;
627
- }
628
-
629
- return returnRef;
630
- }
631
-
632
- function calculatePeriodUnrealized(currentSummary, previousSummary, override) {
561
+ function calculatePeriodGain(currentSummary, overridePrice) {
633
562
  let returnRef;
634
563
 
635
564
  if (currentSummary) {
636
- const period = currentSummary.period;
637
- const unrealized = override || period.unrealized;
565
+ let endValue;
638
566
 
639
- returnRef = unrealized.subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
640
- } else {
641
- returnRef = Decimal.ZERO;
642
- }
567
+ if (overridePrice) {
568
+ endValue = currentSummary.end.open.multiply(overridePrice);
569
+ } else {
570
+ endValue = currentSummary.end.value;
571
+ }
643
572
 
644
- return returnRef;
645
- }
646
-
647
- function calculatePeriodUnrealizedBasis(currentSummary, previousSummary) {
648
- let returnRef;
573
+ const valueChange = endValue.subtract(currentSummary.start.value);
574
+ const tradeChange = currentSummary.period.sells.subtract(currentSummary.period.buys);
575
+ const incomeChange = currentSummary.period.income;
649
576
 
650
- if (currentSummary) {
651
- returnRef = currentSummary.end.basis.absolute();
577
+ returnRef = valueChange.add(tradeChange).add(incomeChange);
652
578
  } else {
653
579
  returnRef = Decimal.ZERO;
654
580
  }
@@ -656,13 +582,11 @@ module.exports = (() => {
656
582
  return returnRef;
657
583
  }
658
584
 
659
- function calculatePeriodIncome(currentSummary, previousSummary) {
585
+ function calculatePeriodDivisor(currentSummary) {
660
586
  let returnRef;
661
587
 
662
588
  if (currentSummary) {
663
- const period = currentSummary.period;
664
-
665
- returnRef = period.income;
589
+ returnRef = currentSummary.start.value.add(currentSummary.period.buys);
666
590
  } else {
667
591
  returnRef = Decimal.ZERO;
668
592
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.131",
3
+ "version": "1.2.132",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -2659,6 +2659,9 @@ module.exports = (() => {
2659
2659
  this._dataActual.marketChange = null;
2660
2660
  this._dataActual.marketChangePercent = null;
2661
2661
  this._dataActual.cashTotal = null;
2662
+ this._dataActual.periodDivisorCurrent = null;
2663
+ this._dataActual.periodDivisorPrevious = null;
2664
+ this._dataActual.periodDivisorPrevious2 = null;
2662
2665
 
2663
2666
  this._dataFormat.currentPrice = null;
2664
2667
  this._dataFormat.basis = null;
@@ -2690,33 +2693,25 @@ module.exports = (() => {
2690
2693
 
2691
2694
  this._dataActual.periodPrice = null;
2692
2695
  this._dataActual.periodPricePrevious = null;
2693
- this._dataActual.periodRealized = null;
2694
- this._dataActual.periodRealizedPrevious = null;
2695
- this._dataActual.periodRealizedPrevious2 = null;
2696
- this._dataActual.periodRealizedBasis = null;
2697
- this._dataActual.periodRealizedBasisPrevious = null;
2698
- this._dataActual.periodRealizedBasisPrevious2 = null;
2699
- this._dataActual.periodUnrealized = null;
2700
- this._dataActual.periodUnrealizedPrevious = null;
2701
- this._dataActual.periodUnrealizedPrevious2 = null;
2702
- this._dataActual.periodUnrealizedBasis = null;
2703
- this._dataActual.periodUnrealizedBasisPrevious = null;
2704
- this._dataActual.periodUnrealizedBasisPrevious2 = null;
2705
- this._dataActual.periodIncome = null;
2706
2696
 
2707
2697
  this._dataFormat.periodPrice = null;
2708
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;
2709
2705
  this._dataFormat.periodRealized = null;
2710
2706
  this._dataFormat.periodUnrealized = null;
2711
- this._dataFormat.periodIncome = null;
2712
2707
 
2713
2708
  this._dataActual.periodPercent = null;
2714
- this._dataActual.periodPreviousPercent = null;
2715
- this._dataActual.periodPrevious2Percent = null;
2709
+ this._dataActual.periodPercentPrevious = null;
2710
+ this._dataActual.periodPercentPrevious2 = null;
2716
2711
 
2717
2712
  this._dataFormat.periodPercent = null;
2718
- this._dataFormat.periodPreviousPercent = null;
2719
- this._dataFormat.periodPrevious2Percent = null;
2713
+ this._dataFormat.periodPercentPrevious = null;
2714
+ this._dataFormat.periodPercentPrevious2 = null;
2720
2715
 
2721
2716
  this._items.forEach((item) => {
2722
2717
  bindItem.call(this, item);
@@ -3208,9 +3203,9 @@ module.exports = (() => {
3208
3203
  updates.realized = updates.realized.add(translate(item, item.data.realized));
3209
3204
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
3210
3205
  updates.income = updates.income.add(translate(item, item.data.income));
3211
- updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
3212
- updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
3213
- 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));
3214
3209
  updates.marketPrevious = updates.marketPrevious.add(translate(item, item.data.marketPrevious));
3215
3210
  updates.marketPrevious2 = updates.marketPrevious2.add(translate(item, item.data.marketPrevious2));
3216
3211
 
@@ -3222,6 +3217,10 @@ module.exports = (() => {
3222
3217
  updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
3223
3218
  }
3224
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
+
3225
3224
  return updates;
3226
3225
  }, {
3227
3226
  basis: Decimal.ZERO,
@@ -3237,6 +3236,9 @@ module.exports = (() => {
3237
3236
  periodUnrealized: Decimal.ZERO,
3238
3237
  periodIncome: Decimal.ZERO,
3239
3238
  cashTotal: Decimal.ZERO,
3239
+ periodDivisorCurrent: Decimal.ZERO,
3240
+ periodDivisorPrevious: Decimal.ZERO,
3241
+ periodDivisorPrevious2: Decimal.ZERO
3240
3242
  });
3241
3243
 
3242
3244
  actual.basis = updates.basis;
@@ -3252,12 +3254,16 @@ module.exports = (() => {
3252
3254
  actual.periodUnrealized = updates.periodUnrealized;
3253
3255
  actual.periodIncome = updates.periodIncome;
3254
3256
  actual.cashTotal = updates.cashTotal;
3257
+ actual.periodDivisorCurrent = updates.periodDivisorCurrent;
3258
+ actual.periodDivisorPrevious = updates.periodDivisorPrevious;
3259
+ actual.periodDivisorPrevious2 = updates.periodDivisorPrevious2;
3255
3260
 
3256
3261
  format.basis = formatCurrency(actual.basis, currency);
3257
3262
  format.realized = formatCurrency(actual.realized, currency);
3258
3263
  format.unrealized = formatCurrency(actual.unrealized, currency);
3259
3264
  format.income = formatCurrency(actual.income, currency);
3260
3265
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
3266
+ format.summaryTotalCurrentNegative = updates.summaryTotalCurrent.getIsNegative();
3261
3267
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
3262
3268
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
3263
3269
  format.summaryTotalPrevious2 = formatCurrency(updates.summaryTotalPrevious2, currency);
@@ -3292,25 +3298,9 @@ module.exports = (() => {
3292
3298
  format.periodPrice = formatCurrency(actual.periodPrice, currency);
3293
3299
  format.periodPricePrevious = formatCurrency(actual.periodPricePrevious, currency);
3294
3300
 
3295
- actual.periodRealized = item.data.periodRealized;
3296
- actual.periodRealizedPrevious = item.data.periodRealizedPrevious;
3297
- actual.periodRealizedPrevious2 = item.data.periodRealizedPrevious2;
3298
-
3299
- actual.periodRealizedBasis = item.data.periodRealizedBasis;
3300
- actual.periodRealizedBasisPrevious = item.data.periodRealizedBasisPrevious;
3301
- actual.periodRealizedBasisPrevious2 = item.data.periodRealizedBasisPrevious2;
3302
-
3303
- actual.periodUnrealized = item.data.periodUnrealized;
3304
- actual.periodUnrealizedPrevious = item.data.periodUnrealizedPrevious;
3305
- actual.periodUnrealizedPrevious2 = item.data.periodUnrealizedPrevious2;
3306
-
3307
- actual.periodUnrealizedBasis = item.data.periodUnrealizedBasis;
3308
- actual.periodUnrealizedBasisPrevious = item.data.periodUnrealizedBasisPrevious;
3309
- actual.periodUnrealizedBasisPrevious2 = item.data.periodUnrealizedBasisPrevious2;
3310
-
3311
- actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodRealizedBasis, actual.periodUnrealizedBasis);
3312
- actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodRealizedBasisPrevious, actual.periodUnrealizedBasisPrevious);
3313
- 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);
3314
3304
 
3315
3305
  format.periodPercent = formatPercent(actual.periodPercent, 2);
3316
3306
  format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
@@ -3369,7 +3359,7 @@ module.exports = (() => {
3369
3359
  updates.marketAbsolute = updates.marketAbsolute.add(translate(item, item.data.marketAbsolute));
3370
3360
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
3371
3361
  updates.unrealizedToday = updates.unrealizedToday.add(translate(item, item.data.unrealizedToday));
3372
- updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
3362
+ updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.periodGain));
3373
3363
 
3374
3364
  return updates;
3375
3365
  }, {
@@ -3387,7 +3377,7 @@ module.exports = (() => {
3387
3377
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
3388
3378
  unrealized: actual.unrealized.add(translate(item, item.data.unrealizedChange)),
3389
3379
  unrealizedToday: actual.unrealizedToday.add(translate(item, item.data.unrealizedTodayChange)),
3390
- summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrentChange))
3380
+ summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange))
3391
3381
  };
3392
3382
  }
3393
3383
 
@@ -3443,7 +3433,7 @@ module.exports = (() => {
3443
3433
  if (group.single && item) {
3444
3434
  actual.periodUnrealized = item.data.periodUnrealized;
3445
3435
 
3446
- actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodRealizedBasis, actual.periodUnrealizedBasis);
3436
+ actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
3447
3437
  format.periodPercent = formatPercent(actual.periodPercent, 2);
3448
3438
  }
3449
3439
  }
@@ -3504,11 +3494,8 @@ module.exports = (() => {
3504
3494
  }
3505
3495
  }
3506
3496
 
3507
- function calculatePeriodPercent(periodSummaryTotal, realizedBasis, unrealizedBasis) {
3508
- const numerator = periodSummaryTotal;
3509
- const denominator = realizedBasis.add(unrealizedBasis);
3510
-
3511
- return denominator.getIsZero() ? Decimal.ZERO : numerator.divide(denominator);
3497
+ function calculatePeriodPercent(periodSummaryTotal, periodDivisor) {
3498
+ return periodDivisor.getIsZero() ? Decimal.ZERO : periodSummaryTotal.divide(periodDivisor);
3512
3499
  }
3513
3500
 
3514
3501
  const unchanged = { up: false, down: false };
@@ -3581,12 +3568,6 @@ module.exports = (() => {
3581
3568
  this._data.unrealized = null;
3582
3569
  this._data.unrealizedChange = null;
3583
3570
 
3584
- this._data.summaryTotalCurrent = null;
3585
- this._data.summaryTotalCurrentChange = null;
3586
-
3587
- this._data.summaryTotalPrevious = null;
3588
- this._data.summaryTotalPrevious2 = null;
3589
-
3590
3571
  this._data.marketPrevious = null;
3591
3572
  this._data.marketPrevious2 = null;
3592
3573
 
@@ -3597,26 +3578,24 @@ module.exports = (() => {
3597
3578
  this._data.income = null;
3598
3579
  this._data.basisPrice = null;
3599
3580
 
3581
+ this._data.periodIncome = null;
3600
3582
  this._data.periodRealized = null;
3601
- this._data.periodRealizedPrevious = null;
3602
- this._data.periodRealizedPrevious2 = null;
3583
+ this._data.periodUnrealized = null;
3603
3584
 
3604
- this._data.periodRealizedBasis = null;
3605
- this._data.periodRealizedBasisPrevious = null;
3606
- this._data.periodRealizedBasisPrevious2 = null;
3585
+ this._data.periodPrice = null;
3586
+ this._data.periodPricePrevious = null;
3607
3587
 
3608
- this._data.periodUnrealized = null;
3609
- this._data.periodUnrealizedPrevious = null;
3610
- this._data.periodUnrealizedPrevious2 = null;
3588
+ this._data.periodGain = null;
3589
+ this._data.periodGainChange = null;
3611
3590
 
3612
- this._data.periodUnrealizedBasis = null;
3613
- this._data.periodUnrealizedBasisPrevious = null;
3614
- this._data.periodUnrealizedBasisPrevious2 = null;
3591
+ this._data.periodGainPrevious = null;
3592
+ this._data.periodGainPrevious2 = null;
3615
3593
 
3616
- this._data.periodIncome = null;
3594
+ this._data.periodDivisor = null;
3595
+ this._data.periodDivisorChange = null;
3617
3596
 
3618
- this._data.periodPrice = null;
3619
- this._data.periodPricePrevious = null;
3597
+ this._data.periodDivisorPrevious = null;
3598
+ this._data.periodDivisorPrevious2 = null;
3620
3599
 
3621
3600
  this._data.newsExists = false;
3622
3601
  this._data.fundamental = { };
@@ -3912,7 +3891,6 @@ module.exports = (() => {
3912
3891
 
3913
3892
  const previousSummary1 = getPreviousSummary(item.previousSummaries, 1);
3914
3893
  const previousSummary2 = getPreviousSummary(item.previousSummaries, 2);
3915
- const previousSummary3 = getPreviousSummary(item.previousSummaries, 3);
3916
3894
 
3917
3895
  const snapshot = getSnapshot(position, currentSummary, item._reporting);
3918
3896
 
@@ -3936,31 +3914,21 @@ module.exports = (() => {
3936
3914
 
3937
3915
  data.income = snapshot.income;
3938
3916
 
3939
- data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary, previousSummary1);
3940
- data.summaryTotalPrevious = calculateSummaryTotal(previousSummary1, previousSummary2);
3941
- data.summaryTotalPrevious2 = calculateSummaryTotal(previousSummary2, previousSummary3);
3942
-
3943
3917
  data.marketPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.value;
3944
3918
  data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
3945
3919
  data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
3946
3920
 
3947
- data.periodRealized = calculatePeriodRealized(item.currentSummary, previousSummary1);
3948
- data.periodRealizedPrevious = calculatePeriodRealized(previousSummary1, previousSummary2);
3949
- data.periodRealizedPrevious2 = calculatePeriodRealized(previousSummary2, previousSummary3);
3950
-
3951
- data.periodRealizedBasis = calculatePeriodRealizedBasis(item.currentSummary, previousSummary1);
3952
- data.periodRealizedBasisPrevious = calculatePeriodRealizedBasis(previousSummary1, previousSummary2);
3953
- data.periodRealizedBasisPrevious2 = calculatePeriodRealizedBasis(previousSummary2, previousSummary3);
3954
-
3955
- data.periodUnrealized = calculatePeriodUnrealized(item.currentSummary, previousSummary1);
3956
- data.periodUnrealizedPrevious = calculatePeriodUnrealized(previousSummary1, previousSummary2);
3957
- data.periodUnrealizedPrevious2 = calculatePeriodUnrealized(previousSummary2, previousSummary3);
3921
+ data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
3922
+ data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
3923
+ data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
3958
3924
 
3959
- data.periodUnrealizedBasis = calculatePeriodUnrealizedBasis(item.currentSummary, previousSummary1);
3960
- data.periodUnrealizedBasisPrevious = calculatePeriodUnrealizedBasis(previousSummary1, previousSummary2);
3961
- data.periodUnrealizedBasisPrevious2 = calculatePeriodUnrealizedBasis(previousSummary2, previousSummary3);
3962
-
3963
- data.periodIncome = calculatePeriodIncome(item.currentSummary, previousSummary1);
3925
+ data.periodGain = calculatePeriodGain(currentSummary);
3926
+ data.periodGainPrevious = calculatePeriodGain(previousSummary1);
3927
+ data.periodGainPrevious2 = calculatePeriodGain(previousSummary2);
3928
+
3929
+ data.periodDivisor = calculatePeriodDivisor(currentSummary);
3930
+ data.periodDivisorPrevious = calculatePeriodDivisor(previousSummary1);
3931
+ data.periodDivisorPrevious2 = calculatePeriodDivisor(previousSummary2);
3964
3932
 
3965
3933
  if (snapshot.open.getIsZero()) {
3966
3934
  data.basisPrice = Decimal.ZERO;
@@ -3984,7 +3952,6 @@ module.exports = (() => {
3984
3952
  function calculatePriceData(item, price) {
3985
3953
  const position = item.position;
3986
3954
  const snapshot = getSnapshot(position, item.currentSummary, item._reporting);
3987
- const previousSummaries = item.previousSummaries;
3988
3955
 
3989
3956
  const data = item._data;
3990
3957
 
@@ -4047,8 +4014,6 @@ module.exports = (() => {
4047
4014
  const currentSummary = item.currentSummary;
4048
4015
 
4049
4016
  if (currentSummary && position.instrument.type !== InstrumentType.CASH) {
4050
- const previousSummary = getPreviousSummary(previousSummaries, 1);
4051
-
4052
4017
  let priceToUse;
4053
4018
 
4054
4019
  if (price) {
@@ -4062,8 +4027,6 @@ module.exports = (() => {
4062
4027
  }
4063
4028
 
4064
4029
  if (priceToUse !== null) {
4065
- const period = currentSummary.period;
4066
-
4067
4030
  let unrealized = currentSummary.end.open.multiply(priceToUse).add(currentSummary.end.basis);
4068
4031
  let unrealizedChange;
4069
4032
 
@@ -4073,101 +4036,51 @@ module.exports = (() => {
4073
4036
  unrealizedChange = Decimal.ZERO;
4074
4037
  }
4075
4038
 
4076
- let summaryTotalCurrent = period.realized.add(period.income).add(unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
4077
- let summaryTotalCurrentChange;
4039
+ data.unrealized = unrealized;
4040
+ data.unrealizedChange = unrealizedChange;
4078
4041
 
4079
- if (data.summaryTotalCurrent !== null) {
4080
- summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
4042
+ let periodGain = calculatePeriodGain(currentSummary, priceToUse);
4043
+ let periodGainChange;
4044
+
4045
+ if (data.periodGain !== null) {
4046
+ periodGainChange = periodGain.subtract(data.periodGain);
4081
4047
  } else {
4082
- summaryTotalCurrentChange = Decimal.ZERO;
4048
+ periodGainChange = Decimal.ZERO;
4083
4049
  }
4084
4050
 
4085
- data.summaryTotalCurrent = summaryTotalCurrent;
4086
- data.summaryTotalCurrentChange = summaryTotalCurrentChange;
4087
-
4088
- data.unrealized = unrealized;
4089
- data.unrealizedChange = unrealizedChange;
4090
-
4091
- data.periodUnrealized = calculatePeriodUnrealized(item.currentSummary, previousSummary, data.unrealized);
4092
- data.periodUnrealizedChange = unrealizedChange;
4051
+ data.periodGain = periodGain;
4052
+ data.periodGainChange = periodGainChange;
4093
4053
  } else {
4094
- data.summaryTotalCurrentChange = Decimal.ZERO;
4095
-
4096
4054
  data.unrealized = Decimal.ZERO;
4097
4055
  data.unrealizedChange = Decimal.ZERO;
4098
4056
 
4099
- data.periodUnrealizedChange = Decimal.ZERO;
4057
+ data.periodGainChange = Decimal.ZERO;
4100
4058
  }
4101
4059
  } else {
4102
- data.summaryTotalCurrentChange = Decimal.ZERO;
4103
-
4104
4060
  data.unrealized = Decimal.ZERO;
4105
4061
  data.unrealizedChange = Decimal.ZERO;
4106
- }
4107
- }
4108
-
4109
- function calculateSummaryTotal(currentSummary, previousSummary) {
4110
- let returnRef;
4111
-
4112
- if (currentSummary) {
4113
- const period = currentSummary.period;
4114
-
4115
- returnRef = period.realized.add(period.income).add(period.unrealized).subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
4116
- } else {
4117
- returnRef = Decimal.ZERO;
4118
- }
4119
-
4120
- return returnRef;
4121
- }
4122
-
4123
- function calculatePeriodRealized(currentSummary, previousSummary) {
4124
- let returnRef;
4125
-
4126
- if (currentSummary) {
4127
- const period = currentSummary.period;
4128
4062
 
4129
- returnRef = period.realized;
4130
- } else {
4131
- returnRef = Decimal.ZERO;
4063
+ data.periodGainChange = Decimal.ZERO;
4132
4064
  }
4133
-
4134
- return returnRef;
4135
4065
  }
4136
4066
 
4137
- function calculatePeriodRealizedBasis(currentSummary, previousSummary) {
4067
+ function calculatePeriodGain(currentSummary, overridePrice) {
4138
4068
  let returnRef;
4139
4069
 
4140
4070
  if (currentSummary) {
4141
- const period = currentSummary.period;
4071
+ let endValue;
4142
4072
 
4143
- returnRef = period.sells.subtract(calculatePeriodRealized(currentSummary, previousSummary));
4144
- } else {
4145
- returnRef = Decimal.ZERO;
4146
- }
4147
-
4148
- return returnRef;
4149
- }
4150
-
4151
- function calculatePeriodUnrealized(currentSummary, previousSummary, override) {
4152
- let returnRef;
4153
-
4154
- if (currentSummary) {
4155
- const period = currentSummary.period;
4156
- const unrealized = override || period.unrealized;
4157
-
4158
- returnRef = unrealized.subtract(previousSummary !== null ? previousSummary.period.unrealized : Decimal.ZERO);
4159
- } else {
4160
- returnRef = Decimal.ZERO;
4161
- }
4073
+ if (overridePrice) {
4074
+ endValue = currentSummary.end.open.multiply(overridePrice);
4075
+ } else {
4076
+ endValue = currentSummary.end.value;
4077
+ }
4162
4078
 
4163
- return returnRef;
4164
- }
4165
-
4166
- function calculatePeriodUnrealizedBasis(currentSummary, previousSummary) {
4167
- let returnRef;
4079
+ const valueChange = endValue.subtract(currentSummary.start.value);
4080
+ const tradeChange = currentSummary.period.sells.subtract(currentSummary.period.buys);
4081
+ const incomeChange = currentSummary.period.income;
4168
4082
 
4169
- if (currentSummary) {
4170
- returnRef = currentSummary.end.basis.absolute();
4083
+ returnRef = valueChange.add(tradeChange).add(incomeChange);
4171
4084
  } else {
4172
4085
  returnRef = Decimal.ZERO;
4173
4086
  }
@@ -4175,13 +4088,11 @@ module.exports = (() => {
4175
4088
  return returnRef;
4176
4089
  }
4177
4090
 
4178
- function calculatePeriodIncome(currentSummary, previousSummary) {
4091
+ function calculatePeriodDivisor(currentSummary) {
4179
4092
  let returnRef;
4180
4093
 
4181
4094
  if (currentSummary) {
4182
- const period = currentSummary.period;
4183
-
4184
- returnRef = period.income;
4095
+ returnRef = currentSummary.start.value.add(currentSummary.period.buys);
4185
4096
  } else {
4186
4097
  returnRef = Decimal.ZERO;
4187
4098
  }