@barchart/portfolio-api-common 1.2.139 → 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.
|
@@ -303,7 +303,7 @@ module.exports = (() => {
|
|
|
303
303
|
const transactionCreateFailedTypeReserved = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_RESERVED', 'Unable to create {U|type.description} transaction, this type of transaction is managed by the system.');
|
|
304
304
|
const transactionCreateFailedReinvestPriceUnavailable = new FailureType('TRANSACTION_CREATE_FAILED_REINVEST_PRICE_UNAVAILABLE', 'Unable to create transaction, a dividend was paid on {L|day}; however no historical price is available for this day. To successfully create this transaction, please turn off dividend reinvestment for this position.');
|
|
305
305
|
const transactionCreateFailedPositionLocked = new FailureType('TRANSACTION_CREATE_FAILED_POSITION_LOCKED', 'Unable to create transaction, your {L|description} history is being recalculated. Please re-enter this transaction in a minute or two.');
|
|
306
|
-
const transactionCreateFailedInstrumentCorrupt = new
|
|
306
|
+
const transactionCreateFailedInstrumentCorrupt = new FailureType('TRANSACTION_CREATE_FAILED_INSTRUMENT_CORRUPT', 'Unable to create transaction, corporate action history for {U|symbol} cannot be located.');
|
|
307
307
|
|
|
308
308
|
const transactionDeleteFailedOutOfSequence = new FailureType('TRANSACTION_DELETE_FAILED_OUT_OF_SEQUENCE', 'Deleting any transaction, except for the most recent, will cause transaction history to be re-written. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
|
|
309
309
|
const transactionDeleteFailedNoTransaction = new FailureType('TRANSACTION_DELETE_FAILED_NO_TRANSACTION', 'Unable to delete transaction. The referenced transaction does not exist.');
|
|
@@ -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,6 +761,14 @@ module.exports = (() => {
|
|
|
755
761
|
|
|
756
762
|
calculateUnrealizedPercent(group);
|
|
757
763
|
|
|
764
|
+
actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
765
|
+
actual.periodPercentPrevious = calculateGainPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
|
|
766
|
+
actual.periodPercentPrevious2 = calculateGainPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
|
|
767
|
+
|
|
768
|
+
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
769
|
+
format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
|
|
770
|
+
format.periodPercentPrevious2 = formatPercent(actual.periodPercentPrevious2, 2);
|
|
771
|
+
|
|
758
772
|
const groupItems = group._items;
|
|
759
773
|
|
|
760
774
|
if (group.single && groupItems.length === 1) {
|
|
@@ -762,28 +776,20 @@ module.exports = (() => {
|
|
|
762
776
|
|
|
763
777
|
actual.quantity = item.data.quantity;
|
|
764
778
|
actual.quantityPrevious = item.data.quantityPrevious;
|
|
765
|
-
|
|
766
|
-
actual.basisPrice = item.data.basisPrice;
|
|
767
|
-
|
|
768
|
-
actual.periodPrice = item.data.periodPrice;
|
|
769
|
-
actual.periodPricePrevious = item.data.periodPricePrevious;
|
|
770
779
|
|
|
771
780
|
format.quantity = formatDecimal(actual.quantity, 2);
|
|
772
781
|
format.quantityPrevious = formatDecimal(actual.quantityPrevious, 2);
|
|
773
782
|
|
|
783
|
+
actual.basisPrice = item.data.basisPrice;
|
|
784
|
+
|
|
774
785
|
format.basisPrice = formatCurrency(actual.basisPrice, currency);
|
|
775
786
|
|
|
787
|
+
actual.periodPrice = item.data.periodPrice;
|
|
788
|
+
actual.periodPricePrevious = item.data.periodPricePrevious;
|
|
789
|
+
|
|
776
790
|
format.periodPrice = formatCurrency(actual.periodPrice, currency);
|
|
777
791
|
format.periodPricePrevious = formatCurrency(actual.periodPricePrevious, currency);
|
|
778
792
|
|
|
779
|
-
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
780
|
-
actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
|
|
781
|
-
actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
|
|
782
|
-
|
|
783
|
-
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
784
|
-
format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
|
|
785
|
-
format.periodPercentPrevious2 = formatPercent(actual.periodPercentPrevious2, 2);
|
|
786
|
-
|
|
787
793
|
format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
|
|
788
794
|
format.locked = definition.type === PositionLevelType.POSITION && item.data.locked;
|
|
789
795
|
}
|
|
@@ -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,17 +910,18 @@ 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
|
|
|
920
|
+
actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
921
|
+
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
922
|
+
|
|
911
923
|
if (group.single && item) {
|
|
912
924
|
actual.periodUnrealized = item.data.periodUnrealized;
|
|
913
|
-
|
|
914
|
-
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
915
|
-
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
916
925
|
}
|
|
917
926
|
}
|
|
918
927
|
|
|
@@ -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);
|
|
@@ -422,13 +424,13 @@ module.exports = (() => {
|
|
|
422
424
|
data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
|
|
423
425
|
data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
|
|
424
426
|
|
|
425
|
-
data.periodGain = calculatePeriodGain(data.initiate, currentSummary, previousSummary1);
|
|
426
|
-
data.periodGainPrevious = calculatePeriodGain(data.initiate, previousSummary1, previousSummary2);
|
|
427
|
-
data.periodGainPrevious2 = calculatePeriodGain(data.initiate, previousSummary2, previousSummary3);
|
|
427
|
+
data.periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary1);
|
|
428
|
+
data.periodGainPrevious = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
|
|
429
|
+
data.periodGainPrevious2 = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
|
|
428
430
|
|
|
429
|
-
data.periodDivisor = calculatePeriodDivisor(data.initiate, currentSummary, previousSummary1);
|
|
430
|
-
data.periodDivisorPrevious = calculatePeriodDivisor(data.initiate, previousSummary1, previousSummary2);
|
|
431
|
-
data.periodDivisorPrevious2 = calculatePeriodDivisor(data.initiate, previousSummary2, previousSummary3);
|
|
431
|
+
data.periodDivisor = calculatePeriodDivisor(position.instrument.type, data.initiate, currentSummary, previousSummary1);
|
|
432
|
+
data.periodDivisorPrevious = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
|
|
433
|
+
data.periodDivisorPrevious2 = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
|
|
432
434
|
|
|
433
435
|
if (snapshot.open.getIsZero()) {
|
|
434
436
|
data.basisPrice = Decimal.ZERO;
|
|
@@ -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) {
|
|
@@ -540,7 +544,7 @@ module.exports = (() => {
|
|
|
540
544
|
data.unrealized = unrealized;
|
|
541
545
|
data.unrealizedChange = unrealizedChange;
|
|
542
546
|
|
|
543
|
-
let periodGain = calculatePeriodGain(data.initiate, currentSummary, previousSummary, priceToUse);
|
|
547
|
+
let periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary, priceToUse);
|
|
544
548
|
let periodGainChange;
|
|
545
549
|
|
|
546
550
|
if (data.periodGain !== null) {
|
|
@@ -585,10 +589,10 @@ module.exports = (() => {
|
|
|
585
589
|
return direction || PositionDirection.LONG;
|
|
586
590
|
}
|
|
587
591
|
|
|
588
|
-
function calculatePeriodGain(direction, currentSummary, previousSummary, overridePrice) {
|
|
592
|
+
function calculatePeriodGain(type, direction, currentSummary, previousSummary, overridePrice) {
|
|
589
593
|
let returnRef;
|
|
590
594
|
|
|
591
|
-
if (currentSummary) {
|
|
595
|
+
if (currentSummary && type !== InstrumentType.CASH) {
|
|
592
596
|
let startValue;
|
|
593
597
|
|
|
594
598
|
if (previousSummary) {
|
|
@@ -617,10 +621,10 @@ module.exports = (() => {
|
|
|
617
621
|
return returnRef;
|
|
618
622
|
}
|
|
619
623
|
|
|
620
|
-
function calculatePeriodDivisor(direction, currentSummary, previousSummary) {
|
|
624
|
+
function calculatePeriodDivisor(type, direction, currentSummary, previousSummary) {
|
|
621
625
|
let returnRef;
|
|
622
626
|
|
|
623
|
-
if (currentSummary) {
|
|
627
|
+
if (currentSummary && type !== InstrumentType.CASH) {
|
|
624
628
|
let startValue;
|
|
625
629
|
|
|
626
630
|
if (previousSummary) {
|
|
@@ -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,6 +3283,14 @@ module.exports = (() => {
|
|
|
3277
3283
|
|
|
3278
3284
|
calculateUnrealizedPercent(group);
|
|
3279
3285
|
|
|
3286
|
+
actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
3287
|
+
actual.periodPercentPrevious = calculateGainPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
|
|
3288
|
+
actual.periodPercentPrevious2 = calculateGainPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
|
|
3289
|
+
|
|
3290
|
+
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
3291
|
+
format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
|
|
3292
|
+
format.periodPercentPrevious2 = formatPercent(actual.periodPercentPrevious2, 2);
|
|
3293
|
+
|
|
3280
3294
|
const groupItems = group._items;
|
|
3281
3295
|
|
|
3282
3296
|
if (group.single && groupItems.length === 1) {
|
|
@@ -3284,28 +3298,20 @@ module.exports = (() => {
|
|
|
3284
3298
|
|
|
3285
3299
|
actual.quantity = item.data.quantity;
|
|
3286
3300
|
actual.quantityPrevious = item.data.quantityPrevious;
|
|
3287
|
-
|
|
3288
|
-
actual.basisPrice = item.data.basisPrice;
|
|
3289
|
-
|
|
3290
|
-
actual.periodPrice = item.data.periodPrice;
|
|
3291
|
-
actual.periodPricePrevious = item.data.periodPricePrevious;
|
|
3292
3301
|
|
|
3293
3302
|
format.quantity = formatDecimal(actual.quantity, 2);
|
|
3294
3303
|
format.quantityPrevious = formatDecimal(actual.quantityPrevious, 2);
|
|
3295
3304
|
|
|
3305
|
+
actual.basisPrice = item.data.basisPrice;
|
|
3306
|
+
|
|
3296
3307
|
format.basisPrice = formatCurrency(actual.basisPrice, currency);
|
|
3297
3308
|
|
|
3309
|
+
actual.periodPrice = item.data.periodPrice;
|
|
3310
|
+
actual.periodPricePrevious = item.data.periodPricePrevious;
|
|
3311
|
+
|
|
3298
3312
|
format.periodPrice = formatCurrency(actual.periodPrice, currency);
|
|
3299
3313
|
format.periodPricePrevious = formatCurrency(actual.periodPricePrevious, currency);
|
|
3300
3314
|
|
|
3301
|
-
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
3302
|
-
actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
|
|
3303
|
-
actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
|
|
3304
|
-
|
|
3305
|
-
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
3306
|
-
format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
|
|
3307
|
-
format.periodPercentPrevious2 = formatPercent(actual.periodPercentPrevious2, 2);
|
|
3308
|
-
|
|
3309
3315
|
format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
|
|
3310
3316
|
format.locked = definition.type === PositionLevelType.POSITION && item.data.locked;
|
|
3311
3317
|
}
|
|
@@ -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,17 +3432,18 @@ 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
|
|
|
3442
|
+
actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
3443
|
+
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
3444
|
+
|
|
3433
3445
|
if (group.single && item) {
|
|
3434
3446
|
actual.periodUnrealized = item.data.periodUnrealized;
|
|
3435
|
-
|
|
3436
|
-
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
3437
|
-
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
3438
3447
|
}
|
|
3439
3448
|
}
|
|
3440
3449
|
|
|
@@ -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);
|
|
@@ -3928,13 +3939,13 @@ module.exports = (() => {
|
|
|
3928
3939
|
data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
|
|
3929
3940
|
data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
|
|
3930
3941
|
|
|
3931
|
-
data.periodGain = calculatePeriodGain(data.initiate, currentSummary, previousSummary1);
|
|
3932
|
-
data.periodGainPrevious = calculatePeriodGain(data.initiate, previousSummary1, previousSummary2);
|
|
3933
|
-
data.periodGainPrevious2 = calculatePeriodGain(data.initiate, previousSummary2, previousSummary3);
|
|
3942
|
+
data.periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary1);
|
|
3943
|
+
data.periodGainPrevious = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
|
|
3944
|
+
data.periodGainPrevious2 = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
|
|
3934
3945
|
|
|
3935
|
-
data.periodDivisor = calculatePeriodDivisor(data.initiate, currentSummary, previousSummary1);
|
|
3936
|
-
data.periodDivisorPrevious = calculatePeriodDivisor(data.initiate, previousSummary1, previousSummary2);
|
|
3937
|
-
data.periodDivisorPrevious2 = calculatePeriodDivisor(data.initiate, previousSummary2, previousSummary3);
|
|
3946
|
+
data.periodDivisor = calculatePeriodDivisor(position.instrument.type, data.initiate, currentSummary, previousSummary1);
|
|
3947
|
+
data.periodDivisorPrevious = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
|
|
3948
|
+
data.periodDivisorPrevious2 = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
|
|
3938
3949
|
|
|
3939
3950
|
if (snapshot.open.getIsZero()) {
|
|
3940
3951
|
data.basisPrice = Decimal.ZERO;
|
|
@@ -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) {
|
|
@@ -4046,7 +4059,7 @@ module.exports = (() => {
|
|
|
4046
4059
|
data.unrealized = unrealized;
|
|
4047
4060
|
data.unrealizedChange = unrealizedChange;
|
|
4048
4061
|
|
|
4049
|
-
let periodGain = calculatePeriodGain(data.initiate, currentSummary, previousSummary, priceToUse);
|
|
4062
|
+
let periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary, priceToUse);
|
|
4050
4063
|
let periodGainChange;
|
|
4051
4064
|
|
|
4052
4065
|
if (data.periodGain !== null) {
|
|
@@ -4091,10 +4104,10 @@ module.exports = (() => {
|
|
|
4091
4104
|
return direction || PositionDirection.LONG;
|
|
4092
4105
|
}
|
|
4093
4106
|
|
|
4094
|
-
function calculatePeriodGain(direction, currentSummary, previousSummary, overridePrice) {
|
|
4107
|
+
function calculatePeriodGain(type, direction, currentSummary, previousSummary, overridePrice) {
|
|
4095
4108
|
let returnRef;
|
|
4096
4109
|
|
|
4097
|
-
if (currentSummary) {
|
|
4110
|
+
if (currentSummary && type !== InstrumentType.CASH) {
|
|
4098
4111
|
let startValue;
|
|
4099
4112
|
|
|
4100
4113
|
if (previousSummary) {
|
|
@@ -4123,10 +4136,10 @@ module.exports = (() => {
|
|
|
4123
4136
|
return returnRef;
|
|
4124
4137
|
}
|
|
4125
4138
|
|
|
4126
|
-
function calculatePeriodDivisor(direction, currentSummary, previousSummary) {
|
|
4139
|
+
function calculatePeriodDivisor(type, direction, currentSummary, previousSummary) {
|
|
4127
4140
|
let returnRef;
|
|
4128
4141
|
|
|
4129
|
-
if (currentSummary) {
|
|
4142
|
+
if (currentSummary && type !== InstrumentType.CASH) {
|
|
4130
4143
|
let startValue;
|
|
4131
4144
|
|
|
4132
4145
|
if (previousSummary) {
|
|
@@ -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
|
|