@barchart/portfolio-api-common 1.0.17 → 1.0.21
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/PositionSummaryFrame.js +83 -9
- package/lib/serialization/PortfolioSchema.js +23 -3
- package/lib/serialization/PositionSchema.js +10 -0
- package/lib/serialization/TransactionSchema.js +280 -0
- package/package.json +2 -1
- package/test/SpecRunner.js +3515 -1
- package/test/specs/data/PositionSummaryFrameSpec.js +228 -0
|
@@ -0,0 +1,228 @@
|
|
|
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
|
+
|
|
6
|
+
describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
describe('and yearly position summary ranges are processed for a transaction set that does not close', () => {
|
|
10
|
+
let ranges;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
const transactions = [
|
|
14
|
+
{
|
|
15
|
+
date: new Day(2015, 10, 20)
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
date: new Day(2016, 11, 21),
|
|
19
|
+
snapshot: {
|
|
20
|
+
open: new Decimal(1)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should have three ranges (assuming the current year is 2018)', () => {
|
|
29
|
+
expect(ranges.length).toEqual(3);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
33
|
+
expect(ranges[0].start.format()).toEqual('2014-12-31');
|
|
34
|
+
expect(ranges[0].end.format()).toEqual('2015-12-31');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('the second range should be from 12-31-2015 to 12-31-2016', () => {
|
|
38
|
+
expect(ranges[1].start.format()).toEqual('2015-12-31');
|
|
39
|
+
expect(ranges[1].end.format()).toEqual('2016-12-31');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('the third range should be from 12-31-2016 to 12-31-2017', () => {
|
|
43
|
+
expect(ranges[2].start.format()).toEqual('2016-12-31');
|
|
44
|
+
expect(ranges[2].end.format()).toEqual('2017-12-31');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('and yearly position summary ranges are processed for a transaction set closes the same year', () => {
|
|
49
|
+
let ranges;
|
|
50
|
+
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
const transactions = [
|
|
53
|
+
{
|
|
54
|
+
date: new Day(2015, 10, 20)
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
date: new Day(2015, 11, 21),
|
|
58
|
+
snapshot: {
|
|
59
|
+
open: new Decimal(0)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should have one range', () => {
|
|
68
|
+
expect(ranges.length).toEqual(1);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
72
|
+
expect(ranges[0].start.format()).toEqual('2014-12-31');
|
|
73
|
+
expect(ranges[0].end.format()).toEqual('2015-12-31');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('and yearly position summary ranges are processed for a transaction set closes the next year', () => {
|
|
78
|
+
let ranges;
|
|
79
|
+
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
const transactions = [
|
|
82
|
+
{
|
|
83
|
+
date: new Day(2015, 10, 20)
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
date: new Day(2016, 11, 21),
|
|
87
|
+
snapshot: {
|
|
88
|
+
open: new Decimal(0)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should have two ranges', () => {
|
|
97
|
+
expect(ranges.length).toEqual(2);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
101
|
+
expect(ranges[0].start.format()).toEqual('2014-12-31');
|
|
102
|
+
expect(ranges[0].end.format()).toEqual('2015-12-31');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('the second range should be from 12-31-2015 to 12-31-2016', () => {
|
|
106
|
+
expect(ranges[1].start.format()).toEqual('2015-12-31');
|
|
107
|
+
expect(ranges[1].end.format()).toEqual('2016-12-31');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('and yearly position summary ranges are processed for a transaction set closes in the current next year -- assuming its 2018', () => {
|
|
112
|
+
let ranges;
|
|
113
|
+
|
|
114
|
+
beforeEach(() => {
|
|
115
|
+
const transactions = [
|
|
116
|
+
{
|
|
117
|
+
date: new Day(2015, 10, 20)
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
date: new Day(2017, 11, 21),
|
|
121
|
+
snapshot: {
|
|
122
|
+
open: new Decimal(0)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
ranges = PositionSummaryFrame.YEARLY.getRanges(transactions);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should have two ranges', () => {
|
|
131
|
+
expect(ranges.length).toEqual(3);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('the first range should be from 12-31-2014 to 12-31-2015', () => {
|
|
135
|
+
expect(ranges[0].start.format()).toEqual('2014-12-31');
|
|
136
|
+
expect(ranges[0].end.format()).toEqual('2015-12-31');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('the second range should be from 12-31-2015 to 12-31-2016', () => {
|
|
140
|
+
expect(ranges[1].start.format()).toEqual('2015-12-31');
|
|
141
|
+
expect(ranges[1].end.format()).toEqual('2016-12-31');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('the third range should be from 12-31-2015 to 12-31-2016', () => {
|
|
145
|
+
expect(ranges[2].start.format()).toEqual('2016-12-31');
|
|
146
|
+
expect(ranges[2].end.format()).toEqual('2017-12-31');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('and a year-to-date position summary ranges are processed for a transaction set that closed last year', () => {
|
|
151
|
+
let ranges;
|
|
152
|
+
|
|
153
|
+
beforeEach(() => {
|
|
154
|
+
const transactions = [
|
|
155
|
+
{
|
|
156
|
+
date: new Day(2017, 1, 1)
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
date: new Day(2017, 1, 2),
|
|
160
|
+
snapshot: {
|
|
161
|
+
open: new Decimal(0)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
ranges = PositionSummaryFrame.YTD.getRanges(transactions);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should have no ranges', () => {
|
|
170
|
+
expect(ranges.length).toEqual(0);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('and a year-to-date position summary ranges are processed for a transaction set that opened this year and has not yet closed', () => {
|
|
175
|
+
let ranges;
|
|
176
|
+
|
|
177
|
+
beforeEach(() => {
|
|
178
|
+
const transactions = [
|
|
179
|
+
{
|
|
180
|
+
date: new Day(2018, 1, 1),
|
|
181
|
+
snapshot: {
|
|
182
|
+
open: new Decimal(0)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
];
|
|
186
|
+
|
|
187
|
+
ranges = PositionSummaryFrame.YTD.getRanges(transactions);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should have one range', () => {
|
|
191
|
+
expect(ranges.length).toEqual(1);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('the first range should be from 12-31-2017 to 12-31-2015', () => {
|
|
195
|
+
expect(ranges[0].start.format()).toEqual('2017-12-31');
|
|
196
|
+
expect(ranges[0].end.format()).toEqual('2018-12-31');
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe('and a year-to-date position summary ranges are processed for a transaction set that opened and closed this year', () => {
|
|
201
|
+
let ranges;
|
|
202
|
+
|
|
203
|
+
beforeEach(() => {
|
|
204
|
+
const transactions = [
|
|
205
|
+
{
|
|
206
|
+
date: new Day(2018, 1, 1)
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
date: new Day(2018, 1, 2),
|
|
210
|
+
snapshot: {
|
|
211
|
+
open: new Decimal(0)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
ranges = PositionSummaryFrame.YTD.getRanges(transactions);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should have one range', () => {
|
|
220
|
+
expect(ranges.length).toEqual(1);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('the first range should be from 12-31-2017 to 12-31-2015', () => {
|
|
224
|
+
expect(ranges[0].start.format()).toEqual('2017-12-31');
|
|
225
|
+
expect(ranges[0].end.format()).toEqual('2018-12-31');
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
});
|