@barchart/portfolio-api-common 1.10.0 → 1.11.3
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/formatters/TransactionFormatter.js +54 -2
- package/lib/processing/PositionGroup.js +5 -5
- package/package.json +1 -1
- package/.jshintrc +0 -6
- package/.releases/1.10.0.md +0 -3
- package/.releases/1.5.0.md +0 -3
- package/.releases/1.5.1.md +0 -3
- package/.releases/1.5.2.md +0 -4
- package/.releases/1.6.0.md +0 -3
- package/.releases/1.7.0.md +0 -3
- package/.releases/1.8.0.md +0 -3
- package/.releases/1.9.0.md +0 -4
- package/.releases/1.9.1.md +0 -4
- package/buildspec.yml +0 -15
- package/gulpfile.js +0 -122
- package/test/SpecRunner.js +0 -18638
- package/test/SpecRunnner.html +0 -19
- package/test/specs/data/PositionSummaryFrameSpec.js +0 -629
- package/test/specs/data/TransactionValidatorSpec.js +0 -94
- package/test/specs/processing/PositionContainerSpec.js +0 -185
- package/test/specs/serialization/PositionSchemaSpec.js +0 -64
- package/test/specs/serialization/TransactionSchemaSpec.js +0 -65
package/test/SpecRunnner.html
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>Jasmine Spec Runner</title>
|
|
6
|
-
|
|
7
|
-
<link rel="shortcut icon" type="image/png" href="../node_modules/jasmine-core/images/jasmine_favicon.png">
|
|
8
|
-
<link rel="stylesheet" href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
|
|
9
|
-
|
|
10
|
-
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
|
|
11
|
-
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
|
|
12
|
-
<script src="../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
|
|
13
|
-
|
|
14
|
-
<script src="./SpecRunner.js"></script>
|
|
15
|
-
</head>
|
|
16
|
-
|
|
17
|
-
<body>
|
|
18
|
-
</body>
|
|
19
|
-
</html>
|
|
@@ -1,629 +0,0 @@
|
|
|
1
|
-
const Day = require('@barchart/common-js/lang/Day'),
|
|
2
|
-
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
3
|
-
|
|
4
|
-
const PositionSummaryFrame = require('./../../../lib/data/PositionSummaryFrame'),
|
|
5
|
-
TransactionType = require('./../../../lib/data/TransactionType');
|
|
6
|
-
|
|
7
|
-
describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
describe('and yearly position summary ranges are processed for a transaction set that does not close', () => {
|
|
11
|
-
let ranges;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
const transactions = [
|
|
15
|
-
{
|
|
16
|
-
date: new Day(2015, 10, 20),
|
|
17
|
-
snapshot: {
|
|
18
|
-
open: new Decimal(1)
|
|
19
|
-
},
|
|
20
|
-
type: TransactionType.BUY
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
date: new Day(2016, 11, 21),
|
|
24
|
-
snapshot: {
|
|
25
|
-
open: new Decimal(1)
|
|
26
|
-
},
|
|
27
|
-
type: TransactionType.BUY
|
|
28
|
-
}
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should have six ranges (assuming the current year is 2021)', () => {
|
|
35
|
-
expect(ranges.length).toEqual(6);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
39
|
-
expect(ranges[0].start.format()).toEqual('2014-12-31');
|
|
40
|
-
expect(ranges[0].end.format()).toEqual('2015-12-31');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('the second range should be from 12-31-2015 to 12-31-2016', () => {
|
|
44
|
-
expect(ranges[1].start.format()).toEqual('2015-12-31');
|
|
45
|
-
expect(ranges[1].end.format()).toEqual('2016-12-31');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('the third range should be from 12-31-2016 to 12-31-2017', () => {
|
|
49
|
-
expect(ranges[2].start.format()).toEqual('2016-12-31');
|
|
50
|
-
expect(ranges[2].end.format()).toEqual('2017-12-31');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('the fourth range should be from 12-31-2017 to 12-31-2018', () => {
|
|
54
|
-
expect(ranges[3].start.format()).toEqual('2017-12-31');
|
|
55
|
-
expect(ranges[3].end.format()).toEqual('2018-12-31');
|
|
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
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('and yearly position summary ranges are processed for a transaction set closes the same year', () => {
|
|
65
|
-
let ranges;
|
|
66
|
-
|
|
67
|
-
beforeEach(() => {
|
|
68
|
-
const transactions = [
|
|
69
|
-
{
|
|
70
|
-
date: new Day(2015, 10, 20),
|
|
71
|
-
snapshot: {
|
|
72
|
-
open: new Decimal(1)
|
|
73
|
-
},
|
|
74
|
-
type: TransactionType.BUY
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
date: new Day(2015, 11, 21),
|
|
78
|
-
snapshot: {
|
|
79
|
-
open: new Decimal(0)
|
|
80
|
-
},
|
|
81
|
-
type: TransactionType.SELL
|
|
82
|
-
}
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should have one range', () => {
|
|
89
|
-
expect(ranges.length).toEqual(1);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
93
|
-
expect(ranges[0].start.format()).toEqual('2014-12-31');
|
|
94
|
-
expect(ranges[0].end.format()).toEqual('2015-12-31');
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('and yearly position summary ranges are processed for a transaction set closes the next year', () => {
|
|
99
|
-
let ranges;
|
|
100
|
-
|
|
101
|
-
beforeEach(() => {
|
|
102
|
-
const transactions = [
|
|
103
|
-
{
|
|
104
|
-
date: new Day(2015, 10, 20),
|
|
105
|
-
snapshot: {
|
|
106
|
-
open: new Decimal(1)
|
|
107
|
-
},
|
|
108
|
-
type: TransactionType.BUY
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
date: new Day(2016, 11, 21),
|
|
112
|
-
snapshot: {
|
|
113
|
-
open: new Decimal(0)
|
|
114
|
-
},
|
|
115
|
-
type: TransactionType.SELL
|
|
116
|
-
}
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should have two ranges', () => {
|
|
123
|
-
expect(ranges.length).toEqual(2);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
127
|
-
expect(ranges[0].start.format()).toEqual('2014-12-31');
|
|
128
|
-
expect(ranges[0].end.format()).toEqual('2015-12-31');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('the second range should be from 12-31-2015 to 12-31-2016', () => {
|
|
132
|
-
expect(ranges[1].start.format()).toEqual('2015-12-31');
|
|
133
|
-
expect(ranges[1].end.format()).toEqual('2016-12-31');
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe('and yearly position summary ranges are processed for a transaction set that opens in 2015 and closes in 2017', () => {
|
|
138
|
-
let ranges;
|
|
139
|
-
|
|
140
|
-
beforeEach(() => {
|
|
141
|
-
const transactions = [
|
|
142
|
-
{
|
|
143
|
-
date: new Day(2015, 10, 20),
|
|
144
|
-
snapshot: {
|
|
145
|
-
open: new Decimal(1)
|
|
146
|
-
},
|
|
147
|
-
type: TransactionType.BUY
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
date: new Day(2017, 11, 21),
|
|
151
|
-
snapshot: {
|
|
152
|
-
open: new Decimal(0)
|
|
153
|
-
},
|
|
154
|
-
type: TransactionType.SELL
|
|
155
|
-
}
|
|
156
|
-
];
|
|
157
|
-
|
|
158
|
-
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should have three ranges', () => {
|
|
162
|
-
expect(ranges.length).toEqual(3);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
166
|
-
expect(ranges[0].start.format()).toEqual('2014-12-31');
|
|
167
|
-
expect(ranges[0].end.format()).toEqual('2015-12-31');
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('the second range should be from 12-31-2015 to 12-31-2016', () => {
|
|
171
|
-
expect(ranges[1].start.format()).toEqual('2015-12-31');
|
|
172
|
-
expect(ranges[1].end.format()).toEqual('2016-12-31');
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it('the third range should be from 12-31-2015 to 12-31-2016', () => {
|
|
176
|
-
expect(ranges[2].start.format()).toEqual('2016-12-31');
|
|
177
|
-
expect(ranges[2].end.format()).toEqual('2017-12-31');
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('and yearly position summary ranges are processed for a transaction set that opens in 2015 and closes in 2016, but has after-the-fact superfluous valuations in 2017 and 2018', () => {
|
|
182
|
-
let ranges;
|
|
183
|
-
|
|
184
|
-
beforeEach(() => {
|
|
185
|
-
const transactions = [
|
|
186
|
-
{
|
|
187
|
-
date: new Day(2015, 10, 20),
|
|
188
|
-
snapshot: {
|
|
189
|
-
open: new Decimal(1)
|
|
190
|
-
},
|
|
191
|
-
type: TransactionType.BUY
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
date: new Day(2016, 11, 21),
|
|
195
|
-
snapshot: {
|
|
196
|
-
open: new Decimal(0)
|
|
197
|
-
},
|
|
198
|
-
type: TransactionType.SELL
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
date: new Day(2017, 11, 21),
|
|
202
|
-
snapshot: {
|
|
203
|
-
open: new Decimal(0)
|
|
204
|
-
},
|
|
205
|
-
type: TransactionType.VALUATION
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
date: new Day(2017, 11, 21),
|
|
209
|
-
snapshot: {
|
|
210
|
-
open: new Decimal(0)
|
|
211
|
-
},
|
|
212
|
-
type: TransactionType.VALUATION
|
|
213
|
-
}
|
|
214
|
-
];
|
|
215
|
-
|
|
216
|
-
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('should have two ranges', () => {
|
|
220
|
-
expect(ranges.length).toEqual(2);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
224
|
-
expect(ranges[0].start.format()).toEqual('2014-12-31');
|
|
225
|
-
expect(ranges[0].end.format()).toEqual('2015-12-31');
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('the second range should be from 12-31-2015 to 12-31-2016', () => {
|
|
229
|
-
expect(ranges[1].start.format()).toEqual('2015-12-31');
|
|
230
|
-
expect(ranges[1].end.format()).toEqual('2016-12-31');
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
describe('and yearly position summary ranges are processed for a transaction set that opens in the current year', () => {
|
|
235
|
-
let ranges;
|
|
236
|
-
|
|
237
|
-
beforeEach(() => {
|
|
238
|
-
const transactions = [
|
|
239
|
-
{
|
|
240
|
-
date: Day.getToday(),
|
|
241
|
-
snapshot: {
|
|
242
|
-
open: new Decimal(1)
|
|
243
|
-
},
|
|
244
|
-
type: TransactionType.BUY
|
|
245
|
-
}
|
|
246
|
-
];
|
|
247
|
-
|
|
248
|
-
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it('should have zero ranges', () => {
|
|
252
|
-
expect(ranges.length).toEqual(0);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
describe('and monthly position summary ranges are processed for a transaction set that does not close', () => {
|
|
257
|
-
let ranges;
|
|
258
|
-
|
|
259
|
-
beforeEach(() => {
|
|
260
|
-
const transactions = [
|
|
261
|
-
{
|
|
262
|
-
date: new Day(2018, 12, 20),
|
|
263
|
-
snapshot: {
|
|
264
|
-
open: new Decimal(1)
|
|
265
|
-
},
|
|
266
|
-
type: TransactionType.BUY
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
date: new Day(2019, 2, 21),
|
|
270
|
-
snapshot: {
|
|
271
|
-
open: new Decimal(1)
|
|
272
|
-
},
|
|
273
|
-
type: TransactionType.BUY
|
|
274
|
-
}
|
|
275
|
-
];
|
|
276
|
-
|
|
277
|
-
ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it('should have at least two ranges', () => {
|
|
281
|
-
expect(ranges.length > 1).toEqual(true);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
it('the first range should be from 11-30-2018 to 12-31-2018', () => {
|
|
285
|
-
expect(ranges[0].start.format()).toEqual('2018-11-30');
|
|
286
|
-
expect(ranges[0].end.format()).toEqual('2018-12-31');
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it('the last range should be for the previous month', () => {
|
|
290
|
-
const today = Day.getToday();
|
|
291
|
-
|
|
292
|
-
expect(ranges[ranges.length - 1].start.format()).toEqual(today.subtractMonths(2).getEndOfMonth().format());
|
|
293
|
-
expect(ranges[ranges.length - 1].end.format()).toEqual(today.subtractMonths(1).getEndOfMonth().format());
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
describe('and monthly position summary ranges are processed for a transaction set closes the same month', () => {
|
|
298
|
-
let ranges;
|
|
299
|
-
|
|
300
|
-
beforeEach(() => {
|
|
301
|
-
const transactions = [
|
|
302
|
-
{
|
|
303
|
-
date: new Day(2018, 12, 1),
|
|
304
|
-
snapshot: {
|
|
305
|
-
open: new Decimal(1)
|
|
306
|
-
},
|
|
307
|
-
type: TransactionType.BUY
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
date: new Day(2018, 12, 31),
|
|
311
|
-
snapshot: {
|
|
312
|
-
open: new Decimal(0)
|
|
313
|
-
},
|
|
314
|
-
type: TransactionType.SELL
|
|
315
|
-
}
|
|
316
|
-
];
|
|
317
|
-
|
|
318
|
-
ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('should have one range', () => {
|
|
322
|
-
expect(ranges.length).toEqual(1);
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
it('the first range should be from 11-30-2018 to 12-31-2018', () => {
|
|
326
|
-
expect(ranges[0].start.format()).toEqual('2018-11-30');
|
|
327
|
-
expect(ranges[0].end.format()).toEqual('2018-12-31');
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
describe('and monthly position summary ranges are processed for a transaction set closes the next month', () => {
|
|
332
|
-
let ranges;
|
|
333
|
-
|
|
334
|
-
beforeEach(() => {
|
|
335
|
-
const transactions = [
|
|
336
|
-
{
|
|
337
|
-
date: new Day(2015, 10, 20),
|
|
338
|
-
snapshot: {
|
|
339
|
-
open: new Decimal(1)
|
|
340
|
-
},
|
|
341
|
-
type: TransactionType.BUY
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
date: new Day(2015, 11, 20),
|
|
345
|
-
snapshot: {
|
|
346
|
-
open: new Decimal(0)
|
|
347
|
-
},
|
|
348
|
-
type: TransactionType.SELL
|
|
349
|
-
}
|
|
350
|
-
];
|
|
351
|
-
|
|
352
|
-
ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
it('should have two ranges', () => {
|
|
356
|
-
expect(ranges.length).toEqual(2);
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it('the first range should be from 09-30-2015 to 10-31-2015', () => {
|
|
360
|
-
expect(ranges[0].start.format()).toEqual('2015-09-30');
|
|
361
|
-
expect(ranges[0].end.format()).toEqual('2015-10-31');
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it('the second range should be from 10-31-2015 to 11-30-2015', () => {
|
|
365
|
-
expect(ranges[1].start.format()).toEqual('2015-10-31');
|
|
366
|
-
expect(ranges[1].end.format()).toEqual('2015-11-30');
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
describe('and monthly position summary ranges are processed for a transaction set that opens in the current month', () => {
|
|
371
|
-
let ranges;
|
|
372
|
-
|
|
373
|
-
beforeEach(() => {
|
|
374
|
-
const transactions = [
|
|
375
|
-
{
|
|
376
|
-
date: Day.getToday(),
|
|
377
|
-
snapshot: {
|
|
378
|
-
open: new Decimal(1)
|
|
379
|
-
},
|
|
380
|
-
type: TransactionType.BUY
|
|
381
|
-
}
|
|
382
|
-
];
|
|
383
|
-
|
|
384
|
-
ranges = PositionSummaryFrame.MONTHLY.getRanges(transactions);
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it('should have zero ranges', () => {
|
|
388
|
-
expect(ranges.length).toEqual(0);
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
describe('and a year-to-date position summary ranges are processed for a transaction set that closed in 2017', () => {
|
|
393
|
-
let ranges;
|
|
394
|
-
|
|
395
|
-
beforeEach(() => {
|
|
396
|
-
const transactions = [
|
|
397
|
-
{
|
|
398
|
-
date: new Day(2017, 1, 1),
|
|
399
|
-
snapshot: {
|
|
400
|
-
open: new Decimal(1)
|
|
401
|
-
},
|
|
402
|
-
type: TransactionType.BUY
|
|
403
|
-
},
|
|
404
|
-
{
|
|
405
|
-
date: new Day(2017, 1, 2),
|
|
406
|
-
snapshot: {
|
|
407
|
-
open: new Decimal(0)
|
|
408
|
-
},
|
|
409
|
-
type: TransactionType.SELL
|
|
410
|
-
}
|
|
411
|
-
];
|
|
412
|
-
|
|
413
|
-
ranges = PositionSummaryFrame.YTD.getRanges(transactions);
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
it('should have no ranges', () => {
|
|
417
|
-
expect(ranges.length).toEqual(0);
|
|
418
|
-
});
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
describe('and a year-to-date position summary ranges are processed for a transaction set that opened last year and has not yet closed (assuming its 2021)', () => {
|
|
422
|
-
let ranges;
|
|
423
|
-
|
|
424
|
-
beforeEach(() => {
|
|
425
|
-
const transactions = [
|
|
426
|
-
{
|
|
427
|
-
date: new Day(2019, 1, 1),
|
|
428
|
-
snapshot: {
|
|
429
|
-
open: new Decimal(100)
|
|
430
|
-
},
|
|
431
|
-
type: TransactionType.BUY
|
|
432
|
-
}
|
|
433
|
-
];
|
|
434
|
-
|
|
435
|
-
ranges = PositionSummaryFrame.YTD.getRanges(transactions);
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
it('should have one range', () => {
|
|
439
|
-
expect(ranges.length).toEqual(1);
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
it('the first range should be from 12-31-2020 to 12-31-2021', () => {
|
|
443
|
-
expect(ranges[0].start.format()).toEqual('2020-12-31');
|
|
444
|
-
expect(ranges[0].end.format()).toEqual('2021-12-31');
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
describe('and a year-to-date position summary ranges are processed for a transaction set that that opened and closed in 2020', () => {
|
|
449
|
-
let ranges;
|
|
450
|
-
|
|
451
|
-
beforeEach(() => {
|
|
452
|
-
const transactions = [
|
|
453
|
-
{
|
|
454
|
-
date: new Day(2021, 1, 1),
|
|
455
|
-
snapshot: {
|
|
456
|
-
open: new Decimal(1)
|
|
457
|
-
},
|
|
458
|
-
type: TransactionType.BUY
|
|
459
|
-
},
|
|
460
|
-
{
|
|
461
|
-
date: new Day(2021, 1, 2),
|
|
462
|
-
snapshot: {
|
|
463
|
-
open: new Decimal(0)
|
|
464
|
-
},
|
|
465
|
-
type: TransactionType.SELL
|
|
466
|
-
}
|
|
467
|
-
];
|
|
468
|
-
|
|
469
|
-
ranges = PositionSummaryFrame.YTD.getRanges(transactions);
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
it('should have one range', () => {
|
|
473
|
-
expect(ranges.length).toEqual(1);
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
it('the first range should be from 12-31-2020 to 12-31-2021', () => {
|
|
477
|
-
expect(ranges[0].start.format()).toEqual('2020-12-31');
|
|
478
|
-
expect(ranges[0].end.format()).toEqual('2021-12-31');
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
describe('and getting the start date for yearly frames', () => {
|
|
483
|
-
describe('for one year ago', () => {
|
|
484
|
-
let start;
|
|
485
|
-
let today;
|
|
486
|
-
|
|
487
|
-
beforeEach(() => {
|
|
488
|
-
start = PositionSummaryFrame.YEARLY.getStartDate(1);
|
|
489
|
-
today = new Date();
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
it('should be in December', () => {
|
|
493
|
-
expect(start.month).toEqual(12);
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
it('should be on the 31st', () => {
|
|
497
|
-
expect(start.day).toEqual(31);
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
it('should be two years ago', () => {
|
|
501
|
-
expect(start.year).toEqual(today.getFullYear() - 2);
|
|
502
|
-
});
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
describe('for two years ago', () => {
|
|
506
|
-
let start;
|
|
507
|
-
let today;
|
|
508
|
-
|
|
509
|
-
beforeEach(() => {
|
|
510
|
-
start = PositionSummaryFrame.YEARLY.getStartDate(2);
|
|
511
|
-
today = new Date();
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
it('should be in December', () => {
|
|
515
|
-
expect(start.month).toEqual(12);
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
it('should be on the 31st', () => {
|
|
519
|
-
expect(start.day).toEqual(31);
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
it('should be three years ago', () => {
|
|
523
|
-
expect(start.year).toEqual(today.getFullYear() - 3);
|
|
524
|
-
});
|
|
525
|
-
});
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
describe('and recent ranges are calculated', () => {
|
|
529
|
-
let todayYear;
|
|
530
|
-
let todayMonth;
|
|
531
|
-
let todayDay;
|
|
532
|
-
|
|
533
|
-
beforeEach(() => {
|
|
534
|
-
const today = new Date();
|
|
535
|
-
|
|
536
|
-
todayYear = today.getFullYear();
|
|
537
|
-
todayMonth = today.getMonth() + 1;
|
|
538
|
-
todayDay = today.getDate();
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
describe('the most recent YTD frame', () => {
|
|
542
|
-
let ranges;
|
|
543
|
-
|
|
544
|
-
beforeEach(() => {
|
|
545
|
-
ranges = PositionSummaryFrame.YTD.getRecentRanges(0);
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
it('should contain one range', () => {
|
|
549
|
-
expect(ranges.length).toEqual(1);
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
it('the range should begin at the end of last year', () => {
|
|
553
|
-
expect(ranges[0].start.format()).toEqual(`${todayYear - 1}-12-31`);
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
it('the range should end at the end of this year', () => {
|
|
557
|
-
expect(ranges[0].end.format()).toEqual(`${todayYear}-12-31`);
|
|
558
|
-
});
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
describe('the three most recent YEARLY frames', () => {
|
|
562
|
-
let ranges;
|
|
563
|
-
|
|
564
|
-
beforeEach(() => {
|
|
565
|
-
ranges = PositionSummaryFrame.YEARLY.getRecentRanges(2);
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
it('should contain three range', () => {
|
|
569
|
-
expect(ranges.length).toEqual(3);
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
it('the first range should begin at the end of this year (minus three years)', () => {
|
|
573
|
-
expect(ranges[0].start.format()).toEqual(`${todayYear - 4}-12-31`);
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
it('the first range should end at the end of this year (minus two years)', () => {
|
|
577
|
-
expect(ranges[0].end.format()).toEqual(`${todayYear - 3}-12-31`);
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
it('the second range should begin at the end of this year (minus two years)', () => {
|
|
581
|
-
expect(ranges[1].start.format()).toEqual(`${todayYear - 3}-12-31`);
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
it('the second range should end at the end of this year (minus one years)', () => {
|
|
585
|
-
expect(ranges[1].end.format()).toEqual(`${todayYear - 2}-12-31`);
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
it('the third range should begin at the end of the year before last', () => {
|
|
589
|
-
expect(ranges[2].start.format()).toEqual(`${todayYear - 2}-12-31`);
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
it('the third range should end at the end of last year', () => {
|
|
593
|
-
expect(ranges[2].end.format()).toEqual(`${todayYear - 1}-12-31`);
|
|
594
|
-
});
|
|
595
|
-
});
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
describe('and prior ranges are calculated', () => {
|
|
599
|
-
describe('for YEARLY ranges', () => {
|
|
600
|
-
describe('from 2017-10-10, including one previous ranges', () => {
|
|
601
|
-
let ranges;
|
|
602
|
-
|
|
603
|
-
beforeEach(() => {
|
|
604
|
-
ranges = PositionSummaryFrame.YEARLY.getPriorRanges(new Day(2015, 4, 20), 1);
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
it('should return two ranges', () => {
|
|
608
|
-
expect(ranges.length).toEqual(2);
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
it('the first range should begin on 2013-12-31', () => {
|
|
612
|
-
expect(ranges[0].start.getIsEqual(new Day(2013, 12, 31))).toEqual(true);
|
|
613
|
-
});
|
|
614
|
-
|
|
615
|
-
it('the first range should end on 2014-12-31', () => {
|
|
616
|
-
expect(ranges[0].end.getIsEqual(new Day(2014, 12, 31))).toEqual(true);
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
it('the second range should begin on 2014-12-31', () => {
|
|
620
|
-
expect(ranges[1].start.getIsEqual(new Day(2014, 12, 31))).toEqual(true);
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
it('the second range should end on 2015-12-31', () => {
|
|
624
|
-
expect(ranges[1].end.getIsEqual(new Day(2015, 12, 31))).toEqual(true);
|
|
625
|
-
});
|
|
626
|
-
});
|
|
627
|
-
});
|
|
628
|
-
});
|
|
629
|
-
});
|