@barchart/portfolio-api-common 1.2.13 → 1.2.17
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.
|
@@ -197,8 +197,18 @@ module.exports = (() => {
|
|
|
197
197
|
});
|
|
198
198
|
|
|
199
199
|
formatters.set(TransactionType.VALUATION, (t) => {
|
|
200
|
+
let rate;
|
|
201
|
+
|
|
202
|
+
if (t.valuation.rate) {
|
|
203
|
+
rate = t.valuation.rate;
|
|
204
|
+
} else if (t.snapshot.open.getIsZero()) {
|
|
205
|
+
rate = null;
|
|
206
|
+
} else {
|
|
207
|
+
rate = t.valuation.value.divide(t.snapshot.open)
|
|
208
|
+
}
|
|
209
|
+
|
|
200
210
|
return {
|
|
201
|
-
price:
|
|
211
|
+
price: rate
|
|
202
212
|
};
|
|
203
213
|
});
|
|
204
214
|
|
|
@@ -406,32 +406,59 @@ 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 (data.previousPrice) {
|
|
423
|
+
priceToUse = new Decimal(data.previousPrice);
|
|
424
|
+
} else if (!summary.end.open.getIsZero()) {
|
|
425
|
+
priceToUse = summary.end.value.divide(summary.end.open);
|
|
417
426
|
} else {
|
|
418
|
-
|
|
427
|
+
priceToUse = null;
|
|
419
428
|
}
|
|
420
429
|
|
|
421
|
-
|
|
422
|
-
|
|
430
|
+
if (priceToUse !== null) {
|
|
431
|
+
const period = summary.period;
|
|
423
432
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
433
|
+
let unrealized = summary.end.open.multiply(priceToUse).add(summary.end.basis);
|
|
434
|
+
let unrealizedChange;
|
|
435
|
+
|
|
436
|
+
if (data.unrealizedToday !== null) {
|
|
437
|
+
unrealizedChange = unrealized.subtract(data.unrealized);
|
|
438
|
+
} else {
|
|
439
|
+
unrealizedChange = Decimal.ZERO;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
let summaryTotalCurrent = period.realized.add(period.income).add(unrealized);
|
|
443
|
+
let summaryTotalCurrentChange;
|
|
444
|
+
|
|
445
|
+
if (data.summaryTotalCurrent !== null) {
|
|
446
|
+
summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
|
|
447
|
+
} else {
|
|
448
|
+
summaryTotalCurrentChange = Decimal.ZERO;
|
|
449
|
+
}
|
|
429
450
|
|
|
430
|
-
|
|
431
|
-
|
|
451
|
+
data.summaryTotalCurrent = summaryTotalCurrent;
|
|
452
|
+
data.summaryTotalCurrentChange = summaryTotalCurrentChange;
|
|
432
453
|
|
|
433
|
-
|
|
434
|
-
|
|
454
|
+
data.unrealized = unrealized;
|
|
455
|
+
data.unrealizedChange = unrealizedChange;
|
|
456
|
+
} else {
|
|
457
|
+
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
458
|
+
|
|
459
|
+
data.unrealized = Decimal.ZERO;
|
|
460
|
+
data.unrealizedChange = Decimal.ZERO;
|
|
461
|
+
}
|
|
435
462
|
} else {
|
|
436
463
|
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
437
464
|
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -3424,32 +3424,59 @@ 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 (data.previousPrice) {
|
|
3441
|
+
priceToUse = new Decimal(data.previousPrice);
|
|
3442
|
+
} else if (!summary.end.open.getIsZero()) {
|
|
3443
|
+
priceToUse = summary.end.value.divide(summary.end.open);
|
|
3435
3444
|
} else {
|
|
3436
|
-
|
|
3445
|
+
priceToUse = null;
|
|
3437
3446
|
}
|
|
3438
3447
|
|
|
3439
|
-
|
|
3440
|
-
|
|
3448
|
+
if (priceToUse !== null) {
|
|
3449
|
+
const period = summary.period;
|
|
3441
3450
|
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
} else {
|
|
3445
|
-
summaryTotalCurrentChange = Decimal.ZERO;
|
|
3446
|
-
}
|
|
3451
|
+
let unrealized = summary.end.open.multiply(priceToUse).add(summary.end.basis);
|
|
3452
|
+
let unrealizedChange;
|
|
3447
3453
|
|
|
3448
|
-
|
|
3449
|
-
|
|
3454
|
+
if (data.unrealizedToday !== null) {
|
|
3455
|
+
unrealizedChange = unrealized.subtract(data.unrealized);
|
|
3456
|
+
} else {
|
|
3457
|
+
unrealizedChange = Decimal.ZERO;
|
|
3458
|
+
}
|
|
3459
|
+
|
|
3460
|
+
let summaryTotalCurrent = period.realized.add(period.income).add(unrealized);
|
|
3461
|
+
let summaryTotalCurrentChange;
|
|
3462
|
+
|
|
3463
|
+
if (data.summaryTotalCurrent !== null) {
|
|
3464
|
+
summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
|
|
3465
|
+
} else {
|
|
3466
|
+
summaryTotalCurrentChange = Decimal.ZERO;
|
|
3467
|
+
}
|
|
3450
3468
|
|
|
3451
|
-
|
|
3452
|
-
|
|
3469
|
+
data.summaryTotalCurrent = summaryTotalCurrent;
|
|
3470
|
+
data.summaryTotalCurrentChange = summaryTotalCurrentChange;
|
|
3471
|
+
|
|
3472
|
+
data.unrealized = unrealized;
|
|
3473
|
+
data.unrealizedChange = unrealizedChange;
|
|
3474
|
+
} else {
|
|
3475
|
+
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
3476
|
+
|
|
3477
|
+
data.unrealized = Decimal.ZERO;
|
|
3478
|
+
data.unrealizedChange = Decimal.ZERO;
|
|
3479
|
+
}
|
|
3453
3480
|
} else {
|
|
3454
3481
|
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
3455
3482
|
|