@barchart/portfolio-api-common 1.2.142 → 1.2.146

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.
@@ -137,6 +137,7 @@ module.exports = (() => {
137
137
  this._dataActual.marketChange = null;
138
138
  this._dataActual.marketChangePercent = null;
139
139
  this._dataActual.cashTotal = null;
140
+ this._dataActual.totalDivisor = null;
140
141
  this._dataActual.periodDivisorCurrent = null;
141
142
  this._dataActual.periodDivisorPrevious = null;
142
143
  this._dataActual.periodDivisorPrevious2 = null;
@@ -144,6 +145,7 @@ module.exports = (() => {
144
145
  this._dataFormat.currentPrice = null;
145
146
  this._dataFormat.basis = null;
146
147
  this._dataFormat.realized = null;
148
+ this._dataFormat.realizedPercent = null;
147
149
  this._dataFormat.income = null;
148
150
  this._dataFormat.market = null;
149
151
  this._dataFormat.marketPercent = null;
@@ -183,10 +185,12 @@ module.exports = (() => {
183
185
  this._dataFormat.periodRealized = null;
184
186
  this._dataFormat.periodUnrealized = null;
185
187
 
188
+ this._dataActual.totalPercent = null;
186
189
  this._dataActual.periodPercent = null;
187
190
  this._dataActual.periodPercentPrevious = null;
188
191
  this._dataActual.periodPercentPrevious2 = null;
189
192
 
193
+ this._dataFormat.totalPercent = null;
190
194
  this._dataFormat.periodPercent = null;
191
195
  this._dataFormat.periodPercentPrevious = null;
192
196
  this._dataFormat.periodPercentPrevious2 = null;
@@ -695,6 +699,7 @@ module.exports = (() => {
695
699
  updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
696
700
  }
697
701
 
702
+ updates.totalDivisor = updates.periodDivisorCurrent.add(translate(item, item.data.totalDivisor));
698
703
  updates.periodDivisorCurrent = updates.periodDivisorCurrent.add(translate(item, item.data.periodDivisor));
699
704
  updates.periodDivisorPrevious = updates.periodDivisorPrevious.add(translate(item, item.data.periodDivisorPrevious));
700
705
  updates.periodDivisorPrevious2 = updates.periodDivisorPrevious2.add(translate(item, item.data.periodDivisorPrevious2));
@@ -714,6 +719,7 @@ module.exports = (() => {
714
719
  periodUnrealized: Decimal.ZERO,
715
720
  periodIncome: Decimal.ZERO,
716
721
  cashTotal: Decimal.ZERO,
722
+ totalDivisor: Decimal.ZERO,
717
723
  periodDivisorCurrent: Decimal.ZERO,
718
724
  periodDivisorPrevious: Decimal.ZERO,
719
725
  periodDivisorPrevious2: Decimal.ZERO
@@ -732,6 +738,7 @@ module.exports = (() => {
732
738
  actual.periodUnrealized = updates.periodUnrealized;
733
739
  actual.periodIncome = updates.periodIncome;
734
740
  actual.cashTotal = updates.cashTotal;
741
+ actual.totalDivisor = updates.totalDivisor;
735
742
  actual.periodDivisorCurrent = updates.periodDivisorCurrent;
736
743
  actual.periodDivisorPrevious = updates.periodDivisorPrevious;
737
744
  actual.periodDivisorPrevious2 = updates.periodDivisorPrevious2;
@@ -753,11 +760,12 @@ module.exports = (() => {
753
760
  format.periodIncome = formatCurrency(updates.periodIncome, currency);
754
761
  format.cashTotal = formatCurrency(updates.cashTotal, currency);
755
762
 
763
+ calculateRealizedPercent(group);
756
764
  calculateUnrealizedPercent(group);
757
765
 
758
- actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
759
- actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
760
- actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
766
+ actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
767
+ actual.periodPercentPrevious = calculateGainPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
768
+ actual.periodPercentPrevious2 = calculateGainPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
761
769
 
762
770
  format.periodPercent = formatPercent(actual.periodPercent, 2);
763
771
  format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
@@ -864,7 +872,9 @@ module.exports = (() => {
864
872
  actual.unrealized = updates.unrealized;
865
873
  actual.unrealizedToday = updates.unrealizedToday;
866
874
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
875
+
867
876
  actual.total = updates.unrealized.add(actual.realized).add(actual.income);
877
+ actual.totalPercent = calculateGainPercent(actual.total, actual.totalDivisor);
868
878
 
869
879
  let marketChange = updates.market.subtract(actual.marketPrevious);
870
880
  let marketChangePercent;
@@ -902,13 +912,15 @@ module.exports = (() => {
902
912
 
903
913
  format.total = formatCurrency(actual.total, currency);
904
914
  format.totalNegative = actual.total.getIsNegative();
915
+ format.totalPercent = formatPercent(actual.totalPercent, 2);
905
916
 
906
917
  format.marketChange = formatCurrency(actual.marketChange, currency);
907
918
  format.marketChangePercent = formatPercent(actual.marketChangePercent, 2);
908
919
 
920
+ calculateRealizedPercent(group);
909
921
  calculateUnrealizedPercent(group);
910
922
 
911
- actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
923
+ actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
912
924
  format.periodPercent = formatPercent(actual.periodPercent, 2);
913
925
 
914
926
  if (group.single && item) {
@@ -959,21 +971,43 @@ module.exports = (() => {
959
971
  }
960
972
  }
961
973
 
974
+ function calculateRealizedPercent(group) {
975
+ const actual = group._dataActual;
976
+ const format = group._dataFormat;
977
+
978
+ const openBasis = actual.basis;
979
+ const totalBasis = actual.totalDivisor;
980
+
981
+ const numerator = actual.realized;
982
+ const denominator = totalBasis.subtract(openBasis);
983
+
984
+ if (denominator.getIsZero()) {
985
+ actual.realizedPercent = Decimal.ZERO;
986
+ } else {
987
+ actual.realizedPercent = numerator.divide(denominator);
988
+ }
989
+
990
+ format.realizedPercent = formatPercent(actual.realizedPercent, 2);
991
+ }
992
+
962
993
  function calculateUnrealizedPercent(group) {
963
994
  const actual = group._dataActual;
964
995
  const format = group._dataFormat;
965
996
 
966
- if (actual.basis.getIsZero()) {
967
- actual.unrealizedPercent = null;
968
- format.unrealizedPercent = '—';
997
+ const numerator = actual.unrealized;
998
+ const denominator = actual.basis;
999
+
1000
+ if (denominator.getIsZero()) {
1001
+ actual.unrealizedPercent = Decimal.ZERO;
969
1002
  } else {
970
- actual.unrealizedPercent = actual.unrealized.divide(actual.basis);
971
- format.unrealizedPercent = formatPercent(actual.unrealizedPercent, 2);
1003
+ actual.unrealizedPercent = numerator.divide(denominator);
972
1004
  }
1005
+
1006
+ format.unrealizedPercent = formatPercent(actual.unrealizedPercent, 2);
973
1007
  }
974
1008
 
975
- function calculatePeriodPercent(periodSummaryTotal, periodDivisor) {
976
- return periodDivisor.getIsZero() ? Decimal.ZERO : periodSummaryTotal.divide(periodDivisor);
1009
+ function calculateGainPercent(gain, basis) {
1010
+ return basis.getIsZero() ? Decimal.ZERO : gain.divide(basis);
977
1011
  }
978
1012
 
979
1013
  const unchanged = { up: false, down: false };
@@ -94,6 +94,8 @@ module.exports = (() => {
94
94
 
95
95
  this._data.initiate = null;
96
96
 
97
+ this._data.totalDivisor = null;
98
+
97
99
  this._data.newsExists = false;
98
100
  this._data.fundamental = { };
99
101
  this._data.locked = getIsLocked(position);
@@ -447,6 +449,8 @@ module.exports = (() => {
447
449
  } else {
448
450
  data.periodPricePrevious = null;
449
451
  }
452
+
453
+ data.totalDivisor = calculateTotalDivisor(position.instrument.type, data.initiate, currentSummary, position);
450
454
  }
451
455
 
452
456
  function calculatePriceData(item, price) {
@@ -641,6 +645,26 @@ module.exports = (() => {
641
645
  return returnRef;
642
646
  }
643
647
 
648
+ function calculateTotalDivisor(type, direction, finalSummary, position) {
649
+ let returnRef;
650
+
651
+ // 2019-06-05, BRI. We should be reading from the summary -- in case we are
652
+ // running for a previous period. However, the summary does not have buy and
653
+ // sell totals for the entire history. Could be added.
654
+
655
+ if (finalSummary && type !== InstrumentType.CASH) {
656
+ if (direction === PositionDirection.SHORT) {
657
+ returnRef = position.snapshot.sells;
658
+ } else {
659
+ returnRef = position.snapshot.buys.opposite();
660
+ }
661
+ } else {
662
+ returnRef = Decimal.ZERO;
663
+ }
664
+
665
+ return returnRef;
666
+ }
667
+
644
668
  function getPreviousSummary(previousSummaries, count) {
645
669
  const index = previousSummaries.length - count;
646
670
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.142",
3
+ "version": "1.2.146",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -2659,6 +2659,7 @@ module.exports = (() => {
2659
2659
  this._dataActual.marketChange = null;
2660
2660
  this._dataActual.marketChangePercent = null;
2661
2661
  this._dataActual.cashTotal = null;
2662
+ this._dataActual.totalDivisor = null;
2662
2663
  this._dataActual.periodDivisorCurrent = null;
2663
2664
  this._dataActual.periodDivisorPrevious = null;
2664
2665
  this._dataActual.periodDivisorPrevious2 = null;
@@ -2666,6 +2667,7 @@ module.exports = (() => {
2666
2667
  this._dataFormat.currentPrice = null;
2667
2668
  this._dataFormat.basis = null;
2668
2669
  this._dataFormat.realized = null;
2670
+ this._dataFormat.realizedPercent = null;
2669
2671
  this._dataFormat.income = null;
2670
2672
  this._dataFormat.market = null;
2671
2673
  this._dataFormat.marketPercent = null;
@@ -2705,10 +2707,12 @@ module.exports = (() => {
2705
2707
  this._dataFormat.periodRealized = null;
2706
2708
  this._dataFormat.periodUnrealized = null;
2707
2709
 
2710
+ this._dataActual.totalPercent = null;
2708
2711
  this._dataActual.periodPercent = null;
2709
2712
  this._dataActual.periodPercentPrevious = null;
2710
2713
  this._dataActual.periodPercentPrevious2 = null;
2711
2714
 
2715
+ this._dataFormat.totalPercent = null;
2712
2716
  this._dataFormat.periodPercent = null;
2713
2717
  this._dataFormat.periodPercentPrevious = null;
2714
2718
  this._dataFormat.periodPercentPrevious2 = null;
@@ -3217,6 +3221,7 @@ module.exports = (() => {
3217
3221
  updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
3218
3222
  }
3219
3223
 
3224
+ updates.totalDivisor = updates.periodDivisorCurrent.add(translate(item, item.data.totalDivisor));
3220
3225
  updates.periodDivisorCurrent = updates.periodDivisorCurrent.add(translate(item, item.data.periodDivisor));
3221
3226
  updates.periodDivisorPrevious = updates.periodDivisorPrevious.add(translate(item, item.data.periodDivisorPrevious));
3222
3227
  updates.periodDivisorPrevious2 = updates.periodDivisorPrevious2.add(translate(item, item.data.periodDivisorPrevious2));
@@ -3236,6 +3241,7 @@ module.exports = (() => {
3236
3241
  periodUnrealized: Decimal.ZERO,
3237
3242
  periodIncome: Decimal.ZERO,
3238
3243
  cashTotal: Decimal.ZERO,
3244
+ totalDivisor: Decimal.ZERO,
3239
3245
  periodDivisorCurrent: Decimal.ZERO,
3240
3246
  periodDivisorPrevious: Decimal.ZERO,
3241
3247
  periodDivisorPrevious2: Decimal.ZERO
@@ -3254,6 +3260,7 @@ module.exports = (() => {
3254
3260
  actual.periodUnrealized = updates.periodUnrealized;
3255
3261
  actual.periodIncome = updates.periodIncome;
3256
3262
  actual.cashTotal = updates.cashTotal;
3263
+ actual.totalDivisor = updates.totalDivisor;
3257
3264
  actual.periodDivisorCurrent = updates.periodDivisorCurrent;
3258
3265
  actual.periodDivisorPrevious = updates.periodDivisorPrevious;
3259
3266
  actual.periodDivisorPrevious2 = updates.periodDivisorPrevious2;
@@ -3275,11 +3282,12 @@ module.exports = (() => {
3275
3282
  format.periodIncome = formatCurrency(updates.periodIncome, currency);
3276
3283
  format.cashTotal = formatCurrency(updates.cashTotal, currency);
3277
3284
 
3285
+ calculateRealizedPercent(group);
3278
3286
  calculateUnrealizedPercent(group);
3279
3287
 
3280
- actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
3281
- actual.periodPercentPrevious = calculatePeriodPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
3282
- actual.periodPercentPrevious2 = calculatePeriodPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
3288
+ actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
3289
+ actual.periodPercentPrevious = calculateGainPercent(actual.summaryTotalPrevious, actual.periodDivisorPrevious);
3290
+ actual.periodPercentPrevious2 = calculateGainPercent(actual.summaryTotalPrevious2, actual.periodDivisorPrevious2);
3283
3291
 
3284
3292
  format.periodPercent = formatPercent(actual.periodPercent, 2);
3285
3293
  format.periodPercentPrevious = formatPercent(actual.periodPercentPrevious, 2);
@@ -3386,7 +3394,9 @@ module.exports = (() => {
3386
3394
  actual.unrealized = updates.unrealized;
3387
3395
  actual.unrealizedToday = updates.unrealizedToday;
3388
3396
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
3397
+
3389
3398
  actual.total = updates.unrealized.add(actual.realized).add(actual.income);
3399
+ actual.totalPercent = calculateGainPercent(actual.total, actual.totalDivisor);
3390
3400
 
3391
3401
  let marketChange = updates.market.subtract(actual.marketPrevious);
3392
3402
  let marketChangePercent;
@@ -3424,13 +3434,15 @@ module.exports = (() => {
3424
3434
 
3425
3435
  format.total = formatCurrency(actual.total, currency);
3426
3436
  format.totalNegative = actual.total.getIsNegative();
3437
+ format.totalPercent = formatPercent(actual.totalPercent, 2);
3427
3438
 
3428
3439
  format.marketChange = formatCurrency(actual.marketChange, currency);
3429
3440
  format.marketChangePercent = formatPercent(actual.marketChangePercent, 2);
3430
3441
 
3442
+ calculateRealizedPercent(group);
3431
3443
  calculateUnrealizedPercent(group);
3432
3444
 
3433
- actual.periodPercent = calculatePeriodPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
3445
+ actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
3434
3446
  format.periodPercent = formatPercent(actual.periodPercent, 2);
3435
3447
 
3436
3448
  if (group.single && item) {
@@ -3481,21 +3493,43 @@ module.exports = (() => {
3481
3493
  }
3482
3494
  }
3483
3495
 
3496
+ function calculateRealizedPercent(group) {
3497
+ const actual = group._dataActual;
3498
+ const format = group._dataFormat;
3499
+
3500
+ const openBasis = actual.basis;
3501
+ const totalBasis = actual.totalDivisor;
3502
+
3503
+ const numerator = actual.realized;
3504
+ const denominator = totalBasis.subtract(openBasis);
3505
+
3506
+ if (denominator.getIsZero()) {
3507
+ actual.realizedPercent = Decimal.ZERO;
3508
+ } else {
3509
+ actual.realizedPercent = numerator.divide(denominator);
3510
+ }
3511
+
3512
+ format.realizedPercent = formatPercent(actual.realizedPercent, 2);
3513
+ }
3514
+
3484
3515
  function calculateUnrealizedPercent(group) {
3485
3516
  const actual = group._dataActual;
3486
3517
  const format = group._dataFormat;
3487
3518
 
3488
- if (actual.basis.getIsZero()) {
3489
- actual.unrealizedPercent = null;
3490
- format.unrealizedPercent = '—';
3519
+ const numerator = actual.unrealized;
3520
+ const denominator = actual.basis;
3521
+
3522
+ if (denominator.getIsZero()) {
3523
+ actual.unrealizedPercent = Decimal.ZERO;
3491
3524
  } else {
3492
- actual.unrealizedPercent = actual.unrealized.divide(actual.basis);
3493
- format.unrealizedPercent = formatPercent(actual.unrealizedPercent, 2);
3525
+ actual.unrealizedPercent = numerator.divide(denominator);
3494
3526
  }
3527
+
3528
+ format.unrealizedPercent = formatPercent(actual.unrealizedPercent, 2);
3495
3529
  }
3496
3530
 
3497
- function calculatePeriodPercent(periodSummaryTotal, periodDivisor) {
3498
- return periodDivisor.getIsZero() ? Decimal.ZERO : periodSummaryTotal.divide(periodDivisor);
3531
+ function calculateGainPercent(gain, basis) {
3532
+ return basis.getIsZero() ? Decimal.ZERO : gain.divide(basis);
3499
3533
  }
3500
3534
 
3501
3535
  const unchanged = { up: false, down: false };
@@ -3600,6 +3634,8 @@ module.exports = (() => {
3600
3634
 
3601
3635
  this._data.initiate = null;
3602
3636
 
3637
+ this._data.totalDivisor = null;
3638
+
3603
3639
  this._data.newsExists = false;
3604
3640
  this._data.fundamental = { };
3605
3641
  this._data.locked = getIsLocked(position);
@@ -3953,6 +3989,8 @@ module.exports = (() => {
3953
3989
  } else {
3954
3990
  data.periodPricePrevious = null;
3955
3991
  }
3992
+
3993
+ data.totalDivisor = calculateTotalDivisor(position.instrument.type, data.initiate, currentSummary, position);
3956
3994
  }
3957
3995
 
3958
3996
  function calculatePriceData(item, price) {
@@ -4147,6 +4185,26 @@ module.exports = (() => {
4147
4185
  return returnRef;
4148
4186
  }
4149
4187
 
4188
+ function calculateTotalDivisor(type, direction, finalSummary, position) {
4189
+ let returnRef;
4190
+
4191
+ // 2019-06-05, BRI. We should be reading from the summary -- in case we are
4192
+ // running for a previous period. However, the summary does not have buy and
4193
+ // sell totals for the entire history. Could be added.
4194
+
4195
+ if (finalSummary && type !== InstrumentType.CASH) {
4196
+ if (direction === PositionDirection.SHORT) {
4197
+ returnRef = position.snapshot.sells;
4198
+ } else {
4199
+ returnRef = position.snapshot.buys.opposite();
4200
+ }
4201
+ } else {
4202
+ returnRef = Decimal.ZERO;
4203
+ }
4204
+
4205
+ return returnRef;
4206
+ }
4207
+
4150
4208
  function getPreviousSummary(previousSummaries, count) {
4151
4209
  const index = previousSummaries.length - count;
4152
4210
 
@@ -13997,36 +14055,22 @@ moment.tz.load(require('./data/packed/latest.json'));
13997
14055
  function createDate (y, m, d, h, M, s, ms) {
13998
14056
  // can't just apply() to create a date:
13999
14057
  // https://stackoverflow.com/q/181348
14000
- var date;
14058
+ var date = new Date(y, m, d, h, M, s, ms);
14059
+
14001
14060
  // the date constructor remaps years 0-99 to 1900-1999
14002
- if (y < 100 && y >= 0) {
14003
- // preserve leap years using a full 400 year cycle, then reset
14004
- date = new Date(y + 400, m, d, h, M, s, ms);
14005
- if (isFinite(date.getFullYear())) {
14006
- date.setFullYear(y);
14007
- }
14008
- } else {
14009
- date = new Date(y, m, d, h, M, s, ms);
14061
+ if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
14062
+ date.setFullYear(y);
14010
14063
  }
14011
-
14012
14064
  return date;
14013
14065
  }
14014
14066
 
14015
14067
  function createUTCDate (y) {
14016
- var date;
14068
+ var date = new Date(Date.UTC.apply(null, arguments));
14069
+
14017
14070
  // the Date.UTC function remaps years 0-99 to 1900-1999
14018
- if (y < 100 && y >= 0) {
14019
- var args = Array.prototype.slice.call(arguments);
14020
- // preserve leap years using a full 400 year cycle, then reset
14021
- args[0] = y + 400;
14022
- date = new Date(Date.UTC.apply(null, args));
14023
- if (isFinite(date.getUTCFullYear())) {
14024
- date.setUTCFullYear(y);
14025
- }
14026
- } else {
14027
- date = new Date(Date.UTC.apply(null, arguments));
14071
+ if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
14072
+ date.setUTCFullYear(y);
14028
14073
  }
14029
-
14030
14074
  return date;
14031
14075
  }
14032
14076
 
@@ -14128,7 +14172,7 @@ moment.tz.load(require('./data/packed/latest.json'));
14128
14172
 
14129
14173
  var defaultLocaleWeek = {
14130
14174
  dow : 0, // Sunday is the first day of the week.
14131
- doy : 6 // The week that contains Jan 6th is the first week of the year.
14175
+ doy : 6 // The week that contains Jan 1st is the first week of the year.
14132
14176
  };
14133
14177
 
14134
14178
  function localeFirstDayOfWeek () {
@@ -14237,28 +14281,25 @@ moment.tz.load(require('./data/packed/latest.json'));
14237
14281
  }
14238
14282
 
14239
14283
  // LOCALES
14240
- function shiftWeekdays (ws, n) {
14241
- return ws.slice(n, 7).concat(ws.slice(0, n));
14242
- }
14243
14284
 
14244
14285
  var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
14245
14286
  function localeWeekdays (m, format) {
14246
- var weekdays = isArray(this._weekdays) ? this._weekdays :
14247
- this._weekdays[(m && m !== true && this._weekdays.isFormat.test(format)) ? 'format' : 'standalone'];
14248
- return (m === true) ? shiftWeekdays(weekdays, this._week.dow)
14249
- : (m) ? weekdays[m.day()] : weekdays;
14287
+ if (!m) {
14288
+ return isArray(this._weekdays) ? this._weekdays :
14289
+ this._weekdays['standalone'];
14290
+ }
14291
+ return isArray(this._weekdays) ? this._weekdays[m.day()] :
14292
+ this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
14250
14293
  }
14251
14294
 
14252
14295
  var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
14253
14296
  function localeWeekdaysShort (m) {
14254
- return (m === true) ? shiftWeekdays(this._weekdaysShort, this._week.dow)
14255
- : (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
14297
+ return (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
14256
14298
  }
14257
14299
 
14258
14300
  var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
14259
14301
  function localeWeekdaysMin (m) {
14260
- return (m === true) ? shiftWeekdays(this._weekdaysMin, this._week.dow)
14261
- : (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
14302
+ return (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
14262
14303
  }
14263
14304
 
14264
14305
  function handleStrictParse$1(weekdayName, format, strict) {
@@ -15007,13 +15048,13 @@ moment.tz.load(require('./data/packed/latest.json'));
15007
15048
  weekdayOverflow = true;
15008
15049
  }
15009
15050
  } else if (w.e != null) {
15010
- // local weekday -- counting starts from beginning of week
15051
+ // local weekday -- counting starts from begining of week
15011
15052
  weekday = w.e + dow;
15012
15053
  if (w.e < 0 || w.e > 6) {
15013
15054
  weekdayOverflow = true;
15014
15055
  }
15015
15056
  } else {
15016
- // default to beginning of week
15057
+ // default to begining of week
15017
15058
  weekday = dow;
15018
15059
  }
15019
15060
  }
@@ -15607,7 +15648,7 @@ moment.tz.load(require('./data/packed/latest.json'));
15607
15648
  years = normalizedInput.year || 0,
15608
15649
  quarters = normalizedInput.quarter || 0,
15609
15650
  months = normalizedInput.month || 0,
15610
- weeks = normalizedInput.week || normalizedInput.isoWeek || 0,
15651
+ weeks = normalizedInput.week || 0,
15611
15652
  days = normalizedInput.day || 0,
15612
15653
  hours = normalizedInput.hour || 0,
15613
15654
  minutes = normalizedInput.minute || 0,
@@ -15911,7 +15952,7 @@ moment.tz.load(require('./data/packed/latest.json'));
15911
15952
  ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match
15912
15953
  };
15913
15954
  } else if (!!(match = isoRegex.exec(input))) {
15914
- sign = (match[1] === '-') ? -1 : 1;
15955
+ sign = (match[1] === '-') ? -1 : (match[1] === '+') ? 1 : 1;
15915
15956
  duration = {
15916
15957
  y : parseIso(match[2], sign),
15917
15958
  M : parseIso(match[3], sign),
@@ -15953,7 +15994,7 @@ moment.tz.load(require('./data/packed/latest.json'));
15953
15994
  }
15954
15995
 
15955
15996
  function positiveMomentsDifference(base, other) {
15956
- var res = {};
15997
+ var res = {milliseconds: 0, months: 0};
15957
15998
 
15958
15999
  res.months = other.month() - base.month() +
15959
16000
  (other.year() - base.year()) * 12;
@@ -16062,7 +16103,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16062
16103
  if (!(this.isValid() && localInput.isValid())) {
16063
16104
  return false;
16064
16105
  }
16065
- units = normalizeUnits(units) || 'millisecond';
16106
+ units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
16066
16107
  if (units === 'millisecond') {
16067
16108
  return this.valueOf() > localInput.valueOf();
16068
16109
  } else {
@@ -16075,7 +16116,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16075
16116
  if (!(this.isValid() && localInput.isValid())) {
16076
16117
  return false;
16077
16118
  }
16078
- units = normalizeUnits(units) || 'millisecond';
16119
+ units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
16079
16120
  if (units === 'millisecond') {
16080
16121
  return this.valueOf() < localInput.valueOf();
16081
16122
  } else {
@@ -16084,14 +16125,9 @@ moment.tz.load(require('./data/packed/latest.json'));
16084
16125
  }
16085
16126
 
16086
16127
  function isBetween (from, to, units, inclusivity) {
16087
- var localFrom = isMoment(from) ? from : createLocal(from),
16088
- localTo = isMoment(to) ? to : createLocal(to);
16089
- if (!(this.isValid() && localFrom.isValid() && localTo.isValid())) {
16090
- return false;
16091
- }
16092
16128
  inclusivity = inclusivity || '()';
16093
- return (inclusivity[0] === '(' ? this.isAfter(localFrom, units) : !this.isBefore(localFrom, units)) &&
16094
- (inclusivity[1] === ')' ? this.isBefore(localTo, units) : !this.isAfter(localTo, units));
16129
+ return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
16130
+ (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
16095
16131
  }
16096
16132
 
16097
16133
  function isSame (input, units) {
@@ -16100,7 +16136,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16100
16136
  if (!(this.isValid() && localInput.isValid())) {
16101
16137
  return false;
16102
16138
  }
16103
- units = normalizeUnits(units) || 'millisecond';
16139
+ units = normalizeUnits(units || 'millisecond');
16104
16140
  if (units === 'millisecond') {
16105
16141
  return this.valueOf() === localInput.valueOf();
16106
16142
  } else {
@@ -16110,11 +16146,11 @@ moment.tz.load(require('./data/packed/latest.json'));
16110
16146
  }
16111
16147
 
16112
16148
  function isSameOrAfter (input, units) {
16113
- return this.isSame(input, units) || this.isAfter(input, units);
16149
+ return this.isSame(input, units) || this.isAfter(input,units);
16114
16150
  }
16115
16151
 
16116
16152
  function isSameOrBefore (input, units) {
16117
- return this.isSame(input, units) || this.isBefore(input, units);
16153
+ return this.isSame(input, units) || this.isBefore(input,units);
16118
16154
  }
16119
16155
 
16120
16156
  function diff (input, units, asFloat) {
@@ -16291,130 +16327,62 @@ moment.tz.load(require('./data/packed/latest.json'));
16291
16327
  return this._locale;
16292
16328
  }
16293
16329
 
16294
- var MS_PER_SECOND = 1000;
16295
- var MS_PER_MINUTE = 60 * MS_PER_SECOND;
16296
- var MS_PER_HOUR = 60 * MS_PER_MINUTE;
16297
- var MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR;
16298
-
16299
- // actual modulo - handles negative numbers (for dates before 1970):
16300
- function mod$1(dividend, divisor) {
16301
- return (dividend % divisor + divisor) % divisor;
16302
- }
16303
-
16304
- function localStartOfDate(y, m, d) {
16305
- // the date constructor remaps years 0-99 to 1900-1999
16306
- if (y < 100 && y >= 0) {
16307
- // preserve leap years using a full 400 year cycle, then reset
16308
- return new Date(y + 400, m, d) - MS_PER_400_YEARS;
16309
- } else {
16310
- return new Date(y, m, d).valueOf();
16311
- }
16312
- }
16313
-
16314
- function utcStartOfDate(y, m, d) {
16315
- // Date.UTC remaps years 0-99 to 1900-1999
16316
- if (y < 100 && y >= 0) {
16317
- // preserve leap years using a full 400 year cycle, then reset
16318
- return Date.UTC(y + 400, m, d) - MS_PER_400_YEARS;
16319
- } else {
16320
- return Date.UTC(y, m, d);
16321
- }
16322
- }
16323
-
16324
16330
  function startOf (units) {
16325
- var time;
16326
16331
  units = normalizeUnits(units);
16327
- if (units === undefined || units === 'millisecond' || !this.isValid()) {
16328
- return this;
16329
- }
16330
-
16331
- var startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
16332
-
16332
+ // the following switch intentionally omits break keywords
16333
+ // to utilize falling through the cases.
16333
16334
  switch (units) {
16334
16335
  case 'year':
16335
- time = startOfDate(this.year(), 0, 1);
16336
- break;
16336
+ this.month(0);
16337
+ /* falls through */
16337
16338
  case 'quarter':
16338
- time = startOfDate(this.year(), this.month() - this.month() % 3, 1);
16339
- break;
16340
16339
  case 'month':
16341
- time = startOfDate(this.year(), this.month(), 1);
16342
- break;
16340
+ this.date(1);
16341
+ /* falls through */
16343
16342
  case 'week':
16344
- time = startOfDate(this.year(), this.month(), this.date() - this.weekday());
16345
- break;
16346
16343
  case 'isoWeek':
16347
- time = startOfDate(this.year(), this.month(), this.date() - (this.isoWeekday() - 1));
16348
- break;
16349
16344
  case 'day':
16350
16345
  case 'date':
16351
- time = startOfDate(this.year(), this.month(), this.date());
16352
- break;
16346
+ this.hours(0);
16347
+ /* falls through */
16353
16348
  case 'hour':
16354
- time = this._d.valueOf();
16355
- time -= mod$1(time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE), MS_PER_HOUR);
16356
- break;
16349
+ this.minutes(0);
16350
+ /* falls through */
16357
16351
  case 'minute':
16358
- time = this._d.valueOf();
16359
- time -= mod$1(time, MS_PER_MINUTE);
16360
- break;
16352
+ this.seconds(0);
16353
+ /* falls through */
16361
16354
  case 'second':
16362
- time = this._d.valueOf();
16363
- time -= mod$1(time, MS_PER_SECOND);
16364
- break;
16355
+ this.milliseconds(0);
16356
+ }
16357
+
16358
+ // weeks are a special case
16359
+ if (units === 'week') {
16360
+ this.weekday(0);
16361
+ }
16362
+ if (units === 'isoWeek') {
16363
+ this.isoWeekday(1);
16364
+ }
16365
+
16366
+ // quarters are also special
16367
+ if (units === 'quarter') {
16368
+ this.month(Math.floor(this.month() / 3) * 3);
16365
16369
  }
16366
16370
 
16367
- this._d.setTime(time);
16368
- hooks.updateOffset(this, true);
16369
16371
  return this;
16370
16372
  }
16371
16373
 
16372
16374
  function endOf (units) {
16373
- var time;
16374
16375
  units = normalizeUnits(units);
16375
- if (units === undefined || units === 'millisecond' || !this.isValid()) {
16376
+ if (units === undefined || units === 'millisecond') {
16376
16377
  return this;
16377
16378
  }
16378
16379
 
16379
- var startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
16380
-
16381
- switch (units) {
16382
- case 'year':
16383
- time = startOfDate(this.year() + 1, 0, 1) - 1;
16384
- break;
16385
- case 'quarter':
16386
- time = startOfDate(this.year(), this.month() - this.month() % 3 + 3, 1) - 1;
16387
- break;
16388
- case 'month':
16389
- time = startOfDate(this.year(), this.month() + 1, 1) - 1;
16390
- break;
16391
- case 'week':
16392
- time = startOfDate(this.year(), this.month(), this.date() - this.weekday() + 7) - 1;
16393
- break;
16394
- case 'isoWeek':
16395
- time = startOfDate(this.year(), this.month(), this.date() - (this.isoWeekday() - 1) + 7) - 1;
16396
- break;
16397
- case 'day':
16398
- case 'date':
16399
- time = startOfDate(this.year(), this.month(), this.date() + 1) - 1;
16400
- break;
16401
- case 'hour':
16402
- time = this._d.valueOf();
16403
- time += MS_PER_HOUR - mod$1(time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE), MS_PER_HOUR) - 1;
16404
- break;
16405
- case 'minute':
16406
- time = this._d.valueOf();
16407
- time += MS_PER_MINUTE - mod$1(time, MS_PER_MINUTE) - 1;
16408
- break;
16409
- case 'second':
16410
- time = this._d.valueOf();
16411
- time += MS_PER_SECOND - mod$1(time, MS_PER_SECOND) - 1;
16412
- break;
16380
+ // 'date' is an alias for 'day', so it should be considered as such.
16381
+ if (units === 'date') {
16382
+ units = 'day';
16413
16383
  }
16414
16384
 
16415
- this._d.setTime(time);
16416
- hooks.updateOffset(this, true);
16417
- return this;
16385
+ return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
16418
16386
  }
16419
16387
 
16420
16388
  function valueOf () {
@@ -17120,14 +17088,10 @@ moment.tz.load(require('./data/packed/latest.json'));
17120
17088
 
17121
17089
  units = normalizeUnits(units);
17122
17090
 
17123
- if (units === 'month' || units === 'quarter' || units === 'year') {
17124
- days = this._days + milliseconds / 864e5;
17091
+ if (units === 'month' || units === 'year') {
17092
+ days = this._days + milliseconds / 864e5;
17125
17093
  months = this._months + daysToMonths(days);
17126
- switch (units) {
17127
- case 'month': return months;
17128
- case 'quarter': return months / 3;
17129
- case 'year': return months / 12;
17130
- }
17094
+ return units === 'month' ? months : months / 12;
17131
17095
  } else {
17132
17096
  // handle milliseconds separately because of floating point math errors (issue #1867)
17133
17097
  days = this._days + Math.round(monthsToDays(this._months));
@@ -17170,7 +17134,6 @@ moment.tz.load(require('./data/packed/latest.json'));
17170
17134
  var asDays = makeAs('d');
17171
17135
  var asWeeks = makeAs('w');
17172
17136
  var asMonths = makeAs('M');
17173
- var asQuarters = makeAs('Q');
17174
17137
  var asYears = makeAs('y');
17175
17138
 
17176
17139
  function clone$1 () {
@@ -17362,7 +17325,6 @@ moment.tz.load(require('./data/packed/latest.json'));
17362
17325
  proto$2.asDays = asDays;
17363
17326
  proto$2.asWeeks = asWeeks;
17364
17327
  proto$2.asMonths = asMonths;
17365
- proto$2.asQuarters = asQuarters;
17366
17328
  proto$2.asYears = asYears;
17367
17329
  proto$2.valueOf = valueOf$1;
17368
17330
  proto$2._bubble = bubble;
@@ -17407,7 +17369,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17407
17369
  // Side effect imports
17408
17370
 
17409
17371
 
17410
- hooks.version = '2.24.0';
17372
+ hooks.version = '2.22.2';
17411
17373
 
17412
17374
  setHookCallback(createLocal);
17413
17375
 
@@ -17448,7 +17410,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17448
17410
  TIME: 'HH:mm', // <input type="time" />
17449
17411
  TIME_SECONDS: 'HH:mm:ss', // <input type="time" step="1" />
17450
17412
  TIME_MS: 'HH:mm:ss.SSS', // <input type="time" step="0.001" />
17451
- WEEK: 'GGGG-[W]WW', // <input type="week" />
17413
+ WEEK: 'YYYY-[W]WW', // <input type="week" />
17452
17414
  MONTH: 'YYYY-MM' // <input type="month" />
17453
17415
  };
17454
17416
 
@@ -18415,7 +18377,9 @@ describe('When a position container data is gathered', () => {
18415
18377
  value: new Decimal(456),
18416
18378
  open: new Decimal(1),
18417
18379
  income: new Decimal(0),
18418
- gain: new Decimal(0)
18380
+ gain: new Decimal(0),
18381
+ buys: new Decimal(50),
18382
+ sells: new Decimal(0)
18419
18383
  }
18420
18384
  };
18421
18385
  }
@@ -30,7 +30,9 @@ describe('When a position container data is gathered', () => {
30
30
  value: new Decimal(456),
31
31
  open: new Decimal(1),
32
32
  income: new Decimal(0),
33
- gain: new Decimal(0)
33
+ gain: new Decimal(0),
34
+ buys: new Decimal(50),
35
+ sells: new Decimal(0)
34
36
  }
35
37
  };
36
38
  }