@barchart/portfolio-api-common 1.2.15 → 1.2.16
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/PositionItem.js +43 -18
- package/package.json +1 -1
- package/test/SpecRunner.js +43 -18
|
@@ -406,32 +406,57 @@ module.exports = (() => {
|
|
|
406
406
|
|
|
407
407
|
const summary = item.currentSummary;
|
|
408
408
|
|
|
409
|
-
|
|
410
|
-
const period = summary.period;
|
|
409
|
+
let priceToUse;
|
|
411
410
|
|
|
412
|
-
|
|
413
|
-
|
|
411
|
+
if (price) {
|
|
412
|
+
priceToUse = price;
|
|
413
|
+
} else {
|
|
414
414
|
|
|
415
|
-
|
|
416
|
-
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (summary) {
|
|
418
|
+
let priceToUse;
|
|
419
|
+
|
|
420
|
+
if (price) {
|
|
421
|
+
priceToUse = price;
|
|
422
|
+
} else if (!summary.end.open.getIsZero()) {
|
|
423
|
+
priceToUse = summary.end.value.divide(summary.end.open);
|
|
417
424
|
} else {
|
|
418
|
-
|
|
425
|
+
priceToUse = null;
|
|
419
426
|
}
|
|
420
427
|
|
|
421
|
-
|
|
422
|
-
|
|
428
|
+
if (priceToUse !== null) {
|
|
429
|
+
const period = summary.period;
|
|
423
430
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
431
|
+
let unrealized = summary.end.open.multiply(priceToUse).add(summary.end.basis);
|
|
432
|
+
let unrealizedChange;
|
|
433
|
+
|
|
434
|
+
if (data.unrealizedToday !== null) {
|
|
435
|
+
unrealizedChange = unrealized.subtract(data.unrealized);
|
|
436
|
+
} else {
|
|
437
|
+
unrealizedChange = Decimal.ZERO;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
let summaryTotalCurrent = period.realized.add(period.income).add(unrealized);
|
|
441
|
+
let summaryTotalCurrentChange;
|
|
442
|
+
|
|
443
|
+
if (data.summaryTotalCurrent !== null) {
|
|
444
|
+
summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
|
|
445
|
+
} else {
|
|
446
|
+
summaryTotalCurrentChange = Decimal.ZERO;
|
|
447
|
+
}
|
|
429
448
|
|
|
430
|
-
|
|
431
|
-
|
|
449
|
+
data.summaryTotalCurrent = summaryTotalCurrent;
|
|
450
|
+
data.summaryTotalCurrentChange = summaryTotalCurrentChange;
|
|
432
451
|
|
|
433
|
-
|
|
434
|
-
|
|
452
|
+
data.unrealized = unrealized;
|
|
453
|
+
data.unrealizedChange = unrealizedChange;
|
|
454
|
+
} else {
|
|
455
|
+
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
456
|
+
|
|
457
|
+
data.unrealized = Decimal.ZERO;
|
|
458
|
+
data.unrealizedChange = Decimal.ZERO;
|
|
459
|
+
}
|
|
435
460
|
} else {
|
|
436
461
|
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
437
462
|
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -3424,32 +3424,57 @@ module.exports = (() => {
|
|
|
3424
3424
|
|
|
3425
3425
|
const summary = item.currentSummary;
|
|
3426
3426
|
|
|
3427
|
-
|
|
3428
|
-
const period = summary.period;
|
|
3427
|
+
let priceToUse;
|
|
3429
3428
|
|
|
3430
|
-
|
|
3431
|
-
|
|
3429
|
+
if (price) {
|
|
3430
|
+
priceToUse = price;
|
|
3431
|
+
} else {
|
|
3432
3432
|
|
|
3433
|
-
|
|
3434
|
-
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3435
|
+
if (summary) {
|
|
3436
|
+
let priceToUse;
|
|
3437
|
+
|
|
3438
|
+
if (price) {
|
|
3439
|
+
priceToUse = price;
|
|
3440
|
+
} else if (!summary.end.open.getIsZero()) {
|
|
3441
|
+
priceToUse = summary.end.value.divide(summary.end.open);
|
|
3435
3442
|
} else {
|
|
3436
|
-
|
|
3443
|
+
priceToUse = null;
|
|
3437
3444
|
}
|
|
3438
3445
|
|
|
3439
|
-
|
|
3440
|
-
|
|
3446
|
+
if (priceToUse !== null) {
|
|
3447
|
+
const period = summary.period;
|
|
3441
3448
|
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
} else {
|
|
3445
|
-
summaryTotalCurrentChange = Decimal.ZERO;
|
|
3446
|
-
}
|
|
3449
|
+
let unrealized = summary.end.open.multiply(priceToUse).add(summary.end.basis);
|
|
3450
|
+
let unrealizedChange;
|
|
3447
3451
|
|
|
3448
|
-
|
|
3449
|
-
|
|
3452
|
+
if (data.unrealizedToday !== null) {
|
|
3453
|
+
unrealizedChange = unrealized.subtract(data.unrealized);
|
|
3454
|
+
} else {
|
|
3455
|
+
unrealizedChange = Decimal.ZERO;
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
let summaryTotalCurrent = period.realized.add(period.income).add(unrealized);
|
|
3459
|
+
let summaryTotalCurrentChange;
|
|
3460
|
+
|
|
3461
|
+
if (data.summaryTotalCurrent !== null) {
|
|
3462
|
+
summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
|
|
3463
|
+
} else {
|
|
3464
|
+
summaryTotalCurrentChange = Decimal.ZERO;
|
|
3465
|
+
}
|
|
3450
3466
|
|
|
3451
|
-
|
|
3452
|
-
|
|
3467
|
+
data.summaryTotalCurrent = summaryTotalCurrent;
|
|
3468
|
+
data.summaryTotalCurrentChange = summaryTotalCurrentChange;
|
|
3469
|
+
|
|
3470
|
+
data.unrealized = unrealized;
|
|
3471
|
+
data.unrealizedChange = unrealizedChange;
|
|
3472
|
+
} else {
|
|
3473
|
+
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
3474
|
+
|
|
3475
|
+
data.unrealized = Decimal.ZERO;
|
|
3476
|
+
data.unrealizedChange = Decimal.ZERO;
|
|
3477
|
+
}
|
|
3453
3478
|
} else {
|
|
3454
3479
|
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
3455
3480
|
|