@barchart/portfolio-api-common 1.2.131 → 1.2.135
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.
- package/lib/processing/PositionGroup.js +35 -48
- package/lib/processing/PositionItem.js +61 -119
- package/package.json +1 -1
- package/test/SpecRunner.js +95 -166
|
@@ -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.
|
|
193
|
-
this._dataActual.
|
|
187
|
+
this._dataActual.periodPercentPrevious = null;
|
|
188
|
+
this._dataActual.periodPercentPrevious2 = null;
|
|
194
189
|
|
|
195
190
|
this._dataFormat.periodPercent = null;
|
|
196
|
-
this._dataFormat.
|
|
197
|
-
this._dataFormat.
|
|
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.
|
|
690
|
-
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.
|
|
691
|
-
updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.
|
|
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.
|
|
774
|
-
actual.
|
|
775
|
-
actual.
|
|
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.
|
|
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.
|
|
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.
|
|
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,
|
|
986
|
-
|
|
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.
|
|
83
|
-
this._data.periodRealizedPrevious2 = null;
|
|
77
|
+
this._data.periodUnrealized = null;
|
|
84
78
|
|
|
85
|
-
this._data.
|
|
86
|
-
this._data.
|
|
87
|
-
this._data.periodRealizedBasisPrevious2 = null;
|
|
79
|
+
this._data.periodPrice = null;
|
|
80
|
+
this._data.periodPricePrevious = null;
|
|
88
81
|
|
|
89
|
-
this._data.
|
|
90
|
-
this._data.
|
|
91
|
-
this._data.periodUnrealizedPrevious2 = null;
|
|
82
|
+
this._data.periodGain = null;
|
|
83
|
+
this._data.periodGainChange = null;
|
|
92
84
|
|
|
93
|
-
this._data.
|
|
94
|
-
this._data.
|
|
95
|
-
this._data.periodUnrealizedBasisPrevious2 = null;
|
|
85
|
+
this._data.periodGainPrevious = null;
|
|
86
|
+
this._data.periodGainPrevious2 = null;
|
|
96
87
|
|
|
97
|
-
this._data.
|
|
88
|
+
this._data.periodDivisor = null;
|
|
89
|
+
this._data.periodDivisorChange = null;
|
|
98
90
|
|
|
99
|
-
this._data.
|
|
100
|
-
this._data.
|
|
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.
|
|
429
|
-
data.
|
|
430
|
-
data.
|
|
431
|
-
|
|
432
|
-
data.
|
|
433
|
-
data.
|
|
434
|
-
data.
|
|
435
|
-
|
|
436
|
-
data.
|
|
437
|
-
data.
|
|
438
|
-
data.
|
|
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
|
-
|
|
558
|
-
|
|
535
|
+
data.unrealized = unrealized;
|
|
536
|
+
data.unrealizedChange = unrealizedChange;
|
|
559
537
|
|
|
560
|
-
|
|
561
|
-
|
|
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
|
-
|
|
544
|
+
periodGainChange = Decimal.ZERO;
|
|
564
545
|
}
|
|
565
546
|
|
|
566
|
-
data.
|
|
567
|
-
data.
|
|
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.
|
|
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
|
-
|
|
597
|
-
} else {
|
|
598
|
-
returnRef = Decimal.ZERO;
|
|
559
|
+
data.periodGainChange = Decimal.ZERO;
|
|
599
560
|
}
|
|
600
|
-
|
|
601
|
-
return returnRef;
|
|
602
561
|
}
|
|
603
562
|
|
|
604
|
-
function
|
|
563
|
+
function calculatePeriodGain(currentSummary, previousSummary, overridePrice) {
|
|
605
564
|
let returnRef;
|
|
606
565
|
|
|
607
566
|
if (currentSummary) {
|
|
608
|
-
|
|
567
|
+
let startValue;
|
|
609
568
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
569
|
+
if (previousSummary) {
|
|
570
|
+
startValue = previousSummary.end.value;
|
|
571
|
+
} else {
|
|
572
|
+
startValue = Decimal.ZERO;
|
|
573
|
+
}
|
|
614
574
|
|
|
615
|
-
|
|
616
|
-
}
|
|
575
|
+
let endValue;
|
|
617
576
|
|
|
618
|
-
|
|
619
|
-
|
|
577
|
+
if (overridePrice) {
|
|
578
|
+
endValue = currentSummary.end.open.multiply(overridePrice);
|
|
579
|
+
} else {
|
|
580
|
+
endValue = currentSummary.end.value;
|
|
581
|
+
}
|
|
620
582
|
|
|
621
|
-
|
|
622
|
-
const
|
|
583
|
+
const valueChange = endValue.subtract(startValue);
|
|
584
|
+
const tradeChange = currentSummary.period.sells.subtract(currentSummary.period.buys.opposite());
|
|
585
|
+
const incomeChange = currentSummary.period.income;
|
|
623
586
|
|
|
624
|
-
returnRef =
|
|
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
|
-
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
function calculatePeriodUnrealizedBasis(currentSummary, previousSummary) {
|
|
595
|
+
function calculatePeriodDivisor(currentSummary, previousSummary) {
|
|
648
596
|
let returnRef;
|
|
649
597
|
|
|
650
598
|
if (currentSummary) {
|
|
651
|
-
|
|
652
|
-
} else {
|
|
653
|
-
returnRef = Decimal.ZERO;
|
|
654
|
-
}
|
|
599
|
+
let startValue;
|
|
655
600
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
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.
|
|
607
|
+
returnRef = startValue.add(currentSummary.period.buys.opposite());
|
|
666
608
|
} else {
|
|
667
609
|
returnRef = Decimal.ZERO;
|
|
668
610
|
}
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -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.
|
|
2715
|
-
this._dataActual.
|
|
2709
|
+
this._dataActual.periodPercentPrevious = null;
|
|
2710
|
+
this._dataActual.periodPercentPrevious2 = null;
|
|
2716
2711
|
|
|
2717
2712
|
this._dataFormat.periodPercent = null;
|
|
2718
|
-
this._dataFormat.
|
|
2719
|
-
this._dataFormat.
|
|
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.
|
|
3212
|
-
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.
|
|
3213
|
-
updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.
|
|
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.
|
|
3296
|
-
actual.
|
|
3297
|
-
actual.
|
|
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.
|
|
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.
|
|
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.
|
|
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,
|
|
3508
|
-
|
|
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.
|
|
3602
|
-
this._data.periodRealizedPrevious2 = null;
|
|
3583
|
+
this._data.periodUnrealized = null;
|
|
3603
3584
|
|
|
3604
|
-
this._data.
|
|
3605
|
-
this._data.
|
|
3606
|
-
this._data.periodRealizedBasisPrevious2 = null;
|
|
3585
|
+
this._data.periodPrice = null;
|
|
3586
|
+
this._data.periodPricePrevious = null;
|
|
3607
3587
|
|
|
3608
|
-
this._data.
|
|
3609
|
-
this._data.
|
|
3610
|
-
this._data.periodUnrealizedPrevious2 = null;
|
|
3588
|
+
this._data.periodGain = null;
|
|
3589
|
+
this._data.periodGainChange = null;
|
|
3611
3590
|
|
|
3612
|
-
this._data.
|
|
3613
|
-
this._data.
|
|
3614
|
-
this._data.periodUnrealizedBasisPrevious2 = null;
|
|
3591
|
+
this._data.periodGainPrevious = null;
|
|
3592
|
+
this._data.periodGainPrevious2 = null;
|
|
3615
3593
|
|
|
3616
|
-
this._data.
|
|
3594
|
+
this._data.periodDivisor = null;
|
|
3595
|
+
this._data.periodDivisorChange = null;
|
|
3617
3596
|
|
|
3618
|
-
this._data.
|
|
3619
|
-
this._data.
|
|
3597
|
+
this._data.periodDivisorPrevious = null;
|
|
3598
|
+
this._data.periodDivisorPrevious2 = null;
|
|
3620
3599
|
|
|
3621
3600
|
this._data.newsExists = false;
|
|
3622
3601
|
this._data.fundamental = { };
|
|
@@ -3936,31 +3915,21 @@ module.exports = (() => {
|
|
|
3936
3915
|
|
|
3937
3916
|
data.income = snapshot.income;
|
|
3938
3917
|
|
|
3939
|
-
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary, previousSummary1);
|
|
3940
|
-
data.summaryTotalPrevious = calculateSummaryTotal(previousSummary1, previousSummary2);
|
|
3941
|
-
data.summaryTotalPrevious2 = calculateSummaryTotal(previousSummary2, previousSummary3);
|
|
3942
|
-
|
|
3943
3918
|
data.marketPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.value;
|
|
3944
3919
|
data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
|
|
3945
3920
|
data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
|
|
3946
3921
|
|
|
3947
|
-
data.
|
|
3948
|
-
data.
|
|
3949
|
-
data.
|
|
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);
|
|
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;
|
|
3958
3925
|
|
|
3959
|
-
data.
|
|
3960
|
-
data.
|
|
3961
|
-
data.
|
|
3962
|
-
|
|
3963
|
-
data.
|
|
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);
|
|
3964
3933
|
|
|
3965
3934
|
if (snapshot.open.getIsZero()) {
|
|
3966
3935
|
data.basisPrice = Decimal.ZERO;
|
|
@@ -3984,7 +3953,6 @@ module.exports = (() => {
|
|
|
3984
3953
|
function calculatePriceData(item, price) {
|
|
3985
3954
|
const position = item.position;
|
|
3986
3955
|
const snapshot = getSnapshot(position, item.currentSummary, item._reporting);
|
|
3987
|
-
const previousSummaries = item.previousSummaries;
|
|
3988
3956
|
|
|
3989
3957
|
const data = item._data;
|
|
3990
3958
|
|
|
@@ -4045,10 +4013,9 @@ module.exports = (() => {
|
|
|
4045
4013
|
data.unrealizedTodayChange = unrealizedTodayChange;
|
|
4046
4014
|
|
|
4047
4015
|
const currentSummary = item.currentSummary;
|
|
4016
|
+
const previousSummary = getPreviousSummary(item.previousSummaries, 1);
|
|
4048
4017
|
|
|
4049
4018
|
if (currentSummary && position.instrument.type !== InstrumentType.CASH) {
|
|
4050
|
-
const previousSummary = getPreviousSummary(previousSummaries, 1);
|
|
4051
|
-
|
|
4052
4019
|
let priceToUse;
|
|
4053
4020
|
|
|
4054
4021
|
if (price) {
|
|
@@ -4062,8 +4029,6 @@ module.exports = (() => {
|
|
|
4062
4029
|
}
|
|
4063
4030
|
|
|
4064
4031
|
if (priceToUse !== null) {
|
|
4065
|
-
const period = currentSummary.period;
|
|
4066
|
-
|
|
4067
4032
|
let unrealized = currentSummary.end.open.multiply(priceToUse).add(currentSummary.end.basis);
|
|
4068
4033
|
let unrealizedChange;
|
|
4069
4034
|
|
|
@@ -4073,115 +4038,79 @@ module.exports = (() => {
|
|
|
4073
4038
|
unrealizedChange = Decimal.ZERO;
|
|
4074
4039
|
}
|
|
4075
4040
|
|
|
4076
|
-
|
|
4077
|
-
|
|
4041
|
+
data.unrealized = unrealized;
|
|
4042
|
+
data.unrealizedChange = unrealizedChange;
|
|
4078
4043
|
|
|
4079
|
-
|
|
4080
|
-
|
|
4044
|
+
let periodGain = calculatePeriodGain(currentSummary, previousSummary, priceToUse);
|
|
4045
|
+
let periodGainChange;
|
|
4046
|
+
|
|
4047
|
+
if (data.periodGain !== null) {
|
|
4048
|
+
periodGainChange = periodGain.subtract(data.periodGain);
|
|
4081
4049
|
} else {
|
|
4082
|
-
|
|
4050
|
+
periodGainChange = Decimal.ZERO;
|
|
4083
4051
|
}
|
|
4084
4052
|
|
|
4085
|
-
data.
|
|
4086
|
-
data.
|
|
4087
|
-
|
|
4088
|
-
data.unrealized = unrealized;
|
|
4089
|
-
data.unrealizedChange = unrealizedChange;
|
|
4090
|
-
|
|
4091
|
-
data.periodUnrealized = calculatePeriodUnrealized(item.currentSummary, previousSummary, data.unrealized);
|
|
4092
|
-
data.periodUnrealizedChange = unrealizedChange;
|
|
4053
|
+
data.periodGain = periodGain;
|
|
4054
|
+
data.periodGainChange = periodGainChange;
|
|
4093
4055
|
} else {
|
|
4094
|
-
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
4095
|
-
|
|
4096
4056
|
data.unrealized = Decimal.ZERO;
|
|
4097
4057
|
data.unrealizedChange = Decimal.ZERO;
|
|
4098
4058
|
|
|
4099
|
-
data.
|
|
4059
|
+
data.periodGainChange = Decimal.ZERO;
|
|
4100
4060
|
}
|
|
4101
4061
|
} else {
|
|
4102
|
-
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
4103
|
-
|
|
4104
4062
|
data.unrealized = Decimal.ZERO;
|
|
4105
4063
|
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
4064
|
|
|
4115
|
-
|
|
4116
|
-
} else {
|
|
4117
|
-
returnRef = Decimal.ZERO;
|
|
4065
|
+
data.periodGainChange = Decimal.ZERO;
|
|
4118
4066
|
}
|
|
4119
|
-
|
|
4120
|
-
return returnRef;
|
|
4121
4067
|
}
|
|
4122
4068
|
|
|
4123
|
-
function
|
|
4069
|
+
function calculatePeriodGain(currentSummary, previousSummary, overridePrice) {
|
|
4124
4070
|
let returnRef;
|
|
4125
4071
|
|
|
4126
4072
|
if (currentSummary) {
|
|
4127
|
-
|
|
4073
|
+
let startValue;
|
|
4128
4074
|
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4075
|
+
if (previousSummary) {
|
|
4076
|
+
startValue = previousSummary.end.value;
|
|
4077
|
+
} else {
|
|
4078
|
+
startValue = Decimal.ZERO;
|
|
4079
|
+
}
|
|
4133
4080
|
|
|
4134
|
-
|
|
4135
|
-
}
|
|
4081
|
+
let endValue;
|
|
4136
4082
|
|
|
4137
|
-
|
|
4138
|
-
|
|
4083
|
+
if (overridePrice) {
|
|
4084
|
+
endValue = currentSummary.end.open.multiply(overridePrice);
|
|
4085
|
+
} else {
|
|
4086
|
+
endValue = currentSummary.end.value;
|
|
4087
|
+
}
|
|
4139
4088
|
|
|
4140
|
-
|
|
4141
|
-
const
|
|
4089
|
+
const valueChange = endValue.subtract(startValue);
|
|
4090
|
+
const tradeChange = currentSummary.period.sells.subtract(currentSummary.period.buys.opposite());
|
|
4091
|
+
const incomeChange = currentSummary.period.income;
|
|
4142
4092
|
|
|
4143
|
-
returnRef =
|
|
4093
|
+
returnRef = valueChange.add(tradeChange).add(incomeChange);
|
|
4144
4094
|
} else {
|
|
4145
4095
|
returnRef = Decimal.ZERO;
|
|
4146
4096
|
}
|
|
4147
4097
|
|
|
4148
4098
|
return returnRef;
|
|
4149
4099
|
}
|
|
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
4100
|
|
|
4158
|
-
|
|
4159
|
-
} else {
|
|
4160
|
-
returnRef = Decimal.ZERO;
|
|
4161
|
-
}
|
|
4162
|
-
|
|
4163
|
-
return returnRef;
|
|
4164
|
-
}
|
|
4165
|
-
|
|
4166
|
-
function calculatePeriodUnrealizedBasis(currentSummary, previousSummary) {
|
|
4101
|
+
function calculatePeriodDivisor(currentSummary, previousSummary) {
|
|
4167
4102
|
let returnRef;
|
|
4168
4103
|
|
|
4169
4104
|
if (currentSummary) {
|
|
4170
|
-
|
|
4171
|
-
} else {
|
|
4172
|
-
returnRef = Decimal.ZERO;
|
|
4173
|
-
}
|
|
4174
|
-
|
|
4175
|
-
return returnRef;
|
|
4176
|
-
}
|
|
4105
|
+
let startValue;
|
|
4177
4106
|
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4107
|
+
if (previousSummary) {
|
|
4108
|
+
startValue = previousSummary.end.value;
|
|
4109
|
+
} else {
|
|
4110
|
+
startValue = Decimal.ZERO;
|
|
4111
|
+
}
|
|
4183
4112
|
|
|
4184
|
-
returnRef = period.
|
|
4113
|
+
returnRef = startValue.add(currentSummary.period.buys.opposite());
|
|
4185
4114
|
} else {
|
|
4186
4115
|
returnRef = Decimal.ZERO;
|
|
4187
4116
|
}
|