@barchart/portfolio-api-common 1.2.142 → 1.2.143
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,7 @@ module.exports = (() => {
|
|
|
137
137
|
this._dataActual.marketChange = null;
|
|
138
138
|
this._dataActual.marketChangePercent = null;
|
|
139
139
|
this._dataActual.cashTotal = null;
|
|
140
|
+
this._dataActual.totalDivisor = null;
|
|
140
141
|
this._dataActual.periodDivisorCurrent = null;
|
|
141
142
|
this._dataActual.periodDivisorPrevious = null;
|
|
142
143
|
this._dataActual.periodDivisorPrevious2 = null;
|
|
@@ -183,10 +184,12 @@ module.exports = (() => {
|
|
|
183
184
|
this._dataFormat.periodRealized = null;
|
|
184
185
|
this._dataFormat.periodUnrealized = null;
|
|
185
186
|
|
|
187
|
+
this._dataActual.totalPercent = null;
|
|
186
188
|
this._dataActual.periodPercent = null;
|
|
187
189
|
this._dataActual.periodPercentPrevious = null;
|
|
188
190
|
this._dataActual.periodPercentPrevious2 = null;
|
|
189
191
|
|
|
192
|
+
this._dataFormat.totalPercent = null;
|
|
190
193
|
this._dataFormat.periodPercent = null;
|
|
191
194
|
this._dataFormat.periodPercentPrevious = null;
|
|
192
195
|
this._dataFormat.periodPercentPrevious2 = null;
|
|
@@ -695,6 +698,7 @@ module.exports = (() => {
|
|
|
695
698
|
updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
|
|
696
699
|
}
|
|
697
700
|
|
|
701
|
+
updates.totalDivisor = updates.periodDivisorCurrent.add(translate(item, item.data.totalDivisor));
|
|
698
702
|
updates.periodDivisorCurrent = updates.periodDivisorCurrent.add(translate(item, item.data.periodDivisor));
|
|
699
703
|
updates.periodDivisorPrevious = updates.periodDivisorPrevious.add(translate(item, item.data.periodDivisorPrevious));
|
|
700
704
|
updates.periodDivisorPrevious2 = updates.periodDivisorPrevious2.add(translate(item, item.data.periodDivisorPrevious2));
|
|
@@ -714,6 +718,7 @@ module.exports = (() => {
|
|
|
714
718
|
periodUnrealized: Decimal.ZERO,
|
|
715
719
|
periodIncome: Decimal.ZERO,
|
|
716
720
|
cashTotal: Decimal.ZERO,
|
|
721
|
+
totalDivisor: Decimal.ZERO,
|
|
717
722
|
periodDivisorCurrent: Decimal.ZERO,
|
|
718
723
|
periodDivisorPrevious: Decimal.ZERO,
|
|
719
724
|
periodDivisorPrevious2: Decimal.ZERO
|
|
@@ -732,6 +737,7 @@ module.exports = (() => {
|
|
|
732
737
|
actual.periodUnrealized = updates.periodUnrealized;
|
|
733
738
|
actual.periodIncome = updates.periodIncome;
|
|
734
739
|
actual.cashTotal = updates.cashTotal;
|
|
740
|
+
actual.totalDivisor = updates.totalDivisor;
|
|
735
741
|
actual.periodDivisorCurrent = updates.periodDivisorCurrent;
|
|
736
742
|
actual.periodDivisorPrevious = updates.periodDivisorPrevious;
|
|
737
743
|
actual.periodDivisorPrevious2 = updates.periodDivisorPrevious2;
|
|
@@ -755,9 +761,9 @@ module.exports = (() => {
|
|
|
755
761
|
|
|
756
762
|
calculateUnrealizedPercent(group);
|
|
757
763
|
|
|
758
|
-
actual.periodPercent =
|
|
759
|
-
actual.periodPercentPrevious =
|
|
760
|
-
actual.periodPercentPrevious2 =
|
|
764
|
+
actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
765
|
+
actual.periodPercentPrevious = calculateGainPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
|
|
766
|
+
actual.periodPercentPrevious2 = calculateGainPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
|
|
761
767
|
|
|
762
768
|
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
763
769
|
format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
|
|
@@ -864,7 +870,9 @@ module.exports = (() => {
|
|
|
864
870
|
actual.unrealized = updates.unrealized;
|
|
865
871
|
actual.unrealizedToday = updates.unrealizedToday;
|
|
866
872
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
873
|
+
|
|
867
874
|
actual.total = updates.unrealized.add(actual.realized).add(actual.income);
|
|
875
|
+
actual.totalPercent = calculateGainPercent(actual.total, actual.totalDivisor);
|
|
868
876
|
|
|
869
877
|
let marketChange = updates.market.subtract(actual.marketPrevious);
|
|
870
878
|
let marketChangePercent;
|
|
@@ -902,13 +910,14 @@ module.exports = (() => {
|
|
|
902
910
|
|
|
903
911
|
format.total = formatCurrency(actual.total, currency);
|
|
904
912
|
format.totalNegative = actual.total.getIsNegative();
|
|
913
|
+
format.totalPercent = formatPercent(actual.totalPercent, 2);
|
|
905
914
|
|
|
906
915
|
format.marketChange = formatCurrency(actual.marketChange, currency);
|
|
907
916
|
format.marketChangePercent = formatPercent(actual.marketChangePercent, 2);
|
|
908
917
|
|
|
909
918
|
calculateUnrealizedPercent(group);
|
|
910
919
|
|
|
911
|
-
actual.periodPercent =
|
|
920
|
+
actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
912
921
|
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
913
922
|
|
|
914
923
|
if (group.single && item) {
|
|
@@ -972,8 +981,8 @@ module.exports = (() => {
|
|
|
972
981
|
}
|
|
973
982
|
}
|
|
974
983
|
|
|
975
|
-
function
|
|
976
|
-
return
|
|
984
|
+
function calculateGainPercent(gain, basis) {
|
|
985
|
+
return basis.getIsZero() ? Decimal.ZERO : gain.divide(basis);
|
|
977
986
|
}
|
|
978
987
|
|
|
979
988
|
const unchanged = { up: false, down: false };
|
|
@@ -94,6 +94,8 @@ module.exports = (() => {
|
|
|
94
94
|
|
|
95
95
|
this._data.initiate = null;
|
|
96
96
|
|
|
97
|
+
this._data.totalDivisor = null;
|
|
98
|
+
|
|
97
99
|
this._data.newsExists = false;
|
|
98
100
|
this._data.fundamental = { };
|
|
99
101
|
this._data.locked = getIsLocked(position);
|
|
@@ -447,6 +449,8 @@ module.exports = (() => {
|
|
|
447
449
|
} else {
|
|
448
450
|
data.periodPricePrevious = null;
|
|
449
451
|
}
|
|
452
|
+
|
|
453
|
+
data.totalDivisor = calculateTotalDivisor(position.instrument.type, data.initiate, currentSummary);
|
|
450
454
|
}
|
|
451
455
|
|
|
452
456
|
function calculatePriceData(item, price) {
|
|
@@ -641,6 +645,22 @@ module.exports = (() => {
|
|
|
641
645
|
return returnRef;
|
|
642
646
|
}
|
|
643
647
|
|
|
648
|
+
function calculateTotalDivisor(type, direction, finalSummary) {
|
|
649
|
+
let returnRef;
|
|
650
|
+
|
|
651
|
+
if (finalSummary && type !== InstrumentType.CASH) {
|
|
652
|
+
if (direction === PositionDirection.SHORT) {
|
|
653
|
+
returnRef = finalSummary.period.sells;
|
|
654
|
+
} else {
|
|
655
|
+
returnRef = finalSummary.period.buys.opposite();
|
|
656
|
+
}
|
|
657
|
+
} else {
|
|
658
|
+
returnRef = Decimal.ZERO;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return returnRef;
|
|
662
|
+
}
|
|
663
|
+
|
|
644
664
|
function getPreviousSummary(previousSummaries, count) {
|
|
645
665
|
const index = previousSummaries.length - count;
|
|
646
666
|
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -2659,6 +2659,7 @@ module.exports = (() => {
|
|
|
2659
2659
|
this._dataActual.marketChange = null;
|
|
2660
2660
|
this._dataActual.marketChangePercent = null;
|
|
2661
2661
|
this._dataActual.cashTotal = null;
|
|
2662
|
+
this._dataActual.totalDivisor = null;
|
|
2662
2663
|
this._dataActual.periodDivisorCurrent = null;
|
|
2663
2664
|
this._dataActual.periodDivisorPrevious = null;
|
|
2664
2665
|
this._dataActual.periodDivisorPrevious2 = null;
|
|
@@ -2705,10 +2706,12 @@ module.exports = (() => {
|
|
|
2705
2706
|
this._dataFormat.periodRealized = null;
|
|
2706
2707
|
this._dataFormat.periodUnrealized = null;
|
|
2707
2708
|
|
|
2709
|
+
this._dataActual.totalPercent = null;
|
|
2708
2710
|
this._dataActual.periodPercent = null;
|
|
2709
2711
|
this._dataActual.periodPercentPrevious = null;
|
|
2710
2712
|
this._dataActual.periodPercentPrevious2 = null;
|
|
2711
2713
|
|
|
2714
|
+
this._dataFormat.totalPercent = null;
|
|
2712
2715
|
this._dataFormat.periodPercent = null;
|
|
2713
2716
|
this._dataFormat.periodPercentPrevious = null;
|
|
2714
2717
|
this._dataFormat.periodPercentPrevious2 = null;
|
|
@@ -3217,6 +3220,7 @@ module.exports = (() => {
|
|
|
3217
3220
|
updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
|
|
3218
3221
|
}
|
|
3219
3222
|
|
|
3223
|
+
updates.totalDivisor = updates.periodDivisorCurrent.add(translate(item, item.data.totalDivisor));
|
|
3220
3224
|
updates.periodDivisorCurrent = updates.periodDivisorCurrent.add(translate(item, item.data.periodDivisor));
|
|
3221
3225
|
updates.periodDivisorPrevious = updates.periodDivisorPrevious.add(translate(item, item.data.periodDivisorPrevious));
|
|
3222
3226
|
updates.periodDivisorPrevious2 = updates.periodDivisorPrevious2.add(translate(item, item.data.periodDivisorPrevious2));
|
|
@@ -3236,6 +3240,7 @@ module.exports = (() => {
|
|
|
3236
3240
|
periodUnrealized: Decimal.ZERO,
|
|
3237
3241
|
periodIncome: Decimal.ZERO,
|
|
3238
3242
|
cashTotal: Decimal.ZERO,
|
|
3243
|
+
totalDivisor: Decimal.ZERO,
|
|
3239
3244
|
periodDivisorCurrent: Decimal.ZERO,
|
|
3240
3245
|
periodDivisorPrevious: Decimal.ZERO,
|
|
3241
3246
|
periodDivisorPrevious2: Decimal.ZERO
|
|
@@ -3254,6 +3259,7 @@ module.exports = (() => {
|
|
|
3254
3259
|
actual.periodUnrealized = updates.periodUnrealized;
|
|
3255
3260
|
actual.periodIncome = updates.periodIncome;
|
|
3256
3261
|
actual.cashTotal = updates.cashTotal;
|
|
3262
|
+
actual.totalDivisor = updates.totalDivisor;
|
|
3257
3263
|
actual.periodDivisorCurrent = updates.periodDivisorCurrent;
|
|
3258
3264
|
actual.periodDivisorPrevious = updates.periodDivisorPrevious;
|
|
3259
3265
|
actual.periodDivisorPrevious2 = updates.periodDivisorPrevious2;
|
|
@@ -3277,9 +3283,9 @@ module.exports = (() => {
|
|
|
3277
3283
|
|
|
3278
3284
|
calculateUnrealizedPercent(group);
|
|
3279
3285
|
|
|
3280
|
-
actual.periodPercent =
|
|
3281
|
-
actual.periodPercentPrevious =
|
|
3282
|
-
actual.periodPercentPrevious2 =
|
|
3286
|
+
actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
3287
|
+
actual.periodPercentPrevious = calculateGainPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
|
|
3288
|
+
actual.periodPercentPrevious2 = calculateGainPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
|
|
3283
3289
|
|
|
3284
3290
|
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
3285
3291
|
format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
|
|
@@ -3386,7 +3392,9 @@ module.exports = (() => {
|
|
|
3386
3392
|
actual.unrealized = updates.unrealized;
|
|
3387
3393
|
actual.unrealizedToday = updates.unrealizedToday;
|
|
3388
3394
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
3395
|
+
|
|
3389
3396
|
actual.total = updates.unrealized.add(actual.realized).add(actual.income);
|
|
3397
|
+
actual.totalPercent = calculateGainPercent(actual.total, actual.totalDivisor);
|
|
3390
3398
|
|
|
3391
3399
|
let marketChange = updates.market.subtract(actual.marketPrevious);
|
|
3392
3400
|
let marketChangePercent;
|
|
@@ -3424,13 +3432,14 @@ module.exports = (() => {
|
|
|
3424
3432
|
|
|
3425
3433
|
format.total = formatCurrency(actual.total, currency);
|
|
3426
3434
|
format.totalNegative = actual.total.getIsNegative();
|
|
3435
|
+
format.totalPercent = formatPercent(actual.totalPercent, 2);
|
|
3427
3436
|
|
|
3428
3437
|
format.marketChange = formatCurrency(actual.marketChange, currency);
|
|
3429
3438
|
format.marketChangePercent = formatPercent(actual.marketChangePercent, 2);
|
|
3430
3439
|
|
|
3431
3440
|
calculateUnrealizedPercent(group);
|
|
3432
3441
|
|
|
3433
|
-
actual.periodPercent =
|
|
3442
|
+
actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
3434
3443
|
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
3435
3444
|
|
|
3436
3445
|
if (group.single && item) {
|
|
@@ -3494,8 +3503,8 @@ module.exports = (() => {
|
|
|
3494
3503
|
}
|
|
3495
3504
|
}
|
|
3496
3505
|
|
|
3497
|
-
function
|
|
3498
|
-
return
|
|
3506
|
+
function calculateGainPercent(gain, basis) {
|
|
3507
|
+
return basis.getIsZero() ? Decimal.ZERO : gain.divide(basis);
|
|
3499
3508
|
}
|
|
3500
3509
|
|
|
3501
3510
|
const unchanged = { up: false, down: false };
|
|
@@ -3600,6 +3609,8 @@ module.exports = (() => {
|
|
|
3600
3609
|
|
|
3601
3610
|
this._data.initiate = null;
|
|
3602
3611
|
|
|
3612
|
+
this._data.totalDivisor = null;
|
|
3613
|
+
|
|
3603
3614
|
this._data.newsExists = false;
|
|
3604
3615
|
this._data.fundamental = { };
|
|
3605
3616
|
this._data.locked = getIsLocked(position);
|
|
@@ -3953,6 +3964,8 @@ module.exports = (() => {
|
|
|
3953
3964
|
} else {
|
|
3954
3965
|
data.periodPricePrevious = null;
|
|
3955
3966
|
}
|
|
3967
|
+
|
|
3968
|
+
data.totalDivisor = calculateTotalDivisor(position.instrument.type, data.initiate, currentSummary);
|
|
3956
3969
|
}
|
|
3957
3970
|
|
|
3958
3971
|
function calculatePriceData(item, price) {
|
|
@@ -4147,6 +4160,22 @@ module.exports = (() => {
|
|
|
4147
4160
|
return returnRef;
|
|
4148
4161
|
}
|
|
4149
4162
|
|
|
4163
|
+
function calculateTotalDivisor(type, direction, finalSummary) {
|
|
4164
|
+
let returnRef;
|
|
4165
|
+
|
|
4166
|
+
if (finalSummary && type !== InstrumentType.CASH) {
|
|
4167
|
+
if (direction === PositionDirection.SHORT) {
|
|
4168
|
+
returnRef = finalSummary.period.sells;
|
|
4169
|
+
} else {
|
|
4170
|
+
returnRef = finalSummary.period.buys.opposite();
|
|
4171
|
+
}
|
|
4172
|
+
} else {
|
|
4173
|
+
returnRef = Decimal.ZERO;
|
|
4174
|
+
}
|
|
4175
|
+
|
|
4176
|
+
return returnRef;
|
|
4177
|
+
}
|
|
4178
|
+
|
|
4150
4179
|
function getPreviousSummary(previousSummaries, count) {
|
|
4151
4180
|
const index = previousSummaries.length - count;
|
|
4152
4181
|
|