@barchart/portfolio-api-common 1.2.144 → 1.2.145
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 +15 -11
- package/package.json +1 -1
- package/test/SpecRunner.js +15 -11
|
@@ -978,28 +978,32 @@ module.exports = (() => {
|
|
|
978
978
|
const openBasis = actual.basis;
|
|
979
979
|
const totalBasis = actual.totalDivisor;
|
|
980
980
|
|
|
981
|
-
const
|
|
981
|
+
const numerator = actual.realized;
|
|
982
|
+
const denominator = totalBasis.subtract(openBasis);
|
|
982
983
|
|
|
983
|
-
if (
|
|
984
|
-
actual.realizedPercent =
|
|
985
|
-
format.realizedPercent = '—';
|
|
984
|
+
if (denominator.getIsZero()) {
|
|
985
|
+
actual.realizedPercent = Decimal.ZERO;
|
|
986
986
|
} else {
|
|
987
|
-
actual.realizedPercent =
|
|
988
|
-
format.realizedPercent = formatPercent(actual.realizedPercent, 2);
|
|
987
|
+
actual.realizedPercent = numerator.divide(denominator);
|
|
989
988
|
}
|
|
989
|
+
|
|
990
|
+
format.realizedPercent = formatPercent(actual.realizedPercent, 2);
|
|
990
991
|
}
|
|
991
992
|
|
|
992
993
|
function calculateUnrealizedPercent(group) {
|
|
993
994
|
const actual = group._dataActual;
|
|
994
995
|
const format = group._dataFormat;
|
|
995
996
|
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
997
|
+
const numerator = actual.unrealized;
|
|
998
|
+
const denominator = actual.basis;
|
|
999
|
+
|
|
1000
|
+
if (denominator.getIsZero()) {
|
|
1001
|
+
actual.unrealizedPercent = Decimal.ZERO;
|
|
999
1002
|
} else {
|
|
1000
|
-
actual.unrealizedPercent =
|
|
1001
|
-
format.unrealizedPercent = formatPercent(actual.unrealizedPercent, 2);
|
|
1003
|
+
actual.unrealizedPercent = numerator.divide(denominator);
|
|
1002
1004
|
}
|
|
1005
|
+
|
|
1006
|
+
format.unrealizedPercent = formatPercent(actual.unrealizedPercent, 2);
|
|
1003
1007
|
}
|
|
1004
1008
|
|
|
1005
1009
|
function calculateGainPercent(gain, basis) {
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -3500,28 +3500,32 @@ module.exports = (() => {
|
|
|
3500
3500
|
const openBasis = actual.basis;
|
|
3501
3501
|
const totalBasis = actual.totalDivisor;
|
|
3502
3502
|
|
|
3503
|
-
const
|
|
3503
|
+
const numerator = actual.realized;
|
|
3504
|
+
const denominator = totalBasis.subtract(openBasis);
|
|
3504
3505
|
|
|
3505
|
-
if (
|
|
3506
|
-
actual.realizedPercent =
|
|
3507
|
-
format.realizedPercent = '—';
|
|
3506
|
+
if (denominator.getIsZero()) {
|
|
3507
|
+
actual.realizedPercent = Decimal.ZERO;
|
|
3508
3508
|
} else {
|
|
3509
|
-
actual.realizedPercent =
|
|
3510
|
-
format.realizedPercent = formatPercent(actual.realizedPercent, 2);
|
|
3509
|
+
actual.realizedPercent = numerator.divide(denominator);
|
|
3511
3510
|
}
|
|
3511
|
+
|
|
3512
|
+
format.realizedPercent = formatPercent(actual.realizedPercent, 2);
|
|
3512
3513
|
}
|
|
3513
3514
|
|
|
3514
3515
|
function calculateUnrealizedPercent(group) {
|
|
3515
3516
|
const actual = group._dataActual;
|
|
3516
3517
|
const format = group._dataFormat;
|
|
3517
3518
|
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3519
|
+
const numerator = actual.unrealized;
|
|
3520
|
+
const denominator = actual.basis;
|
|
3521
|
+
|
|
3522
|
+
if (denominator.getIsZero()) {
|
|
3523
|
+
actual.unrealizedPercent = Decimal.ZERO;
|
|
3521
3524
|
} else {
|
|
3522
|
-
actual.unrealizedPercent =
|
|
3523
|
-
format.unrealizedPercent = formatPercent(actual.unrealizedPercent, 2);
|
|
3525
|
+
actual.unrealizedPercent = numerator.divide(denominator);
|
|
3524
3526
|
}
|
|
3527
|
+
|
|
3528
|
+
format.unrealizedPercent = formatPercent(actual.unrealizedPercent, 2);
|
|
3525
3529
|
}
|
|
3526
3530
|
|
|
3527
3531
|
function calculateGainPercent(gain, basis) {
|