@barchart/portfolio-api-common 1.11.0 → 1.11.4

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.
@@ -159,11 +159,27 @@ module.exports = (() => {
159
159
  let shares;
160
160
 
161
161
  if (!t.dividend.rate.getIsZero()) {
162
- shares = t.dividend.amount.divide(t.dividend.rate);
162
+ if (t.dividend.native) {
163
+ shares = t.dividend.native.divide(t.dividend.rate);
164
+ } else {
165
+ shares = t.dividend.amount.divide(t.dividend.rate);
166
+ }
163
167
  } else {
164
168
  shares = '';
165
169
  }
166
170
 
171
+ if (shares) {
172
+ const rounded = shares.round(0);
173
+
174
+ if (rounded.subtract(shares).absolute().getIsLessThan(0.01)) {
175
+ shares = rounded;
176
+ } else {
177
+ shares = shares.round(2);
178
+ }
179
+ }
180
+
181
+ f.shares = shares;
182
+
167
183
  if (t.dividend.currency) {
168
184
  f.currency = t.dividend.currency;
169
185
  }
@@ -171,8 +187,6 @@ module.exports = (() => {
171
187
  if (t.dividend.native) {
172
188
  f.native = t.dividend.native;
173
189
  }
174
-
175
- f.shares = shares;
176
190
  };
177
191
 
178
192
  const distributionCashFormatter = (t, f) => {
@@ -182,11 +196,27 @@ module.exports = (() => {
182
196
  let shares;
183
197
 
184
198
  if (!t.dividend.rate.getIsZero()) {
185
- shares = t.dividend.amount.divide(t.dividend.rate);
199
+ if (t.dividend.native) {
200
+ shares = t.dividend.native.divide(t.dividend.rate);
201
+ } else {
202
+ shares = t.dividend.amount.divide(t.dividend.rate);
203
+ }
186
204
  } else {
187
205
  shares = '';
188
206
  }
189
207
 
208
+ if (shares) {
209
+ const rounded = shares.round(0);
210
+
211
+ if (rounded.subtract(shares).absolute().getIsLessThan(0.01)) {
212
+ shares = rounded;
213
+ } else {
214
+ shares = shares.round(2);
215
+ }
216
+ }
217
+
218
+ f.shares = shares;
219
+
190
220
  if (t.dividend.currency) {
191
221
  f.currency = t.dividend.currency;
192
222
  }
@@ -194,8 +224,6 @@ module.exports = (() => {
194
224
  if (t.dividend.native) {
195
225
  f.native = t.dividend.native;
196
226
  }
197
-
198
- f.shares = shares;
199
227
  };
200
228
 
201
229
  const dividendReinvestFormatter = (t, f) => {
@@ -892,7 +892,7 @@ module.exports = (() => {
892
892
  let marketChange = updates.market.subtract(actual.marketPrevious);
893
893
  let marketChangePercent;
894
894
 
895
- if (actual.marketPrevious.getIsZero()) {
895
+ if (actual.marketPrevious.getIsApproximate(Decimal.ZERO, 4)) {
896
896
  if (marketChange.getIsPositive()) {
897
897
  marketChangePercent = Decimal.ONE;
898
898
  } else if (marketChange.getIsNegative()) {
@@ -950,7 +950,7 @@ module.exports = (() => {
950
950
  if (parent && !excluded) {
951
951
  const parentData = parent._dataActual;
952
952
 
953
- if (parentData.marketAbsolute !== null && !parentData.marketAbsolute.getIsZero()) {
953
+ if (parentData.marketAbsolute !== null && !parentData.marketAbsolute.getIsApproximate(Decimal.ZERO, 4)) {
954
954
  let numerator;
955
955
 
956
956
  if (group.currency !== parent.currency) {
@@ -992,7 +992,7 @@ module.exports = (() => {
992
992
  const numerator = actual.realized;
993
993
  const denominator = totalBasis.subtract(openBasis);
994
994
 
995
- if (denominator.getIsZero()) {
995
+ if (denominator.getIsApproximate(Decimal.ZERO, 4)) {
996
996
  actual.realizedPercent = Decimal.ZERO;
997
997
  } else {
998
998
  actual.realizedPercent = numerator.divide(denominator);
@@ -1008,7 +1008,7 @@ module.exports = (() => {
1008
1008
  const numerator = actual.unrealized;
1009
1009
  const denominator = actual.basis.absolute();
1010
1010
 
1011
- if (denominator.getIsZero()) {
1011
+ if (denominator.getIsApproximate(Decimal.ZERO, 4)) {
1012
1012
  actual.unrealizedPercent = Decimal.ZERO;
1013
1013
  } else {
1014
1014
  actual.unrealizedPercent = numerator.divide(denominator);
@@ -1018,7 +1018,7 @@ module.exports = (() => {
1018
1018
  }
1019
1019
 
1020
1020
  function calculateGainPercent(gain, basis) {
1021
- return basis.getIsZero() ? Decimal.ZERO : gain.divide(basis);
1021
+ return basis.getIsApproximate(Decimal.ZERO, 4) ? Decimal.ZERO : gain.divide(basis);
1022
1022
  }
1023
1023
 
1024
1024
  const unchanged = { up: false, down: false };
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.11.0",
3
+ "version": "1.11.4",
4
4
  "description": "Common code used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
7
7
  "email": "bryan.ingle@barchart.com",
8
8
  "url": "http://www.barchart.com"
9
9
  },
10
+ "homepage": "https://github.com/barchart/portfolio-api-common#readme",
10
11
  "scripts": {},
11
12
  "dependencies": {
12
- "@barchart/common-js": "^3.5.1",
13
+ "@barchart/common-js": "^4.9.0",
13
14
  "uuid": "^3.4.0"
14
15
  },
15
16
  "devDependencies": {
package/.jshintrc DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "esversion": 9,
3
- "validthis": true,
4
- "-W018": true,
5
- "-W093": true
6
- }
@@ -1,3 +0,0 @@
1
- **New Features**
2
-
3
- * Added a new `PortfolioFailureType` for negative quantity.
@@ -1,3 +0,0 @@
1
- **New Features**
2
-
3
- * Added `native` and `currency` fields for dividends and distributions which paid in alternate currency (from underlying stock or fund).
@@ -1,3 +0,0 @@
1
- **New Features**
2
-
3
- * Added new ```Schema``` for results of a query by symbol.
@@ -1,3 +0,0 @@
1
- **Configuration Changes**
2
-
3
- * The failure message for corrupt corporate actions (e.g. two instruments with same symbol) was updated to indicate an expected time to correction (of 24 to 48 hours).
@@ -1,4 +0,0 @@
1
- **Technical Enhancements**
2
-
3
- * Added a `transaction` field into `basicFormatter` function for the `TransactionFormatter` class.
4
- * Changed the way to add and remove a portfolio in `PositionContainer` to support reactive changes.
@@ -1,3 +0,0 @@
1
- **New Features**
2
-
3
- * Added a new `PortfolioFailureType` for attempting to edit a transaction's type.
@@ -1,3 +0,0 @@
1
- **New Features**
2
-
3
- * Added a new `PortfolioFailureType` for attempting to reinvest a dividend when the position is short.
@@ -1,3 +0,0 @@
1
- **New Features**
2
-
3
- * Added a new `PortfolioFailureType` for attempts to switch to dividend reinvestment when the position is short.
@@ -1,4 +0,0 @@
1
- **New Features**
2
-
3
- * Added `close` field to the `Sell` transaction schema.
4
- * Added `close` field to the `Buy Short` transaction schema.
@@ -1,4 +0,0 @@
1
- **Bug Fixes**
2
-
3
- * Made `quantity` field optional for the `Sell` transaction schema.
4
- * Made `quantity` field optional for the `Buy Short` transaction schema.
package/buildspec.yml DELETED
@@ -1,15 +0,0 @@
1
- version: 0.2
2
-
3
- phases:
4
- install:
5
- runtime-versions:
6
- nodejs: 12.x
7
-
8
- pre_build:
9
- commands:
10
- - npm install
11
-
12
- build:
13
- commands:
14
- - ./node_modules/.bin/gulp lint
15
- - ./node_modules/.bin/gulp test
package/gulpfile.js DELETED
@@ -1,122 +0,0 @@
1
- const gulp = require('gulp');
2
-
3
- const fs = require('fs');
4
-
5
- const browserify = require('browserify'),
6
- buffer = require('vinyl-buffer'),
7
- exec = require('child_process').exec,
8
- git = require('gulp-git'),
9
- gitStatus = require('git-get-status'),
10
- glob = require('glob'),
11
- jasmine = require('gulp-jasmine'),
12
- jshint = require('gulp-jshint'),
13
- prompt = require('gulp-prompt'),
14
- source = require('vinyl-source-stream');
15
-
16
- function getVersionFromPackage() {
17
- return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
18
- }
19
-
20
- gulp.task('ensure-clean-working-directory', (cb) => {
21
- gitStatus((err, status) => {
22
- if (err, !status.clean) {
23
- throw new Error('Unable to proceed, your working directory is not clean.');
24
- }
25
-
26
- cb();
27
- });
28
- });
29
-
30
- gulp.task('bump-choice', (cb) => {
31
- const processor = prompt.prompt({
32
- type: 'list',
33
- name: 'bump',
34
- message: 'What type of bump would you like to do?',
35
- choices: ['patch', 'minor', 'major'],
36
- }, (res) => {
37
- global.bump = res.bump;
38
-
39
- return cb();
40
- });
41
-
42
- return gulp.src(['./package.json']).pipe(processor);
43
- });
44
-
45
- gulp.task('bump-version', (cb) => {
46
- exec(`npm version ${global.bump || 'patch'} --no-git-tag-version`, {
47
- cwd: './'
48
- }, (error) => {
49
- if (error) {
50
- cb(error);
51
- }
52
-
53
- cb();
54
- });
55
- });
56
-
57
- gulp.task('commit-changes', () => {
58
- return gulp.src([ './', './test/', './package.json' ])
59
- .pipe(git.add())
60
- .pipe(git.commit('Release. Bump version number'));
61
- });
62
-
63
- gulp.task('push-changes', (cb) => {
64
- git.push('origin', 'master', cb);
65
- });
66
-
67
- gulp.task('create-tag', (cb) => {
68
- const version = getVersionFromPackage();
69
-
70
- git.tag(version, 'Release ' + version, (error) => {
71
- if (error) {
72
- return cb(error);
73
- }
74
-
75
- git.push('origin', 'master', { args: '--tags' }, cb);
76
- });
77
- });
78
-
79
- gulp.task('build-test-bundle', () => {
80
- return browserify({ entries: glob.sync('test/specs/**/*.js') })
81
- .bundle()
82
- .pipe(source('SpecRunner.js'))
83
- .pipe(buffer())
84
- .pipe(gulp.dest('test'));
85
- });
86
-
87
- gulp.task('execute-browser-tests', () => {
88
- return gulp.src('test/SpecRunner.js')
89
- .pipe(jasmine());
90
- });
91
-
92
- gulp.task('execute-node-tests', () => {
93
- return gulp.src(['test/specs/**/*.js'])
94
- .pipe(jasmine());
95
- });
96
-
97
- gulp.task('execute-tests', gulp.series(
98
- 'build-test-bundle',
99
- 'execute-browser-tests',
100
- 'execute-node-tests'
101
- ));
102
-
103
- gulp.task('release', gulp.series(
104
- 'ensure-clean-working-directory',
105
- 'execute-tests',
106
- 'bump-choice',
107
- 'bump-version',
108
- 'commit-changes',
109
- 'push-changes',
110
- 'create-tag'
111
- ));
112
-
113
- gulp.task('lint', () => {
114
- return gulp.src([ './**/*.js', './test/specs/**/*.js', '!./node_modules/**', '!./test/SpecRunner.js' ])
115
- .pipe(jshint({'esversion': 9}))
116
- .pipe(jshint.reporter('default'))
117
- .pipe(jshint.reporter('fail'));
118
- });
119
-
120
- gulp.task('test', gulp.series('execute-tests'));
121
-
122
- gulp.task('default', gulp.series('lint'));