@barchart/portfolio-api-common 1.2.143 → 1.2.144

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.
@@ -145,6 +145,7 @@ module.exports = (() => {
145
145
  this._dataFormat.currentPrice = null;
146
146
  this._dataFormat.basis = null;
147
147
  this._dataFormat.realized = null;
148
+ this._dataFormat.realizedPercent = null;
148
149
  this._dataFormat.income = null;
149
150
  this._dataFormat.market = null;
150
151
  this._dataFormat.marketPercent = null;
@@ -759,6 +760,7 @@ module.exports = (() => {
759
760
  format.periodIncome = formatCurrency(updates.periodIncome, currency);
760
761
  format.cashTotal = formatCurrency(updates.cashTotal, currency);
761
762
 
763
+ calculateRealizedPercent(group);
762
764
  calculateUnrealizedPercent(group);
763
765
 
764
766
  actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
@@ -915,6 +917,7 @@ module.exports = (() => {
915
917
  format.marketChange = formatCurrency(actual.marketChange, currency);
916
918
  format.marketChangePercent = formatPercent(actual.marketChangePercent, 2);
917
919
 
920
+ calculateRealizedPercent(group);
918
921
  calculateUnrealizedPercent(group);
919
922
 
920
923
  actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
@@ -968,6 +971,24 @@ module.exports = (() => {
968
971
  }
969
972
  }
970
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 closedBasis = totalBasis.subtract(openBasis);
982
+
983
+ if (closedBasis.getIsZero()) {
984
+ actual.realizedPercent = null;
985
+ format.realizedPercent = '—';
986
+ } else {
987
+ actual.realizedPercent = actual.realized.divide(closedBasis);
988
+ format.realizedPercent = formatPercent(actual.realizedPercent, 2);
989
+ }
990
+ }
991
+
971
992
  function calculateUnrealizedPercent(group) {
972
993
  const actual = group._dataActual;
973
994
  const format = group._dataFormat;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.143",
3
+ "version": "1.2.144",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -2667,6 +2667,7 @@ module.exports = (() => {
2667
2667
  this._dataFormat.currentPrice = null;
2668
2668
  this._dataFormat.basis = null;
2669
2669
  this._dataFormat.realized = null;
2670
+ this._dataFormat.realizedPercent = null;
2670
2671
  this._dataFormat.income = null;
2671
2672
  this._dataFormat.market = null;
2672
2673
  this._dataFormat.marketPercent = null;
@@ -3281,6 +3282,7 @@ module.exports = (() => {
3281
3282
  format.periodIncome = formatCurrency(updates.periodIncome, currency);
3282
3283
  format.cashTotal = formatCurrency(updates.cashTotal, currency);
3283
3284
 
3285
+ calculateRealizedPercent(group);
3284
3286
  calculateUnrealizedPercent(group);
3285
3287
 
3286
3288
  actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
@@ -3437,6 +3439,7 @@ module.exports = (() => {
3437
3439
  format.marketChange = formatCurrency(actual.marketChange, currency);
3438
3440
  format.marketChangePercent = formatPercent(actual.marketChangePercent, 2);
3439
3441
 
3442
+ calculateRealizedPercent(group);
3440
3443
  calculateUnrealizedPercent(group);
3441
3444
 
3442
3445
  actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
@@ -3490,6 +3493,24 @@ module.exports = (() => {
3490
3493
  }
3491
3494
  }
3492
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 closedBasis = totalBasis.subtract(openBasis);
3504
+
3505
+ if (closedBasis.getIsZero()) {
3506
+ actual.realizedPercent = null;
3507
+ format.realizedPercent = '—';
3508
+ } else {
3509
+ actual.realizedPercent = actual.realized.divide(closedBasis);
3510
+ format.realizedPercent = formatPercent(actual.realizedPercent, 2);
3511
+ }
3512
+ }
3513
+
3493
3514
  function calculateUnrealizedPercent(group) {
3494
3515
  const actual = group._dataActual;
3495
3516
  const format = group._dataFormat;