@barchart/portfolio-api-common 1.2.138 → 1.2.142
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.
|
@@ -303,7 +303,7 @@ module.exports = (() => {
|
|
|
303
303
|
const transactionCreateFailedTypeReserved = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_RESERVED', 'Unable to create {U|type.description} transaction, this type of transaction is managed by the system.');
|
|
304
304
|
const transactionCreateFailedReinvestPriceUnavailable = new FailureType('TRANSACTION_CREATE_FAILED_REINVEST_PRICE_UNAVAILABLE', 'Unable to create transaction, a dividend was paid on {L|day}; however no historical price is available for this day. To successfully create this transaction, please turn off dividend reinvestment for this position.');
|
|
305
305
|
const transactionCreateFailedPositionLocked = new FailureType('TRANSACTION_CREATE_FAILED_POSITION_LOCKED', 'Unable to create transaction, your {L|description} history is being recalculated. Please re-enter this transaction in a minute or two.');
|
|
306
|
-
const transactionCreateFailedInstrumentCorrupt = new
|
|
306
|
+
const transactionCreateFailedInstrumentCorrupt = new FailureType('TRANSACTION_CREATE_FAILED_INSTRUMENT_CORRUPT', 'Unable to create transaction, corporate action history for {U|symbol} cannot be located.');
|
|
307
307
|
|
|
308
308
|
const transactionDeleteFailedOutOfSequence = new FailureType('TRANSACTION_DELETE_FAILED_OUT_OF_SEQUENCE', 'Deleting any transaction, except for the most recent, will cause transaction history to be re-written. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
|
|
309
309
|
const transactionDeleteFailedNoTransaction = new FailureType('TRANSACTION_DELETE_FAILED_NO_TRANSACTION', 'Unable to delete transaction. The referenced transaction does not exist.');
|
|
@@ -755,6 +755,14 @@ module.exports = (() => {
|
|
|
755
755
|
|
|
756
756
|
calculateUnrealizedPercent(group);
|
|
757
757
|
|
|
758
|
+
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
759
|
+
actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
|
|
760
|
+
actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
|
|
761
|
+
|
|
762
|
+
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
763
|
+
format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
|
|
764
|
+
format.periodPercentPrevious2 = formatPercent(actual.periodPercentPrevious2, 2);
|
|
765
|
+
|
|
758
766
|
const groupItems = group._items;
|
|
759
767
|
|
|
760
768
|
if (group.single && groupItems.length === 1) {
|
|
@@ -762,28 +770,20 @@ module.exports = (() => {
|
|
|
762
770
|
|
|
763
771
|
actual.quantity = item.data.quantity;
|
|
764
772
|
actual.quantityPrevious = item.data.quantityPrevious;
|
|
765
|
-
|
|
766
|
-
actual.basisPrice = item.data.basisPrice;
|
|
767
|
-
|
|
768
|
-
actual.periodPrice = item.data.periodPrice;
|
|
769
|
-
actual.periodPricePrevious = item.data.periodPricePrevious;
|
|
770
773
|
|
|
771
774
|
format.quantity = formatDecimal(actual.quantity, 2);
|
|
772
775
|
format.quantityPrevious = formatDecimal(actual.quantityPrevious, 2);
|
|
773
776
|
|
|
777
|
+
actual.basisPrice = item.data.basisPrice;
|
|
778
|
+
|
|
774
779
|
format.basisPrice = formatCurrency(actual.basisPrice, currency);
|
|
775
780
|
|
|
781
|
+
actual.periodPrice = item.data.periodPrice;
|
|
782
|
+
actual.periodPricePrevious = item.data.periodPricePrevious;
|
|
783
|
+
|
|
776
784
|
format.periodPrice = formatCurrency(actual.periodPrice, currency);
|
|
777
785
|
format.periodPricePrevious = formatCurrency(actual.periodPricePrevious, currency);
|
|
778
786
|
|
|
779
|
-
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
780
|
-
actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
|
|
781
|
-
actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
|
|
782
|
-
|
|
783
|
-
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
784
|
-
format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
|
|
785
|
-
format.periodPercentPrevious2 = formatPercent(actual.periodPercentPrevious2, 2);
|
|
786
|
-
|
|
787
787
|
format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
|
|
788
788
|
format.locked = definition.type === PositionLevelType.POSITION && item.data.locked;
|
|
789
789
|
}
|
|
@@ -908,11 +908,11 @@ module.exports = (() => {
|
|
|
908
908
|
|
|
909
909
|
calculateUnrealizedPercent(group);
|
|
910
910
|
|
|
911
|
+
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
912
|
+
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
913
|
+
|
|
911
914
|
if (group.single && item) {
|
|
912
915
|
actual.periodUnrealized = item.data.periodUnrealized;
|
|
913
|
-
|
|
914
|
-
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
915
|
-
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
916
916
|
}
|
|
917
917
|
}
|
|
918
918
|
|
|
@@ -422,13 +422,13 @@ module.exports = (() => {
|
|
|
422
422
|
data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
|
|
423
423
|
data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
|
|
424
424
|
|
|
425
|
-
data.periodGain = calculatePeriodGain(data.initiate, currentSummary, previousSummary1);
|
|
426
|
-
data.periodGainPrevious = calculatePeriodGain(data.initiate, previousSummary1, previousSummary2);
|
|
427
|
-
data.periodGainPrevious2 = calculatePeriodGain(data.initiate, previousSummary2, previousSummary3);
|
|
425
|
+
data.periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary1);
|
|
426
|
+
data.periodGainPrevious = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
|
|
427
|
+
data.periodGainPrevious2 = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
|
|
428
428
|
|
|
429
|
-
data.periodDivisor = calculatePeriodDivisor(data.initiate, currentSummary, previousSummary1);
|
|
430
|
-
data.periodDivisorPrevious = calculatePeriodDivisor(data.initiate, previousSummary1, previousSummary2);
|
|
431
|
-
data.periodDivisorPrevious2 = calculatePeriodDivisor(data.initiate, previousSummary2, previousSummary3);
|
|
429
|
+
data.periodDivisor = calculatePeriodDivisor(position.instrument.type, data.initiate, currentSummary, previousSummary1);
|
|
430
|
+
data.periodDivisorPrevious = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
|
|
431
|
+
data.periodDivisorPrevious2 = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
|
|
432
432
|
|
|
433
433
|
if (snapshot.open.getIsZero()) {
|
|
434
434
|
data.basisPrice = Decimal.ZERO;
|
|
@@ -540,7 +540,7 @@ module.exports = (() => {
|
|
|
540
540
|
data.unrealized = unrealized;
|
|
541
541
|
data.unrealizedChange = unrealizedChange;
|
|
542
542
|
|
|
543
|
-
let periodGain = calculatePeriodGain(data.initiate, currentSummary, previousSummary, priceToUse);
|
|
543
|
+
let periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary, priceToUse);
|
|
544
544
|
let periodGainChange;
|
|
545
545
|
|
|
546
546
|
if (data.periodGain !== null) {
|
|
@@ -585,10 +585,10 @@ module.exports = (() => {
|
|
|
585
585
|
return direction || PositionDirection.LONG;
|
|
586
586
|
}
|
|
587
587
|
|
|
588
|
-
function calculatePeriodGain(direction, currentSummary, previousSummary, overridePrice) {
|
|
588
|
+
function calculatePeriodGain(type, direction, currentSummary, previousSummary, overridePrice) {
|
|
589
589
|
let returnRef;
|
|
590
590
|
|
|
591
|
-
if (currentSummary) {
|
|
591
|
+
if (currentSummary && type !== InstrumentType.CASH) {
|
|
592
592
|
let startValue;
|
|
593
593
|
|
|
594
594
|
if (previousSummary) {
|
|
@@ -617,10 +617,10 @@ module.exports = (() => {
|
|
|
617
617
|
return returnRef;
|
|
618
618
|
}
|
|
619
619
|
|
|
620
|
-
function calculatePeriodDivisor(direction, currentSummary, previousSummary) {
|
|
620
|
+
function calculatePeriodDivisor(type, direction, currentSummary, previousSummary) {
|
|
621
621
|
let returnRef;
|
|
622
622
|
|
|
623
|
-
if (currentSummary) {
|
|
623
|
+
if (currentSummary && type !== InstrumentType.CASH) {
|
|
624
624
|
let startValue;
|
|
625
625
|
|
|
626
626
|
if (previousSummary) {
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -3277,6 +3277,14 @@ module.exports = (() => {
|
|
|
3277
3277
|
|
|
3278
3278
|
calculateUnrealizedPercent(group);
|
|
3279
3279
|
|
|
3280
|
+
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
3281
|
+
actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
|
|
3282
|
+
actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
|
|
3283
|
+
|
|
3284
|
+
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
3285
|
+
format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
|
|
3286
|
+
format.periodPercentPrevious2 = formatPercent(actual.periodPercentPrevious2, 2);
|
|
3287
|
+
|
|
3280
3288
|
const groupItems = group._items;
|
|
3281
3289
|
|
|
3282
3290
|
if (group.single && groupItems.length === 1) {
|
|
@@ -3284,28 +3292,20 @@ module.exports = (() => {
|
|
|
3284
3292
|
|
|
3285
3293
|
actual.quantity = item.data.quantity;
|
|
3286
3294
|
actual.quantityPrevious = item.data.quantityPrevious;
|
|
3287
|
-
|
|
3288
|
-
actual.basisPrice = item.data.basisPrice;
|
|
3289
|
-
|
|
3290
|
-
actual.periodPrice = item.data.periodPrice;
|
|
3291
|
-
actual.periodPricePrevious = item.data.periodPricePrevious;
|
|
3292
3295
|
|
|
3293
3296
|
format.quantity = formatDecimal(actual.quantity, 2);
|
|
3294
3297
|
format.quantityPrevious = formatDecimal(actual.quantityPrevious, 2);
|
|
3295
3298
|
|
|
3299
|
+
actual.basisPrice = item.data.basisPrice;
|
|
3300
|
+
|
|
3296
3301
|
format.basisPrice = formatCurrency(actual.basisPrice, currency);
|
|
3297
3302
|
|
|
3303
|
+
actual.periodPrice = item.data.periodPrice;
|
|
3304
|
+
actual.periodPricePrevious = item.data.periodPricePrevious;
|
|
3305
|
+
|
|
3298
3306
|
format.periodPrice = formatCurrency(actual.periodPrice, currency);
|
|
3299
3307
|
format.periodPricePrevious = formatCurrency(actual.periodPricePrevious, currency);
|
|
3300
3308
|
|
|
3301
|
-
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
3302
|
-
actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
|
|
3303
|
-
actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
|
|
3304
|
-
|
|
3305
|
-
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
3306
|
-
format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
|
|
3307
|
-
format.periodPercentPrevious2 = formatPercent(actual.periodPercentPrevious2, 2);
|
|
3308
|
-
|
|
3309
3309
|
format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
|
|
3310
3310
|
format.locked = definition.type === PositionLevelType.POSITION && item.data.locked;
|
|
3311
3311
|
}
|
|
@@ -3430,11 +3430,11 @@ module.exports = (() => {
|
|
|
3430
3430
|
|
|
3431
3431
|
calculateUnrealizedPercent(group);
|
|
3432
3432
|
|
|
3433
|
+
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
3434
|
+
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
3435
|
+
|
|
3433
3436
|
if (group.single && item) {
|
|
3434
3437
|
actual.periodUnrealized = item.data.periodUnrealized;
|
|
3435
|
-
|
|
3436
|
-
actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
|
|
3437
|
-
format.periodPercent = formatPercent(actual.periodPercent, 2);
|
|
3438
3438
|
}
|
|
3439
3439
|
}
|
|
3440
3440
|
|
|
@@ -3928,13 +3928,13 @@ module.exports = (() => {
|
|
|
3928
3928
|
data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
|
|
3929
3929
|
data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
|
|
3930
3930
|
|
|
3931
|
-
data.periodGain = calculatePeriodGain(data.initiate, currentSummary, previousSummary1);
|
|
3932
|
-
data.periodGainPrevious = calculatePeriodGain(data.initiate, previousSummary1, previousSummary2);
|
|
3933
|
-
data.periodGainPrevious2 = calculatePeriodGain(data.initiate, previousSummary2, previousSummary3);
|
|
3931
|
+
data.periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary1);
|
|
3932
|
+
data.periodGainPrevious = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
|
|
3933
|
+
data.periodGainPrevious2 = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
|
|
3934
3934
|
|
|
3935
|
-
data.periodDivisor = calculatePeriodDivisor(data.initiate, currentSummary, previousSummary1);
|
|
3936
|
-
data.periodDivisorPrevious = calculatePeriodDivisor(data.initiate, previousSummary1, previousSummary2);
|
|
3937
|
-
data.periodDivisorPrevious2 = calculatePeriodDivisor(data.initiate, previousSummary2, previousSummary3);
|
|
3935
|
+
data.periodDivisor = calculatePeriodDivisor(position.instrument.type, data.initiate, currentSummary, previousSummary1);
|
|
3936
|
+
data.periodDivisorPrevious = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
|
|
3937
|
+
data.periodDivisorPrevious2 = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
|
|
3938
3938
|
|
|
3939
3939
|
if (snapshot.open.getIsZero()) {
|
|
3940
3940
|
data.basisPrice = Decimal.ZERO;
|
|
@@ -4046,7 +4046,7 @@ module.exports = (() => {
|
|
|
4046
4046
|
data.unrealized = unrealized;
|
|
4047
4047
|
data.unrealizedChange = unrealizedChange;
|
|
4048
4048
|
|
|
4049
|
-
let periodGain = calculatePeriodGain(data.initiate, currentSummary, previousSummary, priceToUse);
|
|
4049
|
+
let periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary, priceToUse);
|
|
4050
4050
|
let periodGainChange;
|
|
4051
4051
|
|
|
4052
4052
|
if (data.periodGain !== null) {
|
|
@@ -4091,10 +4091,10 @@ module.exports = (() => {
|
|
|
4091
4091
|
return direction || PositionDirection.LONG;
|
|
4092
4092
|
}
|
|
4093
4093
|
|
|
4094
|
-
function calculatePeriodGain(direction, currentSummary, previousSummary, overridePrice) {
|
|
4094
|
+
function calculatePeriodGain(type, direction, currentSummary, previousSummary, overridePrice) {
|
|
4095
4095
|
let returnRef;
|
|
4096
4096
|
|
|
4097
|
-
if (currentSummary) {
|
|
4097
|
+
if (currentSummary && type !== InstrumentType.CASH) {
|
|
4098
4098
|
let startValue;
|
|
4099
4099
|
|
|
4100
4100
|
if (previousSummary) {
|
|
@@ -4123,10 +4123,10 @@ module.exports = (() => {
|
|
|
4123
4123
|
return returnRef;
|
|
4124
4124
|
}
|
|
4125
4125
|
|
|
4126
|
-
function calculatePeriodDivisor(direction, currentSummary, previousSummary) {
|
|
4126
|
+
function calculatePeriodDivisor(type, direction, currentSummary, previousSummary) {
|
|
4127
4127
|
let returnRef;
|
|
4128
4128
|
|
|
4129
|
-
if (currentSummary) {
|
|
4129
|
+
if (currentSummary && type !== InstrumentType.CASH) {
|
|
4130
4130
|
let startValue;
|
|
4131
4131
|
|
|
4132
4132
|
if (previousSummary) {
|