@barchart/portfolio-api-common 1.2.89 → 1.2.90
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.
|
@@ -130,6 +130,10 @@ module.exports = (() => {
|
|
|
130
130
|
this._dataActual.summaryTotalCurrent = null;
|
|
131
131
|
this._dataActual.summaryTotalPrevious = null;
|
|
132
132
|
this._dataActual.summaryTotalPrevious2 = null;
|
|
133
|
+
this._dataActual.endingPrevious = null;
|
|
134
|
+
this._dataActual.endingPrevious2 = null;
|
|
135
|
+
this._dataActual.endingChange = null;
|
|
136
|
+
this._dataActual.endingChangePercent = null;
|
|
133
137
|
this._dataActual.cashTotal = null;
|
|
134
138
|
|
|
135
139
|
this._dataFormat.currentPrice = null;
|
|
@@ -153,6 +157,10 @@ module.exports = (() => {
|
|
|
153
157
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
154
158
|
this._dataFormat.summaryTotalPrevious2 = null;
|
|
155
159
|
this._dataFormat.summaryTotalPrevious2Negative = false;
|
|
160
|
+
this._dataFormat.endingPrevious = null;
|
|
161
|
+
this._dataFormat.endingPrevious2 = null;
|
|
162
|
+
this._dataFormat.endingChange = null;
|
|
163
|
+
this._dataFormat.endingChangePercent = null;
|
|
156
164
|
this._dataFormat.cashTotal = null;
|
|
157
165
|
this._dataFormat.portfolioType = null;
|
|
158
166
|
|
|
@@ -388,8 +396,6 @@ module.exports = (() => {
|
|
|
388
396
|
return;
|
|
389
397
|
}
|
|
390
398
|
|
|
391
|
-
const descriptionSelector = this._definition.descriptionSelector;
|
|
392
|
-
|
|
393
399
|
this._description = PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio);
|
|
394
400
|
|
|
395
401
|
this._dataActual.description = this._description;
|
|
@@ -634,7 +640,7 @@ module.exports = (() => {
|
|
|
634
640
|
const translate = (item, value) => {
|
|
635
641
|
let translated;
|
|
636
642
|
|
|
637
|
-
if (item.currency !== currency) {
|
|
643
|
+
if (item.currency !== currency && !value.getIsZero()) {
|
|
638
644
|
translated = Rate.convert(value, item.currency, currency, ...rates);
|
|
639
645
|
} else {
|
|
640
646
|
translated = value;
|
|
@@ -651,6 +657,8 @@ module.exports = (() => {
|
|
|
651
657
|
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
|
|
652
658
|
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
|
|
653
659
|
updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.summaryTotalPrevious2));
|
|
660
|
+
updates.endingPrevious = updates.endingPrevious.add(translate(item, item.data.endingPrevious));
|
|
661
|
+
updates.endingPrevious2 = updates.endingPrevious2.add(translate(item, item.data.endingPrevious2));
|
|
654
662
|
|
|
655
663
|
if (item.position.instrument.type === InstrumentType.CASH) {
|
|
656
664
|
updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
|
|
@@ -665,6 +673,8 @@ module.exports = (() => {
|
|
|
665
673
|
summaryTotalCurrent: Decimal.ZERO,
|
|
666
674
|
summaryTotalPrevious: Decimal.ZERO,
|
|
667
675
|
summaryTotalPrevious2: Decimal.ZERO,
|
|
676
|
+
endingPrevious: Decimal.ZERO,
|
|
677
|
+
endingPrevious2: Decimal.ZERO,
|
|
668
678
|
cashTotal: Decimal.ZERO
|
|
669
679
|
});
|
|
670
680
|
|
|
@@ -675,6 +685,8 @@ module.exports = (() => {
|
|
|
675
685
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
676
686
|
actual.summaryTotalPrevious = updates.summaryTotalPrevious;
|
|
677
687
|
actual.summaryTotalPrevious2 = updates.summaryTotalPrevious2;
|
|
688
|
+
actual.endingPrevious = updates.endingPrevious;
|
|
689
|
+
actual.endingPrevious2 = updates.endingPrevious2;
|
|
678
690
|
actual.cashTotal = updates.cashTotal;
|
|
679
691
|
|
|
680
692
|
format.basis = formatCurrency(actual.basis, currency);
|
|
@@ -686,6 +698,8 @@ module.exports = (() => {
|
|
|
686
698
|
format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
|
|
687
699
|
format.summaryTotalPrevious2 = formatCurrency(updates.summaryTotalPrevious2, currency);
|
|
688
700
|
format.summaryTotalPrevious2Negative = updates.summaryTotalPrevious2.getIsNegative();
|
|
701
|
+
format.endingPrevious = formatCurrency(updates.endingPrevious, currency);
|
|
702
|
+
format.endingPrevious2 = formatCurrency(updates.endingPrevious2, currency);
|
|
689
703
|
format.cashTotal = formatCurrency(updates.cashTotal, currency);
|
|
690
704
|
|
|
691
705
|
calculateUnrealizedPercent(group);
|
|
@@ -735,7 +749,7 @@ module.exports = (() => {
|
|
|
735
749
|
const translate = (item, value) => {
|
|
736
750
|
let translated;
|
|
737
751
|
|
|
738
|
-
if (item.currency !== currency) {
|
|
752
|
+
if (item.currency !== currency && !value.getIsZero()) {
|
|
739
753
|
translated = Rate.convert(value, item.currency, currency, ...rates);
|
|
740
754
|
} else {
|
|
741
755
|
translated = value;
|
|
@@ -782,7 +796,25 @@ module.exports = (() => {
|
|
|
782
796
|
actual.unrealizedToday = updates.unrealizedToday;
|
|
783
797
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
784
798
|
actual.total = updates.unrealized.add(actual.realized).add(actual.income);
|
|
785
|
-
|
|
799
|
+
|
|
800
|
+
let endingChange = updates.market.subtract(actual.endingPrevious);
|
|
801
|
+
let endingChangePercent;
|
|
802
|
+
|
|
803
|
+
if (actual.endingPrevious.getIsZero()) {
|
|
804
|
+
if (endingChange.getIsPositive()) {
|
|
805
|
+
endingChangePercent = Decimal.ONE;
|
|
806
|
+
} else if (endingChange.getIsNegative()) {
|
|
807
|
+
endingChangePercent = Decimal.NEGATIVE_ONE;
|
|
808
|
+
} else {
|
|
809
|
+
endingChangePercent = Decimal.ZERO;
|
|
810
|
+
}
|
|
811
|
+
} else {
|
|
812
|
+
endingChangePercent = endingChange.divide(actual.endingPrevious);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
actual.endingChange = endingChange;
|
|
816
|
+
actual.endingChangePercent = endingChangePercent;
|
|
817
|
+
|
|
786
818
|
format.market = formatCurrency(actual.market, currency);
|
|
787
819
|
|
|
788
820
|
if (updates.marketDirection.up || updates.marketDirection.down) {
|
|
@@ -802,6 +834,9 @@ module.exports = (() => {
|
|
|
802
834
|
format.total = formatCurrency(actual.total, currency);
|
|
803
835
|
format.totalNegative = actual.total.getIsNegative();
|
|
804
836
|
|
|
837
|
+
format.endingChange = formatCurrency(actual.endingChange, currency);
|
|
838
|
+
format.endingChangePercent = formatPercent(actual.endingChangePercent, 2);
|
|
839
|
+
|
|
805
840
|
calculateUnrealizedPercent(group);
|
|
806
841
|
}
|
|
807
842
|
|
|
@@ -65,6 +65,9 @@ module.exports = (() => {
|
|
|
65
65
|
this._data.summaryTotalPrevious = null;
|
|
66
66
|
this._data.summaryTotalPrevious2 = null;
|
|
67
67
|
|
|
68
|
+
this._data.endingPrevious = null;
|
|
69
|
+
this._data.endingPrevious2 = null;
|
|
70
|
+
|
|
68
71
|
this._data.realized = null;
|
|
69
72
|
this._data.income = null;
|
|
70
73
|
this._data.basisPrice = null;
|
|
@@ -380,9 +383,16 @@ module.exports = (() => {
|
|
|
380
383
|
|
|
381
384
|
data.income = snapshot.income;
|
|
382
385
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
+
const previousSummary1 = getPreviousSummary(previousSummaries, 1);
|
|
387
|
+
const previousSummary2 = getPreviousSummary(previousSummaries, 2);
|
|
388
|
+
const previousSummary3 = getPreviousSummary(previousSummaries, 3);
|
|
389
|
+
|
|
390
|
+
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary, previousSummary1);
|
|
391
|
+
data.summaryTotalPrevious = calculateSummaryTotal(previousSummary1, previousSummary2);
|
|
392
|
+
data.summaryTotalPrevious2 = calculateSummaryTotal(previousSummary2, previousSummary3);
|
|
393
|
+
|
|
394
|
+
data.endingPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.value;
|
|
395
|
+
data.endingPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
|
|
386
396
|
|
|
387
397
|
if (snapshot.open.getIsZero()) {
|
|
388
398
|
data.basisPrice = Decimal.ZERO;
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -2515,6 +2515,10 @@ module.exports = (() => {
|
|
|
2515
2515
|
this._dataActual.summaryTotalCurrent = null;
|
|
2516
2516
|
this._dataActual.summaryTotalPrevious = null;
|
|
2517
2517
|
this._dataActual.summaryTotalPrevious2 = null;
|
|
2518
|
+
this._dataActual.endingPrevious = null;
|
|
2519
|
+
this._dataActual.endingPrevious2 = null;
|
|
2520
|
+
this._dataActual.endingChange = null;
|
|
2521
|
+
this._dataActual.endingChangePercent = null;
|
|
2518
2522
|
this._dataActual.cashTotal = null;
|
|
2519
2523
|
|
|
2520
2524
|
this._dataFormat.currentPrice = null;
|
|
@@ -2538,6 +2542,10 @@ module.exports = (() => {
|
|
|
2538
2542
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
2539
2543
|
this._dataFormat.summaryTotalPrevious2 = null;
|
|
2540
2544
|
this._dataFormat.summaryTotalPrevious2Negative = false;
|
|
2545
|
+
this._dataFormat.endingPrevious = null;
|
|
2546
|
+
this._dataFormat.endingPrevious2 = null;
|
|
2547
|
+
this._dataFormat.endingChange = null;
|
|
2548
|
+
this._dataFormat.endingChangePercent = null;
|
|
2541
2549
|
this._dataFormat.cashTotal = null;
|
|
2542
2550
|
this._dataFormat.portfolioType = null;
|
|
2543
2551
|
|
|
@@ -2773,8 +2781,6 @@ module.exports = (() => {
|
|
|
2773
2781
|
return;
|
|
2774
2782
|
}
|
|
2775
2783
|
|
|
2776
|
-
const descriptionSelector = this._definition.descriptionSelector;
|
|
2777
|
-
|
|
2778
2784
|
this._description = PositionLevelDefinition.getDescriptionForPortfolioGroup(portfolio);
|
|
2779
2785
|
|
|
2780
2786
|
this._dataActual.description = this._description;
|
|
@@ -3019,7 +3025,7 @@ module.exports = (() => {
|
|
|
3019
3025
|
const translate = (item, value) => {
|
|
3020
3026
|
let translated;
|
|
3021
3027
|
|
|
3022
|
-
if (item.currency !== currency) {
|
|
3028
|
+
if (item.currency !== currency && !value.getIsZero()) {
|
|
3023
3029
|
translated = Rate.convert(value, item.currency, currency, ...rates);
|
|
3024
3030
|
} else {
|
|
3025
3031
|
translated = value;
|
|
@@ -3036,6 +3042,8 @@ module.exports = (() => {
|
|
|
3036
3042
|
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
|
|
3037
3043
|
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
|
|
3038
3044
|
updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.summaryTotalPrevious2));
|
|
3045
|
+
updates.endingPrevious = updates.endingPrevious.add(translate(item, item.data.endingPrevious));
|
|
3046
|
+
updates.endingPrevious2 = updates.endingPrevious2.add(translate(item, item.data.endingPrevious2));
|
|
3039
3047
|
|
|
3040
3048
|
if (item.position.instrument.type === InstrumentType.CASH) {
|
|
3041
3049
|
updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
|
|
@@ -3050,6 +3058,8 @@ module.exports = (() => {
|
|
|
3050
3058
|
summaryTotalCurrent: Decimal.ZERO,
|
|
3051
3059
|
summaryTotalPrevious: Decimal.ZERO,
|
|
3052
3060
|
summaryTotalPrevious2: Decimal.ZERO,
|
|
3061
|
+
endingPrevious: Decimal.ZERO,
|
|
3062
|
+
endingPrevious2: Decimal.ZERO,
|
|
3053
3063
|
cashTotal: Decimal.ZERO
|
|
3054
3064
|
});
|
|
3055
3065
|
|
|
@@ -3060,6 +3070,8 @@ module.exports = (() => {
|
|
|
3060
3070
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
3061
3071
|
actual.summaryTotalPrevious = updates.summaryTotalPrevious;
|
|
3062
3072
|
actual.summaryTotalPrevious2 = updates.summaryTotalPrevious2;
|
|
3073
|
+
actual.endingPrevious = updates.endingPrevious;
|
|
3074
|
+
actual.endingPrevious2 = updates.endingPrevious2;
|
|
3063
3075
|
actual.cashTotal = updates.cashTotal;
|
|
3064
3076
|
|
|
3065
3077
|
format.basis = formatCurrency(actual.basis, currency);
|
|
@@ -3071,6 +3083,8 @@ module.exports = (() => {
|
|
|
3071
3083
|
format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
|
|
3072
3084
|
format.summaryTotalPrevious2 = formatCurrency(updates.summaryTotalPrevious2, currency);
|
|
3073
3085
|
format.summaryTotalPrevious2Negative = updates.summaryTotalPrevious2.getIsNegative();
|
|
3086
|
+
format.endingPrevious = formatCurrency(updates.endingPrevious, currency);
|
|
3087
|
+
format.endingPrevious2 = formatCurrency(updates.endingPrevious2, currency);
|
|
3074
3088
|
format.cashTotal = formatCurrency(updates.cashTotal, currency);
|
|
3075
3089
|
|
|
3076
3090
|
calculateUnrealizedPercent(group);
|
|
@@ -3120,7 +3134,7 @@ module.exports = (() => {
|
|
|
3120
3134
|
const translate = (item, value) => {
|
|
3121
3135
|
let translated;
|
|
3122
3136
|
|
|
3123
|
-
if (item.currency !== currency) {
|
|
3137
|
+
if (item.currency !== currency && !value.getIsZero()) {
|
|
3124
3138
|
translated = Rate.convert(value, item.currency, currency, ...rates);
|
|
3125
3139
|
} else {
|
|
3126
3140
|
translated = value;
|
|
@@ -3167,7 +3181,25 @@ module.exports = (() => {
|
|
|
3167
3181
|
actual.unrealizedToday = updates.unrealizedToday;
|
|
3168
3182
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
3169
3183
|
actual.total = updates.unrealized.add(actual.realized).add(actual.income);
|
|
3170
|
-
|
|
3184
|
+
|
|
3185
|
+
let endingChange = updates.market.subtract(actual.endingPrevious);
|
|
3186
|
+
let endingChangePercent;
|
|
3187
|
+
|
|
3188
|
+
if (actual.endingPrevious.getIsZero()) {
|
|
3189
|
+
if (endingChange.getIsPositive()) {
|
|
3190
|
+
endingChangePercent = Decimal.ONE;
|
|
3191
|
+
} else if (endingChange.getIsNegative()) {
|
|
3192
|
+
endingChangePercent = Decimal.NEGATIVE_ONE;
|
|
3193
|
+
} else {
|
|
3194
|
+
endingChangePercent = Decimal.ZERO;
|
|
3195
|
+
}
|
|
3196
|
+
} else {
|
|
3197
|
+
endingChangePercent = endingChange.divide(actual.endingPrevious);
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
actual.endingChange = endingChange;
|
|
3201
|
+
actual.endingChangePercent = endingChangePercent;
|
|
3202
|
+
|
|
3171
3203
|
format.market = formatCurrency(actual.market, currency);
|
|
3172
3204
|
|
|
3173
3205
|
if (updates.marketDirection.up || updates.marketDirection.down) {
|
|
@@ -3187,6 +3219,9 @@ module.exports = (() => {
|
|
|
3187
3219
|
format.total = formatCurrency(actual.total, currency);
|
|
3188
3220
|
format.totalNegative = actual.total.getIsNegative();
|
|
3189
3221
|
|
|
3222
|
+
format.endingChange = formatCurrency(actual.endingChange, currency);
|
|
3223
|
+
format.endingChangePercent = formatPercent(actual.endingChangePercent, 2);
|
|
3224
|
+
|
|
3190
3225
|
calculateUnrealizedPercent(group);
|
|
3191
3226
|
}
|
|
3192
3227
|
|
|
@@ -3319,6 +3354,9 @@ module.exports = (() => {
|
|
|
3319
3354
|
this._data.summaryTotalPrevious = null;
|
|
3320
3355
|
this._data.summaryTotalPrevious2 = null;
|
|
3321
3356
|
|
|
3357
|
+
this._data.endingPrevious = null;
|
|
3358
|
+
this._data.endingPrevious2 = null;
|
|
3359
|
+
|
|
3322
3360
|
this._data.realized = null;
|
|
3323
3361
|
this._data.income = null;
|
|
3324
3362
|
this._data.basisPrice = null;
|
|
@@ -3634,9 +3672,16 @@ module.exports = (() => {
|
|
|
3634
3672
|
|
|
3635
3673
|
data.income = snapshot.income;
|
|
3636
3674
|
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3675
|
+
const previousSummary1 = getPreviousSummary(previousSummaries, 1);
|
|
3676
|
+
const previousSummary2 = getPreviousSummary(previousSummaries, 2);
|
|
3677
|
+
const previousSummary3 = getPreviousSummary(previousSummaries, 3);
|
|
3678
|
+
|
|
3679
|
+
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary, previousSummary1);
|
|
3680
|
+
data.summaryTotalPrevious = calculateSummaryTotal(previousSummary1, previousSummary2);
|
|
3681
|
+
data.summaryTotalPrevious2 = calculateSummaryTotal(previousSummary2, previousSummary3);
|
|
3682
|
+
|
|
3683
|
+
data.endingPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.value;
|
|
3684
|
+
data.endingPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
|
|
3640
3685
|
|
|
3641
3686
|
if (snapshot.open.getIsZero()) {
|
|
3642
3687
|
data.basisPrice = Decimal.ZERO;
|