@barchart/portfolio-api-common 1.0.231 → 1.0.235

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.231",
3
+ "version": "1.0.235",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1,4 +1,4 @@
1
- (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
1
+ (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
2
2
  const uuid = require('uuid');
3
3
 
4
4
  const assert = require('@barchart/common-js/lang/assert'),
@@ -462,9 +462,10 @@ module.exports = (() => {
462
462
  * @param {Boolean} income
463
463
  * @param {Boolean} opening
464
464
  * @param {Boolean} closing
465
+ * @param {Boolean} fee
465
466
  */
466
467
  class TransactionType extends Enum {
467
- constructor(code, description, display, purchase, sale, income, opening, closing) {
468
+ constructor(code, description, display, purchase, sale, income, opening, closing, fee) {
468
469
  super(code, description);
469
470
 
470
471
  assert.argumentIsRequired(display, 'display', String);
@@ -473,6 +474,7 @@ module.exports = (() => {
473
474
  assert.argumentIsRequired(income, 'income', Boolean);
474
475
  assert.argumentIsRequired(opening, 'opening', Boolean);
475
476
  assert.argumentIsRequired(closing, 'closing', Boolean);
477
+ assert.argumentIsRequired(fee, 'fee', Boolean);
476
478
 
477
479
  this._display = display;
478
480
  this._purchase = purchase;
@@ -480,6 +482,7 @@ module.exports = (() => {
480
482
  this._income = income;
481
483
  this._opening = opening;
482
484
  this._closing = closing;
485
+ this._fee = fee
483
486
  }
484
487
 
485
488
  /**
@@ -503,7 +506,7 @@ module.exports = (() => {
503
506
  }
504
507
 
505
508
  /**
506
- * Indicates if the trade was a purchase.
509
+ * Indicates if the transaction was a purchase.
507
510
  *
508
511
  * @public
509
512
  * @returns {Boolean}
@@ -513,7 +516,7 @@ module.exports = (() => {
513
516
  }
514
517
 
515
518
  /**
516
- * Indicates if the trade was a sale.
519
+ * Indicates if the transaction was a sale.
517
520
  *
518
521
  * @public
519
522
  * @returns {Boolean}
@@ -533,7 +536,7 @@ module.exports = (() => {
533
536
  }
534
537
 
535
538
  /**
536
- * Indicates if the transactions opens the position (i.e. increases its
539
+ * Indicates if the transaction opens the position (i.e. increases its
537
540
  * magnitude).
538
541
  *
539
542
  * @public
@@ -544,7 +547,7 @@ module.exports = (() => {
544
547
  }
545
548
 
546
549
  /**
547
- * Indicates if the transactions closes the position (i.e. decreases its
550
+ * Indicates if the transaction closes the position (i.e. decreases its
548
551
  * magnitude).
549
552
  *
550
553
  * @public
@@ -554,6 +557,17 @@ module.exports = (() => {
554
557
  return this._closing;
555
558
  }
556
559
 
560
+ /**
561
+ * Indicates if the transaction is a chart that neither opens nor
562
+ * closes the position.
563
+ *
564
+ * @public
565
+ * @returns {Boolean}
566
+ */
567
+ get fee() {
568
+ return this._fee;
569
+ }
570
+
557
571
  /**
558
572
  * A purchase.
559
573
  *
@@ -757,27 +771,27 @@ module.exports = (() => {
757
771
  }
758
772
  }
759
773
 
760
- const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false);
761
- const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true);
762
- const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true);
763
- const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false);
764
- const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false);
765
- const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false);
766
- const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false);
767
- const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false);
768
- const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, true, false);
769
- const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, false);
774
+ const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false);
775
+ const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false);
776
+ const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false);
777
+ const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false);
778
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false);
779
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false);
780
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false);
781
+ const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false);
782
+ const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, false, false, true);
783
+ const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false);
770
784
 
771
- const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false);
772
- const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false);
785
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false);
786
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false);
773
787
 
774
- const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false);
775
- const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false);
776
- const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false);
777
- const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false);
788
+ const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false);
789
+ const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false);
790
+ const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false);
791
+ const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false);
778
792
 
779
- const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false);
780
- const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false);
793
+ const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false);
794
+ const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false);
781
795
 
782
796
  return TransactionType;
783
797
  })();
@@ -858,7 +872,7 @@ module.exports = (() => {
858
872
  }, { });
859
873
 
860
874
  this._previousSummaryFrame = PositionSummaryFrame.YEARLY;
861
- this._previousSummaryRanges = this._previousSummaryFrame.getRecentRanges(0);
875
+ this._previousSummaryRanges = this._previousSummaryFrame.getRecentRanges(1);
862
876
 
863
877
  this._summariesPrevious = summaries.reduce((map, summary) => {
864
878
  addSummaryPrevious(map, summary, this._previousSummaryFrame, this._previousSummaryRanges);
@@ -1807,6 +1821,7 @@ module.exports = (() => {
1807
1821
  this._dataActual.total = null;
1808
1822
  this._dataActual.summaryTotalCurrent = null;
1809
1823
  this._dataActual.summaryTotalPrevious = null;
1824
+ this._dataActual.summaryTotalPrevious2 = null;
1810
1825
  this._dataActual.cashTotal = null;
1811
1826
 
1812
1827
  this._dataFormat.currentPrice = null;
@@ -1828,6 +1843,8 @@ module.exports = (() => {
1828
1843
  this._dataActual.summaryTotalCurrentNegative = false;
1829
1844
  this._dataFormat.summaryTotalPrevious = null;
1830
1845
  this._dataFormat.summaryTotalPreviousNegative = false;
1846
+ this._dataFormat.summaryTotalPrevious2 = null;
1847
+ this._dataFormat.summaryTotalPrevious2Negative = false;
1831
1848
  this._dataFormat.cashTotal = null;
1832
1849
  this._dataFormat.portfolioType = null;
1833
1850
 
@@ -2275,6 +2292,7 @@ module.exports = (() => {
2275
2292
  updates.income = updates.income.add(translate(item, item.data.income));
2276
2293
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
2277
2294
  updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
2295
+ updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.summaryTotalPrevious2));
2278
2296
 
2279
2297
  if (item.position.instrument.type === InstrumentType.CASH) {
2280
2298
  updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
@@ -2288,6 +2306,7 @@ module.exports = (() => {
2288
2306
  income: Decimal.ZERO,
2289
2307
  summaryTotalCurrent: Decimal.ZERO,
2290
2308
  summaryTotalPrevious: Decimal.ZERO,
2309
+ summaryTotalPrevious2: Decimal.ZERO,
2291
2310
  cashTotal: Decimal.ZERO
2292
2311
  });
2293
2312
 
@@ -2297,6 +2316,7 @@ module.exports = (() => {
2297
2316
  actual.income = updates.income;
2298
2317
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
2299
2318
  actual.summaryTotalPrevious = updates.summaryTotalPrevious;
2319
+ actual.summaryTotalPrevious2 = updates.summaryTotalPrevious2;
2300
2320
  actual.cashTotal = updates.cashTotal;
2301
2321
 
2302
2322
  format.basis = formatCurrency(actual.basis, currency);
@@ -2306,6 +2326,8 @@ module.exports = (() => {
2306
2326
  format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
2307
2327
  format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
2308
2328
  format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
2329
+ format.summaryTotalPrevious2 = formatCurrency(updates.summaryTotalPrevious2, currency);
2330
+ format.summaryTotalPrevious2Negative = updates.summaryTotalPrevious2.getIsNegative();
2309
2331
  format.cashTotal = formatCurrency(updates.cashTotal, currency);
2310
2332
 
2311
2333
  calculateUnrealizedPercent(group);
@@ -2489,8 +2511,7 @@ module.exports = (() => {
2489
2511
  })();
2490
2512
 
2491
2513
  },{"./../data/InstrumentType":1,"./definitions/PositionLevelDefinition":7,"./definitions/PositionLevelType":8,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Disposable":18,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/formatter":23,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],6:[function(require,module,exports){
2492
- const array = require('@barchart/common-js/lang/array'),
2493
- assert = require('@barchart/common-js/lang/assert'),
2514
+ const assert = require('@barchart/common-js/lang/assert'),
2494
2515
  Currency = require('@barchart/common-js/lang/Currency'),
2495
2516
  Decimal = require('@barchart/common-js/lang/Decimal'),
2496
2517
  Disposable = require('@barchart/common-js/lang/Disposable'),
@@ -2550,6 +2571,7 @@ module.exports = (() => {
2550
2571
  this._data.summaryTotalCurrentChange = null;
2551
2572
 
2552
2573
  this._data.summaryTotalPrevious = null;
2574
+ this._data.summaryTotalPrevious2 = null;
2553
2575
 
2554
2576
  this._data.realized = null;
2555
2577
  this._data.income = null;
@@ -2809,7 +2831,8 @@ module.exports = (() => {
2809
2831
  data.income = snapshot.income;
2810
2832
 
2811
2833
  data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary);
2812
- data.summaryTotalPrevious = calculateSummaryTotal(array.last(previousSummaries));
2834
+ data.summaryTotalPrevious = calculateSummaryTotal(getPreviousSummary(previousSummaries, 1));
2835
+ data.summaryTotalPrevious2 = calculateSummaryTotal(getPreviousSummary(previousSummaries, 2));
2813
2836
 
2814
2837
  if (snapshot.open.getIsZero()) {
2815
2838
  data.basisPrice = Decimal.ZERO;
@@ -2930,10 +2953,24 @@ module.exports = (() => {
2930
2953
  return returnRef;
2931
2954
  }
2932
2955
 
2956
+ function getPreviousSummary(previousSummaries, count) {
2957
+ const index = previousSummaries.length - count;
2958
+
2959
+ let summary;
2960
+
2961
+ if (!(index < 0)) {
2962
+ summary = previousSummaries[index];
2963
+ } else {
2964
+ summary = null;
2965
+ }
2966
+
2967
+ return summary;
2968
+ }
2969
+
2933
2970
  return PositionItem;
2934
2971
  })();
2935
2972
 
2936
- },{"./../data/InstrumentType":1,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Disposable":18,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],7:[function(require,module,exports){
2973
+ },{"./../data/InstrumentType":1,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Disposable":18,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],7:[function(require,module,exports){
2937
2974
  const assert = require('@barchart/common-js/lang/assert'),
2938
2975
  Currency = require('@barchart/common-js/lang/Currency'),
2939
2976
  is = require('@barchart/common-js/lang/is');
@@ -3479,31 +3516,14 @@ module.exports = function () {
3479
3516
  }
3480
3517
 
3481
3518
  /**
3482
- * Gets the root node.
3519
+ * Returns the parent node. If this is the root node, a null value is returned.
3483
3520
  *
3484
3521
  * @public
3485
- * @returns {Tree}
3522
+ * @returns {Tree|null}
3486
3523
  */
3487
3524
 
3488
3525
 
3489
3526
  _createClass(Tree, [{
3490
- key: 'getRoot',
3491
- value: function getRoot() {
3492
- if (this.getIsRoot()) {
3493
- return this;
3494
- } else {
3495
- return this._parent.getRoot();
3496
- }
3497
- }
3498
-
3499
- /**
3500
- * Returns the parent node. If this is the root node, a null value is returned.
3501
- *
3502
- * @public
3503
- * @returns {Tree|null}
3504
- */
3505
-
3506
- }, {
3507
3527
  key: 'getParent',
3508
3528
  value: function getParent() {
3509
3529
  return this._parent;
@@ -3604,23 +3624,6 @@ module.exports = function () {
3604
3624
  }
3605
3625
  }
3606
3626
 
3607
- /**
3608
- * Removes the current node from the parent tree. Use on a root node
3609
- * has no effect.
3610
- *
3611
- * @public
3612
- */
3613
-
3614
- }, {
3615
- key: 'sever',
3616
- value: function sever() {
3617
- if (this.getIsRoot()) {
3618
- return;
3619
- }
3620
-
3621
- this.getParent().removeChild(this);
3622
- }
3623
-
3624
3627
  /**
3625
3628
  * Searches the children nodes for the first child node that matches the
3626
3629
  * predicate.
@@ -5015,20 +5018,6 @@ module.exports = function () {
5015
5018
  return this._big.gt(getBig(other));
5016
5019
  }
5017
5020
 
5018
- /**
5019
- * Returns true if the current instance is greater than or equal to the value.
5020
- *
5021
- * @public
5022
- * @param {Decimal|Number|String} other - The value to compare.
5023
- * @returns {Boolean}
5024
- */
5025
-
5026
- }, {
5027
- key: 'getIsGreaterThanOrEqual',
5028
- value: function getIsGreaterThanOrEqual(other) {
5029
- return this._big.gte(getBig(other));
5030
- }
5031
-
5032
5021
  /**
5033
5022
  * Returns true if the current instance is less than the value.
5034
5023
  *
@@ -5043,20 +5032,6 @@ module.exports = function () {
5043
5032
  return this._big.lt(getBig(other));
5044
5033
  }
5045
5034
 
5046
- /**
5047
- * Returns true if the current instance is less than or equal to the value.
5048
- *
5049
- * @public
5050
- * @param {Decimal|Number|String} other - The value to compare.
5051
- * @returns {Boolean}
5052
- */
5053
-
5054
- }, {
5055
- key: 'getIsLessThanOrEqual',
5056
- value: function getIsLessThanOrEqual(other) {
5057
- return this._big.lte(getBig(other));
5058
- }
5059
-
5060
5035
  /**
5061
5036
  * Returns true if the current instance is equal to the value.
5062
5037
  *
@@ -5256,9 +5231,9 @@ module.exports = function () {
5256
5231
  assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
5257
5232
  assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
5258
5233
 
5259
- if (a._big.gt(b._big)) {
5234
+ if (a._big.gt(b)) {
5260
5235
  return 1;
5261
- } else if (a._big.lt(b._big)) {
5236
+ } else if (a._big.lt(b)) {
5262
5237
  return -1;
5263
5238
  } else {
5264
5239
  return 0;
@@ -5719,10 +5694,12 @@ var _createClass = function () { function defineProperties(target, props) { for
5719
5694
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5720
5695
 
5721
5696
  var assert = require('./assert'),
5697
+ is = require('./is'),
5722
5698
  memoize = require('./memoize');
5723
5699
 
5724
5700
  var Currency = require('./Currency'),
5725
- Decimal = require('./Decimal');
5701
+ Decimal = require('./Decimal'),
5702
+ Enum = require('./Enum');
5726
5703
 
5727
5704
  module.exports = function () {
5728
5705
  'use strict';
@@ -5902,7 +5879,12 @@ module.exports = function () {
5902
5879
  assert.argumentIsRequired(amount, 'amount', Decimal, 'Decimal');
5903
5880
  assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
5904
5881
  assert.argumentIsRequired(desiredCurrency, 'desiredCurrency', Currency, 'Currency');
5905
- //assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
5882
+
5883
+ for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
5884
+ rates[_key - 3] = arguments[_key];
5885
+ }
5886
+
5887
+ assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
5906
5888
 
5907
5889
  var converted = void 0;
5908
5890
 
@@ -5912,10 +5894,6 @@ module.exports = function () {
5912
5894
  var numerator = desiredCurrency;
5913
5895
  var denominator = currency;
5914
5896
 
5915
- for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
5916
- rates[_key - 3] = arguments[_key];
5917
- }
5918
-
5919
5897
  var rate = rates.find(function (r) {
5920
5898
  return r.numerator === numerator && r.denominator === denominator || r.numerator === denominator && r.denominator === numerator;
5921
5899
  });
@@ -5966,7 +5944,7 @@ module.exports = function () {
5966
5944
  return Rate;
5967
5945
  }();
5968
5946
 
5969
- },{"./Currency":15,"./Decimal":17,"./assert":22,"./memoize":25}],21:[function(require,module,exports){
5947
+ },{"./Currency":15,"./Decimal":17,"./Enum":19,"./assert":22,"./is":24,"./memoize":25}],21:[function(require,module,exports){
5970
5948
  'use strict';
5971
5949
 
5972
5950
  var assert = require('./assert'),
@@ -6343,26 +6321,6 @@ module.exports = function () {
6343
6321
  });
6344
6322
 
6345
6323
  return returnRef;
6346
- },
6347
-
6348
-
6349
- /**
6350
- * Removes the first item from an array which matches a predicate.
6351
- *
6352
- * @static
6353
- * @public
6354
- * @param {Array} a
6355
- * @param {Function} predicate
6356
- */
6357
- remove: function remove(a, predicate) {
6358
- assert.argumentIsArray(a, 'a');
6359
- assert.argumentIsRequired(predicate, 'predicate', Function);
6360
-
6361
- var index = a.findIndex(predicate);
6362
-
6363
- if (!(index < 0)) {
6364
- a.splice(index, 1);
6365
- }
6366
6324
  }
6367
6325
  };
6368
6326
  }();