@barchart/portfolio-api-common 1.0.115 → 1.0.119
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.
|
@@ -74,6 +74,7 @@ module.exports = (() => {
|
|
|
74
74
|
this._dataFormat.marketPercent = null;
|
|
75
75
|
this._dataFormat.marketDirection = null;
|
|
76
76
|
this._dataFormat.unrealized = null;
|
|
77
|
+
this._dataFormat.unrealizedPercent = null;
|
|
77
78
|
this._dataFormat.unrealizedNegative = false;
|
|
78
79
|
this._dataFormat.unrealizedToday = null;
|
|
79
80
|
this._dataFormat.unrealizedTodayNegative = false;
|
|
@@ -261,11 +262,13 @@ module.exports = (() => {
|
|
|
261
262
|
format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
|
|
262
263
|
format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
|
|
263
264
|
|
|
265
|
+
calculateUnrealizedPercent(group);
|
|
266
|
+
|
|
264
267
|
if (group.single) {
|
|
265
268
|
const item = group._items[0];
|
|
266
269
|
|
|
267
270
|
format.quantity = formatDecimal(item.position.snapshot.open, 2);
|
|
268
|
-
format.basisPrice = formatCurrency(item.basisPrice, currency);
|
|
271
|
+
format.basisPrice = formatCurrency(item.data.basisPrice, currency);
|
|
269
272
|
}
|
|
270
273
|
}
|
|
271
274
|
|
|
@@ -351,6 +354,7 @@ module.exports = (() => {
|
|
|
351
354
|
format.totalNegative = actual.total.getIsNegative();
|
|
352
355
|
|
|
353
356
|
calculateMarketPercent(group, false);
|
|
357
|
+
calculateUnrealizedPercent(group);
|
|
354
358
|
}
|
|
355
359
|
|
|
356
360
|
function calculateMarketPercent(group, silent) {
|
|
@@ -386,6 +390,19 @@ module.exports = (() => {
|
|
|
386
390
|
}
|
|
387
391
|
}
|
|
388
392
|
|
|
393
|
+
function calculateUnrealizedPercent(group) {
|
|
394
|
+
const actual = group._dataActual;
|
|
395
|
+
const format = group._dataFormat;
|
|
396
|
+
|
|
397
|
+
if (actual.basis.getIsZero()) {
|
|
398
|
+
actual.unrealizedPercent = null;
|
|
399
|
+
format.unrealizedPercent = '—';
|
|
400
|
+
} else {
|
|
401
|
+
actual.unrealizedPercent = actual.unrealized.divide(actual.basis);
|
|
402
|
+
format.unrealizedPercent = formatPercent(actual.unrealizedPercent, 2);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
389
406
|
const unchanged = { up: false, down: false };
|
|
390
407
|
|
|
391
408
|
return PositionGroup;
|
|
@@ -149,7 +149,11 @@ module.exports = (() => {
|
|
|
149
149
|
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary);
|
|
150
150
|
data.summaryTotalPrevious = calculateSummaryTotal(array.last(previousSummaries));
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
if (snapshot.open.getIsZero()) {
|
|
153
|
+
data.basisPrice = Decimal.ZERO;
|
|
154
|
+
} else {
|
|
155
|
+
data.basisPrice = basis.divide(snapshot.open);
|
|
156
|
+
}
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
function calculatePriceData(item, price) {
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -1079,6 +1079,7 @@ module.exports = (() => {
|
|
|
1079
1079
|
this._dataFormat.marketPercent = null;
|
|
1080
1080
|
this._dataFormat.marketDirection = null;
|
|
1081
1081
|
this._dataFormat.unrealized = null;
|
|
1082
|
+
this._dataFormat.unrealizedPercent = null;
|
|
1082
1083
|
this._dataFormat.unrealizedNegative = false;
|
|
1083
1084
|
this._dataFormat.unrealizedToday = null;
|
|
1084
1085
|
this._dataFormat.unrealizedTodayNegative = false;
|
|
@@ -1266,11 +1267,13 @@ module.exports = (() => {
|
|
|
1266
1267
|
format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
|
|
1267
1268
|
format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
|
|
1268
1269
|
|
|
1270
|
+
calculateUnrealizedPercent(group);
|
|
1271
|
+
|
|
1269
1272
|
if (group.single) {
|
|
1270
1273
|
const item = group._items[0];
|
|
1271
1274
|
|
|
1272
1275
|
format.quantity = formatDecimal(item.position.snapshot.open, 2);
|
|
1273
|
-
format.basisPrice = formatCurrency(item.basisPrice, currency);
|
|
1276
|
+
format.basisPrice = formatCurrency(item.data.basisPrice, currency);
|
|
1274
1277
|
}
|
|
1275
1278
|
}
|
|
1276
1279
|
|
|
@@ -1356,6 +1359,7 @@ module.exports = (() => {
|
|
|
1356
1359
|
format.totalNegative = actual.total.getIsNegative();
|
|
1357
1360
|
|
|
1358
1361
|
calculateMarketPercent(group, false);
|
|
1362
|
+
calculateUnrealizedPercent(group);
|
|
1359
1363
|
}
|
|
1360
1364
|
|
|
1361
1365
|
function calculateMarketPercent(group, silent) {
|
|
@@ -1391,6 +1395,19 @@ module.exports = (() => {
|
|
|
1391
1395
|
}
|
|
1392
1396
|
}
|
|
1393
1397
|
|
|
1398
|
+
function calculateUnrealizedPercent(group) {
|
|
1399
|
+
const actual = group._dataActual;
|
|
1400
|
+
const format = group._dataFormat;
|
|
1401
|
+
|
|
1402
|
+
if (actual.basis.getIsZero()) {
|
|
1403
|
+
actual.unrealizedPercent = null;
|
|
1404
|
+
format.unrealizedPercent = '—';
|
|
1405
|
+
} else {
|
|
1406
|
+
actual.unrealizedPercent = actual.unrealized.divide(actual.basis);
|
|
1407
|
+
format.unrealizedPercent = formatPercent(actual.unrealizedPercent, 2);
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1394
1411
|
const unchanged = { up: false, down: false };
|
|
1395
1412
|
|
|
1396
1413
|
return PositionGroup;
|
|
@@ -1548,7 +1565,11 @@ module.exports = (() => {
|
|
|
1548
1565
|
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary);
|
|
1549
1566
|
data.summaryTotalPrevious = calculateSummaryTotal(array.last(previousSummaries));
|
|
1550
1567
|
|
|
1551
|
-
|
|
1568
|
+
if (snapshot.open.getIsZero()) {
|
|
1569
|
+
data.basisPrice = Decimal.ZERO;
|
|
1570
|
+
} else {
|
|
1571
|
+
data.basisPrice = basis.divide(snapshot.open);
|
|
1572
|
+
}
|
|
1552
1573
|
}
|
|
1553
1574
|
|
|
1554
1575
|
function calculatePriceData(item, price) {
|