@barchart/portfolio-api-common 1.3.13 → 1.3.17
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.
|
@@ -285,14 +285,14 @@ module.exports = (() => {
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
-
const portfolioUpdateFailedNoPortfolio = new FailureType('PORTFOLIO_UPDATE_FAILED_NO_PORTFOLIO', 'Unable to update portfolio. The portfolio does not exist, has it been deleted?');
|
|
289
|
-
const portfolioDeleteFailedNoPortfolio = new FailureType('PORTFOLIO_DELETE_FAILED_NO_PORTFOLIO', 'Unable to delete portfolio. The portfolio does not exist, has it already been deleted?');
|
|
288
|
+
const portfolioUpdateFailedNoPortfolio = new FailureType('PORTFOLIO_UPDATE_FAILED_NO_PORTFOLIO', 'Unable to update portfolio. The portfolio does not exist, has it been deleted?', false);
|
|
289
|
+
const portfolioDeleteFailedNoPortfolio = new FailureType('PORTFOLIO_DELETE_FAILED_NO_PORTFOLIO', 'Unable to delete portfolio. The portfolio does not exist, has it already been deleted?', false);
|
|
290
290
|
|
|
291
|
-
const positionCreateFailedNoPortfolio = new FailureType('POSITION_CREATE_FAILED_NO_PORTFOLIO', 'Unable to create transaction. The portfolio does not exist, has it been deleted?');
|
|
292
|
-
const positionUpdateFailedNoPosition = new FailureType('POSITION_UPDATE_FAILED_NO_POSITION', 'Unable to update preferences for position. The position does not exist, has it been deleted?');
|
|
291
|
+
const positionCreateFailedNoPortfolio = new FailureType('POSITION_CREATE_FAILED_NO_PORTFOLIO', 'Unable to create transaction. The portfolio does not exist, has it been deleted?', false);
|
|
292
|
+
const positionUpdateFailedNoPosition = new FailureType('POSITION_UPDATE_FAILED_NO_POSITION', 'Unable to update preferences for position. The position does not exist, has it been deleted?', false);
|
|
293
293
|
const positionDeleteFailedPositionLocked = new FailureType('POSITION_DELETE_FAILED_POSITION_LOCKED', 'Unable to delete position, your {L|description} history is being recalculated. Please wait a minute or two and retry.');
|
|
294
294
|
|
|
295
|
-
const transactionCreateFailedNoPosition = new FailureType('TRANSACTION_CREATE_FAILED_NO_POSITION', 'Unable to create transaction. The referenced position does not exist. Has it been deleted?');
|
|
295
|
+
const transactionCreateFailedNoPosition = new FailureType('TRANSACTION_CREATE_FAILED_NO_POSITION', 'Unable to create transaction. The referenced position does not exist. Has it been deleted?', false);
|
|
296
296
|
const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to process transaction, because the transaction date is out-of-sequence. In other words, it would occur before an existing transaction. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
|
|
297
297
|
const transactionCreateFailedInvalidDate = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_DATE', 'Unable to process transaction with given date.');
|
|
298
298
|
const transactionCreateFailedTypeInvalidForInstrument = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_INSTRUMENT', 'Unable to process transaction, {L|transactionType.description} transactions cannot be used with {L|instrumentType.description} positions.');
|
|
@@ -155,14 +155,30 @@ module.exports = (() => {
|
|
|
155
155
|
f.total = t.dividend.amount;
|
|
156
156
|
f.rate = t.dividend.rate;
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
let shares;
|
|
159
|
+
|
|
160
|
+
if (!t.dividend.rate.getIsZero()) {
|
|
161
|
+
shares = t.dividend.amount.divide(t.dividend.rate);
|
|
162
|
+
} else {
|
|
163
|
+
shares = '';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
f.shares = shares;
|
|
159
167
|
};
|
|
160
168
|
|
|
161
169
|
const distributionCashFormatter = (t, f) => {
|
|
162
170
|
f.total = t.dividend.amount;
|
|
163
171
|
f.rate = t.dividend.rate;
|
|
164
172
|
|
|
165
|
-
|
|
173
|
+
let shares;
|
|
174
|
+
|
|
175
|
+
if (!t.dividend.rate.getIsZero()) {
|
|
176
|
+
shares = t.dividend.amount.divide(t.dividend.rate);
|
|
177
|
+
} else {
|
|
178
|
+
shares = '';
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
f.shares = shares;
|
|
166
182
|
};
|
|
167
183
|
|
|
168
184
|
const dividendReinvestFormatter = (t, f) => {
|
|
@@ -199,12 +215,20 @@ module.exports = (() => {
|
|
|
199
215
|
}
|
|
200
216
|
|
|
201
217
|
if (t.dividend) {
|
|
218
|
+
let rate;
|
|
219
|
+
|
|
202
220
|
if (t.dividend.numerator && t.dividend.denominator) {
|
|
203
|
-
|
|
221
|
+
if (!t.dividend.denominator.getIsZero()) {
|
|
222
|
+
rate = t.dividend.numerator.divide(t.dividend.denominator);
|
|
223
|
+
} else {
|
|
224
|
+
rate = '';
|
|
225
|
+
}
|
|
204
226
|
} else if (t.dividend.rate) {
|
|
205
|
-
|
|
227
|
+
rate = t.dividend.rate;
|
|
206
228
|
}
|
|
207
229
|
|
|
230
|
+
f.rate = rate;
|
|
231
|
+
|
|
208
232
|
if (t.dividend.price) {
|
|
209
233
|
f.price = t.dividend.price;
|
|
210
234
|
}
|
|
@@ -221,12 +245,20 @@ module.exports = (() => {
|
|
|
221
245
|
}
|
|
222
246
|
|
|
223
247
|
if (t.dividend) {
|
|
248
|
+
let rate;
|
|
249
|
+
|
|
224
250
|
if (t.dividend.numerator && t.dividend.denominator) {
|
|
225
|
-
|
|
251
|
+
if (!t.dividend.denominator.getIsZero()) {
|
|
252
|
+
rate = t.dividend.numerator.divide(t.dividend.denominator);
|
|
253
|
+
} else {
|
|
254
|
+
rate = '';
|
|
255
|
+
}
|
|
226
256
|
} else if (t.dividend.rate) {
|
|
227
|
-
|
|
257
|
+
rate = t.dividend.rate;
|
|
228
258
|
}
|
|
229
259
|
|
|
260
|
+
f.rate = rate;
|
|
261
|
+
|
|
230
262
|
if (t.dividend.price) {
|
|
231
263
|
f.price = t.dividend.price;
|
|
232
264
|
}
|
|
@@ -251,7 +283,15 @@ module.exports = (() => {
|
|
|
251
283
|
const splitFormatter = (t, f) => {
|
|
252
284
|
f.boughtSold = t.quantity;
|
|
253
285
|
|
|
254
|
-
|
|
286
|
+
let rate;
|
|
287
|
+
|
|
288
|
+
if (!t.split.denominator.getIsZero()) {
|
|
289
|
+
rate = t.split.numerator.divide(t.split.denominator);
|
|
290
|
+
} else {
|
|
291
|
+
rate = '';
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
f.rate = rate;
|
|
255
295
|
|
|
256
296
|
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
257
297
|
};
|
|
@@ -264,7 +304,11 @@ module.exports = (() => {
|
|
|
264
304
|
} else if (t.snapshot.open.getIsZero()) {
|
|
265
305
|
rate = null;
|
|
266
306
|
} else {
|
|
267
|
-
|
|
307
|
+
if (!t.snapshot.open.getIsZero()) {
|
|
308
|
+
rate = t.valuation.value.divide(t.snapshot.open);
|
|
309
|
+
} else {
|
|
310
|
+
rate = '';
|
|
311
|
+
}
|
|
268
312
|
}
|
|
269
313
|
|
|
270
314
|
f.price = rate;
|
|
@@ -997,7 +997,7 @@ module.exports = (() => {
|
|
|
997
997
|
const format = group._dataFormat;
|
|
998
998
|
|
|
999
999
|
const numerator = actual.unrealized;
|
|
1000
|
-
const denominator = actual.basis;
|
|
1000
|
+
const denominator = actual.basis.absolute();
|
|
1001
1001
|
|
|
1002
1002
|
if (denominator.getIsZero()) {
|
|
1003
1003
|
actual.unrealizedPercent = Decimal.ZERO;
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -3565,7 +3565,7 @@ module.exports = (() => {
|
|
|
3565
3565
|
const format = group._dataFormat;
|
|
3566
3566
|
|
|
3567
3567
|
const numerator = actual.unrealized;
|
|
3568
|
-
const denominator = actual.basis;
|
|
3568
|
+
const denominator = actual.basis.absolute();
|
|
3569
3569
|
|
|
3570
3570
|
if (denominator.getIsZero()) {
|
|
3571
3571
|
actual.unrealizedPercent = Decimal.ZERO;
|
|
@@ -17027,8 +17027,8 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17027
17027
|
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
17028
17028
|
});
|
|
17029
17029
|
|
|
17030
|
-
it('should have four ranges (assuming the current year is
|
|
17031
|
-
expect(ranges.length).toEqual(
|
|
17030
|
+
it('should have four ranges (assuming the current year is 2020)', () => {
|
|
17031
|
+
expect(ranges.length).toEqual(5);
|
|
17032
17032
|
});
|
|
17033
17033
|
|
|
17034
17034
|
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
@@ -17050,6 +17050,11 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17050
17050
|
expect(ranges[3].start.format()).toEqual('2017-12-31');
|
|
17051
17051
|
expect(ranges[3].end.format()).toEqual('2018-12-31');
|
|
17052
17052
|
});
|
|
17053
|
+
|
|
17054
|
+
it('the fifth range should be from 12-31-2018 to 12-31-2019', () => {
|
|
17055
|
+
expect(ranges[4].start.format()).toEqual('2018-12-31');
|
|
17056
|
+
expect(ranges[4].end.format()).toEqual('2019-12-31');
|
|
17057
|
+
});
|
|
17053
17058
|
});
|
|
17054
17059
|
|
|
17055
17060
|
describe('and yearly position summary ranges are processed for a transaction set closes the same year', () => {
|
|
@@ -17409,7 +17414,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17409
17414
|
});
|
|
17410
17415
|
});
|
|
17411
17416
|
|
|
17412
|
-
describe('and a year-to-date position summary ranges are processed for a transaction set that opened this year and has not yet closed (assuming its
|
|
17417
|
+
describe('and a year-to-date position summary ranges are processed for a transaction set that opened this year and has not yet closed (assuming its 2020)', () => {
|
|
17413
17418
|
let ranges;
|
|
17414
17419
|
|
|
17415
17420
|
beforeEach(() => {
|
|
@@ -17430,26 +17435,26 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17430
17435
|
expect(ranges.length).toEqual(1);
|
|
17431
17436
|
});
|
|
17432
17437
|
|
|
17433
|
-
it('the first range should be from 12-31-
|
|
17434
|
-
expect(ranges[0].start.format()).toEqual('
|
|
17435
|
-
expect(ranges[0].end.format()).toEqual('
|
|
17438
|
+
it('the first range should be from 12-31-2019 to 12-31-2020', () => {
|
|
17439
|
+
expect(ranges[0].start.format()).toEqual('2019-12-31');
|
|
17440
|
+
expect(ranges[0].end.format()).toEqual('2020-12-31');
|
|
17436
17441
|
});
|
|
17437
17442
|
});
|
|
17438
17443
|
|
|
17439
|
-
describe('and a year-to-date position summary ranges are processed for a transaction set that that opened and closed in
|
|
17444
|
+
describe('and a year-to-date position summary ranges are processed for a transaction set that that opened and closed in 2020', () => {
|
|
17440
17445
|
let ranges;
|
|
17441
17446
|
|
|
17442
17447
|
beforeEach(() => {
|
|
17443
17448
|
const transactions = [
|
|
17444
17449
|
{
|
|
17445
|
-
date: new Day(
|
|
17450
|
+
date: new Day(2020, 1, 1),
|
|
17446
17451
|
snapshot: {
|
|
17447
17452
|
open: new Decimal(1)
|
|
17448
17453
|
},
|
|
17449
17454
|
type: TransactionType.BUY
|
|
17450
17455
|
},
|
|
17451
17456
|
{
|
|
17452
|
-
date: new Day(
|
|
17457
|
+
date: new Day(2020, 1, 2),
|
|
17453
17458
|
snapshot: {
|
|
17454
17459
|
open: new Decimal(0)
|
|
17455
17460
|
},
|
|
@@ -17464,9 +17469,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17464
17469
|
expect(ranges.length).toEqual(1);
|
|
17465
17470
|
});
|
|
17466
17471
|
|
|
17467
|
-
it('the first range should be from 12-31-
|
|
17468
|
-
expect(ranges[0].start.format()).toEqual('
|
|
17469
|
-
expect(ranges[0].end.format()).toEqual('
|
|
17472
|
+
it('the first range should be from 12-31-2019 to 12-31-2020', () => {
|
|
17473
|
+
expect(ranges[0].start.format()).toEqual('2019-12-31');
|
|
17474
|
+
expect(ranges[0].end.format()).toEqual('2020-12-31');
|
|
17470
17475
|
});
|
|
17471
17476
|
});
|
|
17472
17477
|
|
|
@@ -31,8 +31,8 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
31
31
|
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
it('should have four ranges (assuming the current year is
|
|
35
|
-
expect(ranges.length).toEqual(
|
|
34
|
+
it('should have four ranges (assuming the current year is 2020)', () => {
|
|
35
|
+
expect(ranges.length).toEqual(5);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
@@ -54,6 +54,11 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
54
54
|
expect(ranges[3].start.format()).toEqual('2017-12-31');
|
|
55
55
|
expect(ranges[3].end.format()).toEqual('2018-12-31');
|
|
56
56
|
});
|
|
57
|
+
|
|
58
|
+
it('the fifth range should be from 12-31-2018 to 12-31-2019', () => {
|
|
59
|
+
expect(ranges[4].start.format()).toEqual('2018-12-31');
|
|
60
|
+
expect(ranges[4].end.format()).toEqual('2019-12-31');
|
|
61
|
+
});
|
|
57
62
|
});
|
|
58
63
|
|
|
59
64
|
describe('and yearly position summary ranges are processed for a transaction set closes the same year', () => {
|
|
@@ -413,7 +418,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
413
418
|
});
|
|
414
419
|
});
|
|
415
420
|
|
|
416
|
-
describe('and a year-to-date position summary ranges are processed for a transaction set that opened this year and has not yet closed (assuming its
|
|
421
|
+
describe('and a year-to-date position summary ranges are processed for a transaction set that opened this year and has not yet closed (assuming its 2020)', () => {
|
|
417
422
|
let ranges;
|
|
418
423
|
|
|
419
424
|
beforeEach(() => {
|
|
@@ -434,26 +439,26 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
434
439
|
expect(ranges.length).toEqual(1);
|
|
435
440
|
});
|
|
436
441
|
|
|
437
|
-
it('the first range should be from 12-31-
|
|
438
|
-
expect(ranges[0].start.format()).toEqual('
|
|
439
|
-
expect(ranges[0].end.format()).toEqual('
|
|
442
|
+
it('the first range should be from 12-31-2019 to 12-31-2020', () => {
|
|
443
|
+
expect(ranges[0].start.format()).toEqual('2019-12-31');
|
|
444
|
+
expect(ranges[0].end.format()).toEqual('2020-12-31');
|
|
440
445
|
});
|
|
441
446
|
});
|
|
442
447
|
|
|
443
|
-
describe('and a year-to-date position summary ranges are processed for a transaction set that that opened and closed in
|
|
448
|
+
describe('and a year-to-date position summary ranges are processed for a transaction set that that opened and closed in 2020', () => {
|
|
444
449
|
let ranges;
|
|
445
450
|
|
|
446
451
|
beforeEach(() => {
|
|
447
452
|
const transactions = [
|
|
448
453
|
{
|
|
449
|
-
date: new Day(
|
|
454
|
+
date: new Day(2020, 1, 1),
|
|
450
455
|
snapshot: {
|
|
451
456
|
open: new Decimal(1)
|
|
452
457
|
},
|
|
453
458
|
type: TransactionType.BUY
|
|
454
459
|
},
|
|
455
460
|
{
|
|
456
|
-
date: new Day(
|
|
461
|
+
date: new Day(2020, 1, 2),
|
|
457
462
|
snapshot: {
|
|
458
463
|
open: new Decimal(0)
|
|
459
464
|
},
|
|
@@ -468,9 +473,9 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
468
473
|
expect(ranges.length).toEqual(1);
|
|
469
474
|
});
|
|
470
475
|
|
|
471
|
-
it('the first range should be from 12-31-
|
|
472
|
-
expect(ranges[0].start.format()).toEqual('
|
|
473
|
-
expect(ranges[0].end.format()).toEqual('
|
|
476
|
+
it('the first range should be from 12-31-2019 to 12-31-2020', () => {
|
|
477
|
+
expect(ranges[0].start.format()).toEqual('2019-12-31');
|
|
478
|
+
expect(ranges[0].end.format()).toEqual('2020-12-31');
|
|
474
479
|
});
|
|
475
480
|
});
|
|
476
481
|
|