@barchart/portfolio-api-common 1.2.132 → 1.2.133

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.
@@ -385,6 +385,7 @@ module.exports = (() => {
385
385
 
386
386
  const previousSummary1 = getPreviousSummary(item.previousSummaries, 1);
387
387
  const previousSummary2 = getPreviousSummary(item.previousSummaries, 2);
388
+ const previousSummary3 = getPreviousSummary(item.previousSummaries, 3);
388
389
 
389
390
  const snapshot = getSnapshot(position, currentSummary, item._reporting);
390
391
 
@@ -416,13 +417,13 @@ module.exports = (() => {
416
417
  data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
417
418
  data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
418
419
 
419
- data.periodGain = calculatePeriodGain(currentSummary);
420
- data.periodGainPrevious = calculatePeriodGain(previousSummary1);
421
- data.periodGainPrevious2 = calculatePeriodGain(previousSummary2);
420
+ data.periodGain = calculatePeriodGain(currentSummary, previousSummary1);
421
+ data.periodGainPrevious = calculatePeriodGain(previousSummary1, previousSummary2);
422
+ data.periodGainPrevious2 = calculatePeriodGain(previousSummary2, previousSummary3);
422
423
 
423
- data.periodDivisor = calculatePeriodDivisor(currentSummary);
424
- data.periodDivisorPrevious = calculatePeriodDivisor(previousSummary1);
425
- data.periodDivisorPrevious2 = calculatePeriodDivisor(previousSummary2);
424
+ data.periodDivisor = calculatePeriodDivisor(currentSummary, previousSummary1);
425
+ data.periodDivisorPrevious = calculatePeriodDivisor(previousSummary1, previousSummary2);
426
+ data.periodDivisorPrevious2 = calculatePeriodDivisor(previousSummary2, previousSummary3);
426
427
 
427
428
  if (snapshot.open.getIsZero()) {
428
429
  data.basisPrice = Decimal.ZERO;
@@ -506,6 +507,7 @@ module.exports = (() => {
506
507
  data.unrealizedTodayChange = unrealizedTodayChange;
507
508
 
508
509
  const currentSummary = item.currentSummary;
510
+ const previousSummary = getPreviousSummary(item.previousSummaries, 1);
509
511
 
510
512
  if (currentSummary && position.instrument.type !== InstrumentType.CASH) {
511
513
  let priceToUse;
@@ -533,7 +535,7 @@ module.exports = (() => {
533
535
  data.unrealized = unrealized;
534
536
  data.unrealizedChange = unrealizedChange;
535
537
 
536
- let periodGain = calculatePeriodGain(currentSummary, priceToUse);
538
+ let periodGain = calculatePeriodGain(currentSummary, previousSummary, priceToUse);
537
539
  let periodGainChange;
538
540
 
539
541
  if (data.periodGain !== null) {
@@ -558,10 +560,18 @@ module.exports = (() => {
558
560
  }
559
561
  }
560
562
 
561
- function calculatePeriodGain(currentSummary, overridePrice) {
563
+ function calculatePeriodGain(currentSummary, previousSummary, overridePrice) {
562
564
  let returnRef;
563
565
 
564
566
  if (currentSummary) {
567
+ let startValue;
568
+
569
+ if (previousSummary) {
570
+ startValue = previousSummary.end.value;
571
+ } else {
572
+ startValue = Decimal.ZERO;
573
+ }
574
+
565
575
  let endValue;
566
576
 
567
577
  if (overridePrice) {
@@ -570,7 +580,7 @@ module.exports = (() => {
570
580
  endValue = currentSummary.end.value;
571
581
  }
572
582
 
573
- const valueChange = endValue.subtract(currentSummary.start.value);
583
+ const valueChange = endValue.subtract(startValue);
574
584
  const tradeChange = currentSummary.period.sells.subtract(currentSummary.period.buys);
575
585
  const incomeChange = currentSummary.period.income;
576
586
 
@@ -582,11 +592,19 @@ module.exports = (() => {
582
592
  return returnRef;
583
593
  }
584
594
 
585
- function calculatePeriodDivisor(currentSummary) {
595
+ function calculatePeriodDivisor(currentSummary, previousSummary) {
586
596
  let returnRef;
587
597
 
588
598
  if (currentSummary) {
589
- returnRef = currentSummary.start.value.add(currentSummary.period.buys);
599
+ let startValue;
600
+
601
+ if (previousSummary) {
602
+ startValue = previousSummary.end.value;
603
+ } else {
604
+ startValue = Decimal.ZERO;
605
+ }
606
+
607
+ returnRef = startValue.add(currentSummary.period.buys);
590
608
  } else {
591
609
  returnRef = Decimal.ZERO;
592
610
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.132",
3
+ "version": "1.2.133",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -3891,6 +3891,7 @@ module.exports = (() => {
3891
3891
 
3892
3892
  const previousSummary1 = getPreviousSummary(item.previousSummaries, 1);
3893
3893
  const previousSummary2 = getPreviousSummary(item.previousSummaries, 2);
3894
+ const previousSummary3 = getPreviousSummary(item.previousSummaries, 3);
3894
3895
 
3895
3896
  const snapshot = getSnapshot(position, currentSummary, item._reporting);
3896
3897
 
@@ -3922,13 +3923,13 @@ module.exports = (() => {
3922
3923
  data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
3923
3924
  data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
3924
3925
 
3925
- data.periodGain = calculatePeriodGain(currentSummary);
3926
- data.periodGainPrevious = calculatePeriodGain(previousSummary1);
3927
- data.periodGainPrevious2 = calculatePeriodGain(previousSummary2);
3926
+ data.periodGain = calculatePeriodGain(currentSummary, previousSummary1);
3927
+ data.periodGainPrevious = calculatePeriodGain(previousSummary1, previousSummary2);
3928
+ data.periodGainPrevious2 = calculatePeriodGain(previousSummary2, previousSummary3);
3928
3929
 
3929
- data.periodDivisor = calculatePeriodDivisor(currentSummary);
3930
- data.periodDivisorPrevious = calculatePeriodDivisor(previousSummary1);
3931
- data.periodDivisorPrevious2 = calculatePeriodDivisor(previousSummary2);
3930
+ data.periodDivisor = calculatePeriodDivisor(currentSummary, previousSummary1);
3931
+ data.periodDivisorPrevious = calculatePeriodDivisor(previousSummary1, previousSummary2);
3932
+ data.periodDivisorPrevious2 = calculatePeriodDivisor(previousSummary2, previousSummary3);
3932
3933
 
3933
3934
  if (snapshot.open.getIsZero()) {
3934
3935
  data.basisPrice = Decimal.ZERO;
@@ -4012,6 +4013,7 @@ module.exports = (() => {
4012
4013
  data.unrealizedTodayChange = unrealizedTodayChange;
4013
4014
 
4014
4015
  const currentSummary = item.currentSummary;
4016
+ const previousSummary = getPreviousSummary(item.previousSummaries, 1);
4015
4017
 
4016
4018
  if (currentSummary && position.instrument.type !== InstrumentType.CASH) {
4017
4019
  let priceToUse;
@@ -4039,7 +4041,7 @@ module.exports = (() => {
4039
4041
  data.unrealized = unrealized;
4040
4042
  data.unrealizedChange = unrealizedChange;
4041
4043
 
4042
- let periodGain = calculatePeriodGain(currentSummary, priceToUse);
4044
+ let periodGain = calculatePeriodGain(currentSummary, previousSummary, priceToUse);
4043
4045
  let periodGainChange;
4044
4046
 
4045
4047
  if (data.periodGain !== null) {
@@ -4064,10 +4066,18 @@ module.exports = (() => {
4064
4066
  }
4065
4067
  }
4066
4068
 
4067
- function calculatePeriodGain(currentSummary, overridePrice) {
4069
+ function calculatePeriodGain(currentSummary, previousSummary, overridePrice) {
4068
4070
  let returnRef;
4069
4071
 
4070
4072
  if (currentSummary) {
4073
+ let startValue;
4074
+
4075
+ if (previousSummary) {
4076
+ startValue = previousSummary.end.value;
4077
+ } else {
4078
+ startValue = Decimal.ZERO;
4079
+ }
4080
+
4071
4081
  let endValue;
4072
4082
 
4073
4083
  if (overridePrice) {
@@ -4076,7 +4086,7 @@ module.exports = (() => {
4076
4086
  endValue = currentSummary.end.value;
4077
4087
  }
4078
4088
 
4079
- const valueChange = endValue.subtract(currentSummary.start.value);
4089
+ const valueChange = endValue.subtract(startValue);
4080
4090
  const tradeChange = currentSummary.period.sells.subtract(currentSummary.period.buys);
4081
4091
  const incomeChange = currentSummary.period.income;
4082
4092
 
@@ -4088,11 +4098,19 @@ module.exports = (() => {
4088
4098
  return returnRef;
4089
4099
  }
4090
4100
 
4091
- function calculatePeriodDivisor(currentSummary) {
4101
+ function calculatePeriodDivisor(currentSummary, previousSummary) {
4092
4102
  let returnRef;
4093
4103
 
4094
4104
  if (currentSummary) {
4095
- returnRef = currentSummary.start.value.add(currentSummary.period.buys);
4105
+ let startValue;
4106
+
4107
+ if (previousSummary) {
4108
+ startValue = previousSummary.end.value;
4109
+ } else {
4110
+ startValue = Decimal.ZERO;
4111
+ }
4112
+
4113
+ returnRef = startValue.add(currentSummary.period.buys);
4096
4114
  } else {
4097
4115
  returnRef = Decimal.ZERO;
4098
4116
  }