@barchart/portfolio-api-common 1.0.90 → 1.0.94
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.
|
@@ -58,6 +58,7 @@ module.exports = (() => {
|
|
|
58
58
|
this._dataFormat.total = null;
|
|
59
59
|
this._dataFormat.totalNegative = false;
|
|
60
60
|
this._dataFormat.summaryTotalCurrent = null;
|
|
61
|
+
this._dataActual.summaryTotalCurrentNegative = false;
|
|
61
62
|
this._dataFormat.summaryTotalPrevious = null;
|
|
62
63
|
|
|
63
64
|
this._dataFormat.unrealizedTodayNegative = false;
|
|
@@ -234,19 +235,22 @@ module.exports = (() => {
|
|
|
234
235
|
updates = items.reduce((updates, item) => {
|
|
235
236
|
updates.market = updates.market.add(item.data.market);
|
|
236
237
|
updates.unrealizedToday = updates.unrealizedToday.add(item.data.unrealizedToday);
|
|
238
|
+
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(item.data.summaryTotalCurrent);
|
|
237
239
|
|
|
238
240
|
return updates;
|
|
239
241
|
}, {
|
|
240
242
|
market: Decimal.ZERO,
|
|
241
243
|
marketDirection: unchanged,
|
|
242
|
-
unrealizedToday: Decimal.ZERO
|
|
244
|
+
unrealizedToday: Decimal.ZERO,
|
|
245
|
+
summaryTotalCurrent: Decimal.ZERO
|
|
243
246
|
|
|
244
247
|
});
|
|
245
248
|
} else {
|
|
246
249
|
updates = {
|
|
247
250
|
market: actual.market.add(item.data.marketChange),
|
|
248
251
|
marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
|
|
249
|
-
unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange)
|
|
252
|
+
unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange),
|
|
253
|
+
summaryTotalCurrent: actual.summaryTotalCurrent.add(item.data.summaryTotalCurrentChange)
|
|
250
254
|
};
|
|
251
255
|
}
|
|
252
256
|
|
|
@@ -264,6 +268,7 @@ module.exports = (() => {
|
|
|
264
268
|
|
|
265
269
|
actual.market = updates.market;
|
|
266
270
|
actual.unrealizedToday = updates.unrealizedToday;
|
|
271
|
+
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
267
272
|
actual.total = updates.unrealizedToday.add(actual.realized).add(actual.income);
|
|
268
273
|
|
|
269
274
|
format.market = formatCurrency(actual.market, currency);
|
|
@@ -275,6 +280,10 @@ module.exports = (() => {
|
|
|
275
280
|
|
|
276
281
|
format.unrealizedToday = formatCurrency(actual.unrealizedToday, currency);
|
|
277
282
|
format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
|
|
283
|
+
|
|
284
|
+
format.summaryTotalCurrent = formatCurrency(actual.summaryTotalCurrent, currency);
|
|
285
|
+
format.summaryTotalCurrentNegative = actual.summaryTotalCurrent.getIsNegative();
|
|
286
|
+
|
|
278
287
|
format.total = formatCurrency(actual.total, currency);
|
|
279
288
|
format.totalNegative = actual.total.getIsNegative();
|
|
280
289
|
|
|
@@ -37,6 +37,8 @@ module.exports = (() => {
|
|
|
37
37
|
this._data.income = null;
|
|
38
38
|
|
|
39
39
|
this._data.summaryTotalCurrent = null;
|
|
40
|
+
this._data.summaryTotalCurrentChange = null;
|
|
41
|
+
|
|
40
42
|
this._data.summaryTotalPrevious = null;
|
|
41
43
|
|
|
42
44
|
this._excluded = false;
|
|
@@ -178,6 +180,28 @@ module.exports = (() => {
|
|
|
178
180
|
|
|
179
181
|
data.unrealizedToday = unrealizedToday;
|
|
180
182
|
data.unrealizedTodayChange = unrealizedTodayChange;
|
|
183
|
+
|
|
184
|
+
const summary = item.currentSummary;
|
|
185
|
+
|
|
186
|
+
if (summary && price) {
|
|
187
|
+
const period = summary.period;
|
|
188
|
+
|
|
189
|
+
let unrealizedCurrent = summary.end.open.multiply(price).add(summary.end.basis);
|
|
190
|
+
|
|
191
|
+
let summaryTotalCurrent = period.realized.add(period.income).add(unrealizedCurrent);
|
|
192
|
+
let summaryTotalCurrentChange;
|
|
193
|
+
|
|
194
|
+
if (data.summaryTotalCurrent !== null) {
|
|
195
|
+
summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
|
|
196
|
+
} else {
|
|
197
|
+
summaryTotalCurrentChange = Decimal.ZERO;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
data.summaryTotalCurrent = summaryTotalCurrent;
|
|
201
|
+
data.summaryTotalCurrentChange = summaryTotalCurrentChange;
|
|
202
|
+
} else {
|
|
203
|
+
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
204
|
+
}
|
|
181
205
|
}
|
|
182
206
|
|
|
183
207
|
function calculateSummaryTotal(summary) {
|
|
@@ -186,7 +210,7 @@ module.exports = (() => {
|
|
|
186
210
|
if (summary) {
|
|
187
211
|
const period = summary.period;
|
|
188
212
|
|
|
189
|
-
returnRef = period.realized.add(period.
|
|
213
|
+
returnRef = period.realized.add(period.income).add(period.unrealized);
|
|
190
214
|
} else {
|
|
191
215
|
returnRef = Decimal.ZERO;
|
|
192
216
|
}
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -160,8 +160,6 @@ module.exports = (() => {
|
|
|
160
160
|
* @return {String}
|
|
161
161
|
*/
|
|
162
162
|
describeRange(range) {
|
|
163
|
-
console.log('range: ', range);
|
|
164
|
-
|
|
165
163
|
return this._descriptionCalculator(range.start, range.end);
|
|
166
164
|
}
|
|
167
165
|
|
|
@@ -1040,6 +1038,7 @@ module.exports = (() => {
|
|
|
1040
1038
|
this._dataFormat.total = null;
|
|
1041
1039
|
this._dataFormat.totalNegative = false;
|
|
1042
1040
|
this._dataFormat.summaryTotalCurrent = null;
|
|
1041
|
+
this._dataActual.summaryTotalCurrentNegative = false;
|
|
1043
1042
|
this._dataFormat.summaryTotalPrevious = null;
|
|
1044
1043
|
|
|
1045
1044
|
this._dataFormat.unrealizedTodayNegative = false;
|
|
@@ -1216,19 +1215,22 @@ module.exports = (() => {
|
|
|
1216
1215
|
updates = items.reduce((updates, item) => {
|
|
1217
1216
|
updates.market = updates.market.add(item.data.market);
|
|
1218
1217
|
updates.unrealizedToday = updates.unrealizedToday.add(item.data.unrealizedToday);
|
|
1218
|
+
updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(item.data.summaryTotalCurrent);
|
|
1219
1219
|
|
|
1220
1220
|
return updates;
|
|
1221
1221
|
}, {
|
|
1222
1222
|
market: Decimal.ZERO,
|
|
1223
1223
|
marketDirection: unchanged,
|
|
1224
|
-
unrealizedToday: Decimal.ZERO
|
|
1224
|
+
unrealizedToday: Decimal.ZERO,
|
|
1225
|
+
summaryTotalCurrent: Decimal.ZERO
|
|
1225
1226
|
|
|
1226
1227
|
});
|
|
1227
1228
|
} else {
|
|
1228
1229
|
updates = {
|
|
1229
1230
|
market: actual.market.add(item.data.marketChange),
|
|
1230
1231
|
marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
|
|
1231
|
-
unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange)
|
|
1232
|
+
unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange),
|
|
1233
|
+
summaryTotalCurrent: actual.summaryTotalCurrent.add(item.data.summaryTotalCurrentChange)
|
|
1232
1234
|
};
|
|
1233
1235
|
}
|
|
1234
1236
|
|
|
@@ -1246,6 +1248,7 @@ module.exports = (() => {
|
|
|
1246
1248
|
|
|
1247
1249
|
actual.market = updates.market;
|
|
1248
1250
|
actual.unrealizedToday = updates.unrealizedToday;
|
|
1251
|
+
actual.summaryTotalCurrent = updates.summaryTotalCurrent;
|
|
1249
1252
|
actual.total = updates.unrealizedToday.add(actual.realized).add(actual.income);
|
|
1250
1253
|
|
|
1251
1254
|
format.market = formatCurrency(actual.market, currency);
|
|
@@ -1257,6 +1260,10 @@ module.exports = (() => {
|
|
|
1257
1260
|
|
|
1258
1261
|
format.unrealizedToday = formatCurrency(actual.unrealizedToday, currency);
|
|
1259
1262
|
format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
|
|
1263
|
+
|
|
1264
|
+
format.summaryTotalCurrent = formatCurrency(actual.summaryTotalCurrent, currency);
|
|
1265
|
+
format.summaryTotalCurrentNegative = actual.summaryTotalCurrent.getIsNegative();
|
|
1266
|
+
|
|
1260
1267
|
format.total = formatCurrency(actual.total, currency);
|
|
1261
1268
|
format.totalNegative = actual.total.getIsNegative();
|
|
1262
1269
|
|
|
@@ -1391,6 +1398,8 @@ module.exports = (() => {
|
|
|
1391
1398
|
this._data.income = null;
|
|
1392
1399
|
|
|
1393
1400
|
this._data.summaryTotalCurrent = null;
|
|
1401
|
+
this._data.summaryTotalCurrentChange = null;
|
|
1402
|
+
|
|
1394
1403
|
this._data.summaryTotalPrevious = null;
|
|
1395
1404
|
|
|
1396
1405
|
this._excluded = false;
|
|
@@ -1532,6 +1541,28 @@ module.exports = (() => {
|
|
|
1532
1541
|
|
|
1533
1542
|
data.unrealizedToday = unrealizedToday;
|
|
1534
1543
|
data.unrealizedTodayChange = unrealizedTodayChange;
|
|
1544
|
+
|
|
1545
|
+
const summary = item.currentSummary;
|
|
1546
|
+
|
|
1547
|
+
if (summary && price) {
|
|
1548
|
+
const period = summary.period;
|
|
1549
|
+
|
|
1550
|
+
let unrealizedCurrent = summary.end.open.multiply(price).add(summary.end.basis);
|
|
1551
|
+
|
|
1552
|
+
let summaryTotalCurrent = period.realized.add(period.income).add(unrealizedCurrent);
|
|
1553
|
+
let summaryTotalCurrentChange;
|
|
1554
|
+
|
|
1555
|
+
if (data.summaryTotalCurrent !== null) {
|
|
1556
|
+
summaryTotalCurrentChange = summaryTotalCurrent.subtract(data.summaryTotalCurrent);
|
|
1557
|
+
} else {
|
|
1558
|
+
summaryTotalCurrentChange = Decimal.ZERO;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
data.summaryTotalCurrent = summaryTotalCurrent;
|
|
1562
|
+
data.summaryTotalCurrentChange = summaryTotalCurrentChange;
|
|
1563
|
+
} else {
|
|
1564
|
+
data.summaryTotalCurrentChange = Decimal.ZERO;
|
|
1565
|
+
}
|
|
1535
1566
|
}
|
|
1536
1567
|
|
|
1537
1568
|
function calculateSummaryTotal(summary) {
|
|
@@ -1540,7 +1571,7 @@ module.exports = (() => {
|
|
|
1540
1571
|
if (summary) {
|
|
1541
1572
|
const period = summary.period;
|
|
1542
1573
|
|
|
1543
|
-
returnRef = period.realized.add(period.
|
|
1574
|
+
returnRef = period.realized.add(period.income).add(period.unrealized);
|
|
1544
1575
|
} else {
|
|
1545
1576
|
returnRef = Decimal.ZERO;
|
|
1546
1577
|
}
|
|
@@ -3191,9 +3222,9 @@ module.exports = function () {
|
|
|
3191
3222
|
assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
|
|
3192
3223
|
assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
|
|
3193
3224
|
|
|
3194
|
-
if (a._big.gt(b)) {
|
|
3225
|
+
if (a._big.gt(b._big)) {
|
|
3195
3226
|
return 1;
|
|
3196
|
-
} else if (a._big.lt(b)) {
|
|
3227
|
+
} else if (a._big.lt(b._big)) {
|
|
3197
3228
|
return -1;
|
|
3198
3229
|
} else {
|
|
3199
3230
|
return 0;
|