@barchart/portfolio-api-common 1.2.115 → 1.2.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.
@@ -88,6 +88,18 @@ module.exports = (() => {
88
88
  static get TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE() {
89
89
  return transactionCreateFailedOutOfSequence;
90
90
  }
91
+
92
+ /**
93
+ * The transaction date is invalid.
94
+ * For example create opening transaction after delist date.
95
+ *
96
+ * @public
97
+ * @static
98
+ * @returns {FailureType}
99
+ */
100
+ static get TRANSACTION_CREATE_FAILED_INVALID_DATE() {
101
+ return transactionCreateFailedInvalidDate;
102
+ }
91
103
 
92
104
  /**
93
105
  * @public
@@ -164,6 +176,18 @@ module.exports = (() => {
164
176
  static get TRANSACTION_CREATE_FAILED_POSITION_LOCKED() {
165
177
  return transactionCreateFailedPositionLocked;
166
178
  }
179
+
180
+ /**
181
+ * The transaction (of this type) cannot be deleted by a user, instead,
182
+ * it is created and managed by the system (e.g. dividends).
183
+ *
184
+ * @public
185
+ * @static
186
+ * @returns {FailureType}
187
+ */
188
+ static get TRANSACTION_DELETE_FAILED_TYPE_RESERVED() {
189
+ return transactionDeleteFailedTypeReserved;
190
+ }
167
191
 
168
192
  /**
169
193
  * Deleting any transaction except for the most recent requires
@@ -209,6 +233,18 @@ module.exports = (() => {
209
233
  static get TRANSACTION_DELETE_FAILED_POSITION_LOCKED() {
210
234
  return transactionDeleteFailedPositionLocked;
211
235
  }
236
+
237
+ /**
238
+ * The transaction date is invalid.
239
+ * For example edit opening transaction after delist date.
240
+ *
241
+ * @public
242
+ * @static
243
+ * @returns {FailureType}
244
+ */
245
+ static get TRANSACTION_EDIT_FAILED_INVALID_DATE() {
246
+ return transactionEditFailedInvalidDate;
247
+ }
212
248
 
213
249
  /**
214
250
  * Unable to edit, the transaction doesn't exist.
@@ -247,10 +283,12 @@ module.exports = (() => {
247
283
 
248
284
  const transactionCreateFailedNoPosition = new FailureType('TRANSACTION_CREATE_FAILED_NO_POSITION', 'Unable to create transaction. The referenced position does not exist. Has it been deleted?');
249
285
  const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to process transaction, because the transaction date is out-of-sequence. In other words, it would occur before an existing transaction. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
286
+ const transactionCreateFailedInvalidDate = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_DATE', 'Unable to process transaction with given date.');
250
287
  const transactionCreateFailedTypeInvalidForInstrument = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_INSTRUMENT', 'Unable to process transaction, {L|transactionType.description} transactions cannot be used with {L|instrumentType.description} positions.');
251
288
  const transactionCreateFailedTypeInvalidForDirection = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_DIRECTION', 'Unable to process transaction, a {L|positionDirection.description} position would be created (i.e. you would have {L|positionDirection.sign} shares/units). {u|instrumentType.description} positions cannot have {L|positionDirection.description} positions.');
252
289
  const transactionCreateFailedInvalidDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_DIRECTION_SWITCH', 'Unable to process transaction, the transaction would switch the position from {L|currentDirection.description} to {L|proposedDirection.description} (i.e. {L|currentDirection.sign} to {L|proposedDirection.sign} shares/units). This is not allowed. Please close the current position (i.e. zero it out) and then enter a second transaction.');
253
290
  const transactionCreateFailedInvalidInitialType = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_INITIAL_TYPE', 'Unable to process operation because the first transaction would to be a {U|transactionType.description}, which is not allowed -- since {U|transactionType.description} transactions cannot open a position.');
291
+
254
292
  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.');
255
293
  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.');
256
294
  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.');
@@ -259,9 +297,11 @@ module.exports = (() => {
259
297
  const transactionDeleteFailedNoTransaction = new FailureType('TRANSACTION_DELETE_FAILED_NO_TRANSACTION', 'Unable to delete transaction. The referenced transaction does not exist.');
260
298
  const transactionDeleteFailedDirectionSwitchOnRewrite = new FailureType('TRANSACTION_DELETE_FAILED_DIRECTION_SWITCH_ON_REWRITE', 'Deleting this transaction would cause your history to be re-written and the position to switch from long to short (i.e. positive to negative) or vice versa.');
261
299
  const transactionDeleteFailedPositionLocked = new FailureType('TRANSACTION_DELETE_FAILED_POSITION_LOCKED', 'Unable to delete transaction, your {L|description} history is being recalculated. Please wait a minute or two and retry.');
300
+ const transactionDeleteFailedTypeReserved = new FailureType('TRANSACTION_DELETE_FAILED_TYPE_RESERVED', 'Unable to delete {U|type.description} transaction, this type of transaction is managed by the system.');
262
301
 
302
+ const transactionEditFailedInvalidDate = new FailureType('TRANSACTION_EDIT_FAILED_INVALID_DATE', 'Unable to edit transaction with given date.');
263
303
  const transactionEditFailedNoTransaction = new FailureType('TRANSACTION_EDIT_FAILED_NO_TRANSACTION', 'Unable to edit transaction. The referenced transaction does not exist.');
264
304
  const transactionEditFailedTypeReserved = new FailureType('TRANSACTION_EDIT_FAILED_TYPE_RESERVED', 'Unable to edit {U|type.description} transaction, this type of transaction is managed by the system.');
265
305
 
266
306
  return PortfolioFailureType;
267
- })();
307
+ })();
@@ -22,7 +22,6 @@ module.exports = (() => {
22
22
  * @param {Boolean} corporateAction
23
23
  * @param {Boolean} initial
24
24
  * @param {Boolean} significant
25
- * @param {Boolean} eod
26
25
  */
27
26
  class TransactionType extends Enum {
28
27
  constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
@@ -352,7 +351,7 @@ module.exports = (() => {
352
351
  static get DEBIT() {
353
352
  return debit;
354
353
  }
355
-
354
+
356
355
  /**
357
356
  * A system-generated transaction, indicating the security has stopped active trading.
358
357
  *
@@ -412,7 +411,7 @@ module.exports = (() => {
412
411
  const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
413
412
  const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false);
414
413
  const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false);
415
- const delist = new TransactionType('DL', 'Delist', 'Delist', 0, false, false, false, false, false, false, false, false, false);
414
+ const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, false);
416
415
 
417
416
  const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false);
418
417
  const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false);
@@ -1,6 +1,7 @@
1
1
  const assert = require('@barchart/common-js/lang/assert'),
2
2
  array = require('@barchart/common-js/lang/array'),
3
- is = require('@barchart/common-js/lang/is');
3
+ is = require('@barchart/common-js/lang/is'),
4
+ Day = require('@barchart/common-js/lang/Day');
4
5
 
5
6
  const InstrumentType = require('./InstrumentType'),
6
7
  PositionDirection = require('./PositionDirection'),
@@ -786,9 +786,9 @@ module.exports = (() => {
786
786
  actual.periodUnrealizedBasisPrevious = item.data.periodUnrealizedBasisPrevious;
787
787
  actual.periodUnrealizedBasisPrevious2 = item.data.periodUnrealizedBasisPrevious2;
788
788
 
789
- actual.periodPercent = calculatePeriodPercent(actual.periodRealized, actual.periodRealizedBasis, actual.periodUnrealized, actual.periodUnrealizedBasis);
790
- actual.periodPercentPrevious = calculatePeriodPercent(actual.periodRealizedPrevious, actual.periodRealizedBasisPrevious, actual.periodUnrealizedPrevious, actual.periodUnrealizedBasisPrevious);
791
- actual.periodPercentPrevious2 = calculatePeriodPercent(actual.periodRealizedPrevious2, actual.periodRealizedBasisPrevious2, actual.periodUnrealizedPrevious2, actual.periodUnrealizedBasisPrevious2);
789
+ actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodRealizedBasis, actual.periodUnrealizedBasis);
790
+ actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodRealizedBasisPrevious, actual.periodUnrealizedBasisPrevious);
791
+ actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodRealizedBasisPrevious2, actual.periodUnrealizedBasisPrevious2);
792
792
 
793
793
  format.periodPercent = formatPercent(actual.periodPercent, 2);
794
794
  format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
@@ -921,7 +921,7 @@ module.exports = (() => {
921
921
  if (group.single && item) {
922
922
  actual.periodUnrealized = item.data.periodUnrealized;
923
923
 
924
- actual.periodPercent = calculatePeriodPercent(actual.periodRealized, actual.periodRealizedBasis, actual.periodUnrealized, actual.periodUnrealizedBasis);
924
+ actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodRealizedBasis, actual.periodUnrealizedBasis);
925
925
  format.periodPercent = formatPercent(actual.periodPercent, 2);
926
926
  }
927
927
  }
@@ -982,8 +982,8 @@ module.exports = (() => {
982
982
  }
983
983
  }
984
984
 
985
- function calculatePeriodPercent(realized, realizedBasis, unrealized, unrealizedBasis) {
986
- const numerator = realized.add(unrealized);
985
+ function calculatePeriodPercent(periodSummaryTotal, realizedBasis, unrealizedBasis) {
986
+ const numerator = periodSummaryTotal;
987
987
  const denominator = realizedBasis.add(unrealizedBasis);
988
988
 
989
989
  return denominator.getIsZero() ? Decimal.ZERO : numerator.divide(denominator);
@@ -648,8 +648,6 @@ module.exports = (() => {
648
648
  let returnRef;
649
649
 
650
650
  if (currentSummary) {
651
- const period = currentSummary.period;
652
-
653
651
  returnRef = currentSummary.end.basis.absolute();
654
652
  } else {
655
653
  returnRef = Decimal.ZERO;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.115",
3
+ "version": "1.2.119",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -759,7 +759,6 @@ module.exports = (() => {
759
759
  * @param {Boolean} corporateAction
760
760
  * @param {Boolean} initial
761
761
  * @param {Boolean} significant
762
- * @param {Boolean} eod
763
762
  */
764
763
  class TransactionType extends Enum {
765
764
  constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
@@ -1089,7 +1088,7 @@ module.exports = (() => {
1089
1088
  static get DEBIT() {
1090
1089
  return debit;
1091
1090
  }
1092
-
1091
+
1093
1092
  /**
1094
1093
  * A system-generated transaction, indicating the security has stopped active trading.
1095
1094
  *
@@ -1149,7 +1148,7 @@ module.exports = (() => {
1149
1148
  const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
1150
1149
  const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false);
1151
1150
  const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false);
1152
- const delist = new TransactionType('DL', 'Delist', 'Delist', 0, false, false, false, false, false, false, false, false, false);
1151
+ const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, false);
1153
1152
 
1154
1153
  const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false);
1155
1154
  const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false);
@@ -1169,7 +1168,8 @@ module.exports = (() => {
1169
1168
  },{"@barchart/common-js/lang/Enum":24,"@barchart/common-js/lang/assert":29}],5:[function(require,module,exports){
1170
1169
  const assert = require('@barchart/common-js/lang/assert'),
1171
1170
  array = require('@barchart/common-js/lang/array'),
1172
- is = require('@barchart/common-js/lang/is');
1171
+ is = require('@barchart/common-js/lang/is'),
1172
+ Day = require('@barchart/common-js/lang/Day');
1173
1173
 
1174
1174
  const InstrumentType = require('./InstrumentType'),
1175
1175
  PositionDirection = require('./PositionDirection'),
@@ -1464,7 +1464,7 @@ module.exports = (() => {
1464
1464
  return TransactionValidator;
1465
1465
  })();
1466
1466
 
1467
- },{"./InstrumentType":1,"./PositionDirection":2,"./TransactionType":4,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29,"@barchart/common-js/lang/is":33}],6:[function(require,module,exports){
1467
+ },{"./InstrumentType":1,"./PositionDirection":2,"./TransactionType":4,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29,"@barchart/common-js/lang/is":33}],6:[function(require,module,exports){
1468
1468
  const array = require('@barchart/common-js/lang/array'),
1469
1469
  assert = require('@barchart/common-js/lang/assert'),
1470
1470
  ComparatorBuilder = require('@barchart/common-js/collections/sorting/ComparatorBuilder'),
@@ -3289,9 +3289,9 @@ module.exports = (() => {
3289
3289
  actual.periodUnrealizedBasisPrevious = item.data.periodUnrealizedBasisPrevious;
3290
3290
  actual.periodUnrealizedBasisPrevious2 = item.data.periodUnrealizedBasisPrevious2;
3291
3291
 
3292
- actual.periodPercent = calculatePeriodPercent(actual.periodRealized, actual.periodRealizedBasis, actual.periodUnrealized, actual.periodUnrealizedBasis);
3293
- actual.periodPercentPrevious = calculatePeriodPercent(actual.periodRealizedPrevious, actual.periodRealizedBasisPrevious, actual.periodUnrealizedPrevious, actual.periodUnrealizedBasisPrevious);
3294
- actual.periodPercentPrevious2 = calculatePeriodPercent(actual.periodRealizedPrevious2, actual.periodRealizedBasisPrevious2, actual.periodUnrealizedPrevious2, actual.periodUnrealizedBasisPrevious2);
3292
+ actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodRealizedBasis, actual.periodUnrealizedBasis);
3293
+ actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodRealizedBasisPrevious, actual.periodUnrealizedBasisPrevious);
3294
+ actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodRealizedBasisPrevious2, actual.periodUnrealizedBasisPrevious2);
3295
3295
 
3296
3296
  format.periodPercent = formatPercent(actual.periodPercent, 2);
3297
3297
  format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
@@ -3424,7 +3424,7 @@ module.exports = (() => {
3424
3424
  if (group.single && item) {
3425
3425
  actual.periodUnrealized = item.data.periodUnrealized;
3426
3426
 
3427
- actual.periodPercent = calculatePeriodPercent(actual.periodRealized, actual.periodRealizedBasis, actual.periodUnrealized, actual.periodUnrealizedBasis);
3427
+ actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodRealizedBasis, actual.periodUnrealizedBasis);
3428
3428
  format.periodPercent = formatPercent(actual.periodPercent, 2);
3429
3429
  }
3430
3430
  }
@@ -3485,8 +3485,8 @@ module.exports = (() => {
3485
3485
  }
3486
3486
  }
3487
3487
 
3488
- function calculatePeriodPercent(realized, realizedBasis, unrealized, unrealizedBasis) {
3489
- const numerator = realized.add(unrealized);
3488
+ function calculatePeriodPercent(periodSummaryTotal, realizedBasis, unrealizedBasis) {
3489
+ const numerator = periodSummaryTotal;
3490
3490
  const denominator = realizedBasis.add(unrealizedBasis);
3491
3491
 
3492
3492
  return denominator.getIsZero() ? Decimal.ZERO : numerator.divide(denominator);
@@ -4148,8 +4148,6 @@ module.exports = (() => {
4148
4148
  let returnRef;
4149
4149
 
4150
4150
  if (currentSummary) {
4151
- const period = currentSummary.period;
4152
-
4153
4151
  returnRef = currentSummary.end.basis.absolute();
4154
4152
  } else {
4155
4153
  returnRef = Decimal.ZERO;
@@ -18152,7 +18150,7 @@ describe('When validating transaction order', () => {
18152
18150
  'use strict';
18153
18151
 
18154
18152
  const build = (sequence, day, type) => {
18155
- return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY ) };
18153
+ return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY) };
18156
18154
  };
18157
18155
 
18158
18156
  it('An array of zero transactions should be valid', () => {
@@ -7,7 +7,7 @@ describe('When validating transaction order', () => {
7
7
  'use strict';
8
8
 
9
9
  const build = (sequence, day, type) => {
10
- return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY ) };
10
+ return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY) };
11
11
  };
12
12
 
13
13
  it('An array of zero transactions should be valid', () => {