@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/lib/data/TransactionType.js +40 -26
- package/lib/processing/PositionContainer.js +1 -1
- package/lib/processing/PositionGroup.js +8 -0
- package/lib/processing/PositionItem.js +18 -3
- package/package-lock.json +5484 -0
- package/package.json +1 -1
- package/test/SpecRunner.js +80 -122
|
@@ -17,9 +17,10 @@ module.exports = (() => {
|
|
|
17
17
|
* @param {Boolean} income
|
|
18
18
|
* @param {Boolean} opening
|
|
19
19
|
* @param {Boolean} closing
|
|
20
|
+
* @param {Boolean} fee
|
|
20
21
|
*/
|
|
21
22
|
class TransactionType extends Enum {
|
|
22
|
-
constructor(code, description, display, purchase, sale, income, opening, closing) {
|
|
23
|
+
constructor(code, description, display, purchase, sale, income, opening, closing, fee) {
|
|
23
24
|
super(code, description);
|
|
24
25
|
|
|
25
26
|
assert.argumentIsRequired(display, 'display', String);
|
|
@@ -28,6 +29,7 @@ module.exports = (() => {
|
|
|
28
29
|
assert.argumentIsRequired(income, 'income', Boolean);
|
|
29
30
|
assert.argumentIsRequired(opening, 'opening', Boolean);
|
|
30
31
|
assert.argumentIsRequired(closing, 'closing', Boolean);
|
|
32
|
+
assert.argumentIsRequired(fee, 'fee', Boolean);
|
|
31
33
|
|
|
32
34
|
this._display = display;
|
|
33
35
|
this._purchase = purchase;
|
|
@@ -35,6 +37,7 @@ module.exports = (() => {
|
|
|
35
37
|
this._income = income;
|
|
36
38
|
this._opening = opening;
|
|
37
39
|
this._closing = closing;
|
|
40
|
+
this._fee = fee
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
/**
|
|
@@ -58,7 +61,7 @@ module.exports = (() => {
|
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
/**
|
|
61
|
-
* Indicates if the
|
|
64
|
+
* Indicates if the transaction was a purchase.
|
|
62
65
|
*
|
|
63
66
|
* @public
|
|
64
67
|
* @returns {Boolean}
|
|
@@ -68,7 +71,7 @@ module.exports = (() => {
|
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
|
-
* Indicates if the
|
|
74
|
+
* Indicates if the transaction was a sale.
|
|
72
75
|
*
|
|
73
76
|
* @public
|
|
74
77
|
* @returns {Boolean}
|
|
@@ -88,7 +91,7 @@ module.exports = (() => {
|
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
/**
|
|
91
|
-
* Indicates if the
|
|
94
|
+
* Indicates if the transaction opens the position (i.e. increases its
|
|
92
95
|
* magnitude).
|
|
93
96
|
*
|
|
94
97
|
* @public
|
|
@@ -99,7 +102,7 @@ module.exports = (() => {
|
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
/**
|
|
102
|
-
* Indicates if the
|
|
105
|
+
* Indicates if the transaction closes the position (i.e. decreases its
|
|
103
106
|
* magnitude).
|
|
104
107
|
*
|
|
105
108
|
* @public
|
|
@@ -109,6 +112,17 @@ module.exports = (() => {
|
|
|
109
112
|
return this._closing;
|
|
110
113
|
}
|
|
111
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Indicates if the transaction is a chart that neither opens nor
|
|
117
|
+
* closes the position.
|
|
118
|
+
*
|
|
119
|
+
* @public
|
|
120
|
+
* @returns {Boolean}
|
|
121
|
+
*/
|
|
122
|
+
get fee() {
|
|
123
|
+
return this._fee;
|
|
124
|
+
}
|
|
125
|
+
|
|
112
126
|
/**
|
|
113
127
|
* A purchase.
|
|
114
128
|
*
|
|
@@ -312,27 +326,27 @@ module.exports = (() => {
|
|
|
312
326
|
}
|
|
313
327
|
}
|
|
314
328
|
|
|
315
|
-
const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false);
|
|
316
|
-
const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true);
|
|
317
|
-
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true);
|
|
318
|
-
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false);
|
|
319
|
-
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false);
|
|
320
|
-
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false);
|
|
321
|
-
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false);
|
|
322
|
-
const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false);
|
|
323
|
-
const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false,
|
|
324
|
-
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, false);
|
|
325
|
-
|
|
326
|
-
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false);
|
|
327
|
-
const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false);
|
|
328
|
-
|
|
329
|
-
const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false);
|
|
330
|
-
const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false);
|
|
331
|
-
const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false);
|
|
332
|
-
const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false);
|
|
333
|
-
|
|
334
|
-
const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false);
|
|
335
|
-
const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false);
|
|
329
|
+
const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false);
|
|
330
|
+
const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false);
|
|
331
|
+
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false);
|
|
332
|
+
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false);
|
|
333
|
+
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false);
|
|
334
|
+
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false);
|
|
335
|
+
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false);
|
|
336
|
+
const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false);
|
|
337
|
+
const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, false, false, true);
|
|
338
|
+
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false);
|
|
339
|
+
|
|
340
|
+
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false);
|
|
341
|
+
const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false);
|
|
342
|
+
|
|
343
|
+
const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false);
|
|
344
|
+
const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false);
|
|
345
|
+
const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false);
|
|
346
|
+
const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false);
|
|
347
|
+
|
|
348
|
+
const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false);
|
|
349
|
+
const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false);
|
|
336
350
|
|
|
337
351
|
return TransactionType;
|
|
338
352
|
})();
|
|
@@ -73,7 +73,7 @@ module.exports = (() => {
|
|
|
73
73
|
}, { });
|
|
74
74
|
|
|
75
75
|
this._previousSummaryFrame = PositionSummaryFrame.YEARLY;
|
|
76
|
-
this._previousSummaryRanges = this._previousSummaryFrame.getRecentRanges(
|
|
76
|
+
this._previousSummaryRanges = this._previousSummaryFrame.getRecentRanges(1);
|
|
77
77
|
|
|
78
78
|
this._summariesPrevious = summaries.reduce((map, summary) => {
|
|
79
79
|
addSummaryPrevious(map, summary, this._previousSummaryFrame, this._previousSummaryRanges);
|
|
@@ -127,6 +127,7 @@ module.exports = (() => {
|
|
|
127
127
|
this._dataActual.total = null;
|
|
128
128
|
this._dataActual.summaryTotalCurrent = null;
|
|
129
129
|
this._dataActual.summaryTotalPrevious = null;
|
|
130
|
+
this._dataActual.summaryTotalPrevious2 = null;
|
|
130
131
|
this._dataActual.cashTotal = null;
|
|
131
132
|
|
|
132
133
|
this._dataFormat.currentPrice = null;
|
|
@@ -148,6 +149,8 @@ module.exports = (() => {
|
|
|
148
149
|
this._dataActual.summaryTotalCurrentNegative = false;
|
|
149
150
|
this._dataFormat.summaryTotalPrevious = null;
|
|
150
151
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
152
|
+
this._dataFormat.summaryTotalPrevious2 = null;
|
|
153
|
+
this._dataFormat.summaryTotalPrevious2Negative = false;
|
|
151
154
|
this._dataFormat.cashTotal = null;
|
|
152
155
|
this._dataFormat.portfolioType = null;
|
|
153
156
|
|
|
@@ -595,6 +598,7 @@ module.exports = (() => {
|
|
|
595
598
|
updates.income = updates.income.add(translate(item, item.data.income));
|
|
596
599
|
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.summaryTotalCurrent));
|
|
597
600
|
updates.summaryTotalPrevious = updates.summaryTotalPrevious.add(translate(item, item.data.summaryTotalPrevious));
|
|
601
|
+
updates.summaryTotalPrevious2 = updates.summaryTotalPrevious2.add(translate(item, item.data.summaryTotalPrevious2));
|
|
598
602
|
|
|
599
603
|
if (item.position.instrument.type === InstrumentType.CASH) {
|
|
600
604
|
updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
|
|
@@ -608,6 +612,7 @@ module.exports = (() => {
|
|
|
608
612
|
income: Decimal.ZERO,
|
|
609
613
|
summaryTotalCurrent: Decimal.ZERO,
|
|
610
614
|
summaryTotalPrevious: Decimal.ZERO,
|
|
615
|
+
summaryTotalPrevious2: Decimal.ZERO,
|
|
611
616
|
cashTotal: Decimal.ZERO
|
|
612
617
|
});
|
|
613
618
|
|
|
@@ -617,6 +622,7 @@ module.exports = (() => {
|
|
|
617
622
|
actual.income = updates.income;
|
|
618
623
|
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
619
624
|
actual.summaryTotalPrevious = updates.summaryTotalPrevious;
|
|
625
|
+
actual.summaryTotalPrevious2 = updates.summaryTotalPrevious2;
|
|
620
626
|
actual.cashTotal = updates.cashTotal;
|
|
621
627
|
|
|
622
628
|
format.basis = formatCurrency(actual.basis, currency);
|
|
@@ -626,6 +632,8 @@ module.exports = (() => {
|
|
|
626
632
|
format.summaryTotalCurrent = formatCurrency(updates.summaryTotalCurrent, currency);
|
|
627
633
|
format.summaryTotalPrevious = formatCurrency(updates.summaryTotalPrevious, currency);
|
|
628
634
|
format.summaryTotalPreviousNegative = updates.summaryTotalPrevious.getIsNegative();
|
|
635
|
+
format.summaryTotalPrevious2 = formatCurrency(updates.summaryTotalPrevious2, currency);
|
|
636
|
+
format.summaryTotalPrevious2Negative = updates.summaryTotalPrevious2.getIsNegative();
|
|
629
637
|
format.cashTotal = formatCurrency(updates.cashTotal, currency);
|
|
630
638
|
|
|
631
639
|
calculateUnrealizedPercent(group);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
assert = require('@barchart/common-js/lang/assert'),
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
3
2
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
4
3
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
5
4
|
Disposable = require('@barchart/common-js/lang/Disposable'),
|
|
@@ -59,6 +58,7 @@ module.exports = (() => {
|
|
|
59
58
|
this._data.summaryTotalCurrentChange = null;
|
|
60
59
|
|
|
61
60
|
this._data.summaryTotalPrevious = null;
|
|
61
|
+
this._data.summaryTotalPrevious2 = null;
|
|
62
62
|
|
|
63
63
|
this._data.realized = null;
|
|
64
64
|
this._data.income = null;
|
|
@@ -318,7 +318,8 @@ module.exports = (() => {
|
|
|
318
318
|
data.income = snapshot.income;
|
|
319
319
|
|
|
320
320
|
data.summaryTotalCurrent = calculateSummaryTotal(item.currentSummary);
|
|
321
|
-
data.summaryTotalPrevious = calculateSummaryTotal(
|
|
321
|
+
data.summaryTotalPrevious = calculateSummaryTotal(getPreviousSummary(previousSummaries, 1));
|
|
322
|
+
data.summaryTotalPrevious2 = calculateSummaryTotal(getPreviousSummary(previousSummaries, 2));
|
|
322
323
|
|
|
323
324
|
if (snapshot.open.getIsZero()) {
|
|
324
325
|
data.basisPrice = Decimal.ZERO;
|
|
@@ -439,5 +440,19 @@ module.exports = (() => {
|
|
|
439
440
|
return returnRef;
|
|
440
441
|
}
|
|
441
442
|
|
|
443
|
+
function getPreviousSummary(previousSummaries, count) {
|
|
444
|
+
const index = previousSummaries.length - count;
|
|
445
|
+
|
|
446
|
+
let summary;
|
|
447
|
+
|
|
448
|
+
if (!(index < 0)) {
|
|
449
|
+
summary = previousSummaries[index];
|
|
450
|
+
} else {
|
|
451
|
+
summary = null;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
return summary;
|
|
455
|
+
}
|
|
456
|
+
|
|
442
457
|
return PositionItem;
|
|
443
458
|
})();
|