@barchart/portfolio-api-common 1.0.1
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/LICENSE +674 -0
- package/README.md +2 -0
- package/gulpfile.js +129 -0
- package/jsdoc.json +8 -0
- package/lib/data/CorporateActionType.js +36 -0
- package/lib/data/InstrumentType.js +83 -0
- package/lib/data/PositionSummaryFrame.js +72 -0
- package/lib/data/TransactionType.js +325 -0
- package/lib/data/ValuationType.js +60 -0
- package/lib/formatters/TransactionFormatter.js +37 -0
- package/lib/serialization/PortfolioSchema.js +75 -0
- package/lib/serialization/PositionSchema.js +96 -0
- package/lib/serialization/TransactionSchema.js +116 -0
- package/package.json +32 -0
- package/test/SpecRunner.js +1 -0
- package/test/SpecRunnner.html +19 -0
package/gulpfile.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const gulp = require('gulp');
|
|
2
|
+
|
|
3
|
+
const browserify = require('browserify'),
|
|
4
|
+
buffer = require('vinyl-buffer'),
|
|
5
|
+
bump = require('gulp-bump'),
|
|
6
|
+
exec = require('child_process').exec,
|
|
7
|
+
git = require('gulp-git'),
|
|
8
|
+
gitStatus = require('git-get-status'),
|
|
9
|
+
glob = require('glob'),
|
|
10
|
+
jasmine = require('gulp-jasmine'),
|
|
11
|
+
jshint = require('gulp-jshint'),
|
|
12
|
+
runSequence = require('run-sequence'),
|
|
13
|
+
source = require('vinyl-source-stream'),
|
|
14
|
+
util = require('gulp-util');
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
|
|
18
|
+
function getVersionFromPackage() {
|
|
19
|
+
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
gulp.task('ensure-clean-working-directory', () => {
|
|
23
|
+
gitStatus(function(err, status) {
|
|
24
|
+
if (err, !status.clean) {
|
|
25
|
+
throw new Error('Unable to proceed, your working directory is not clean.');
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
gulp.task('bump-version', () => {
|
|
31
|
+
return gulp.src([ './package.json' ])
|
|
32
|
+
.pipe(bump({ type: 'patch' }).on('error', util.log))
|
|
33
|
+
.pipe(gulp.dest('./'));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
gulp.task('document', function (cb) {
|
|
37
|
+
exec('jsdoc . -c jsdoc.json -r -d docs', (error, stdout, stderr) => {
|
|
38
|
+
console.log(stdout);
|
|
39
|
+
console.log(stderr);
|
|
40
|
+
|
|
41
|
+
cb();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
gulp.task('commit-changes', () => {
|
|
46
|
+
return gulp.src([ './', './test/', './package.json' ])
|
|
47
|
+
.pipe(git.add())
|
|
48
|
+
.pipe(git.commit('Release. Bump version number'));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
gulp.task('push-changes', (cb) => {
|
|
52
|
+
git.push('origin', 'master', cb);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
gulp.task('create-tag', (cb) => {
|
|
56
|
+
const version = getVersionFromPackage();
|
|
57
|
+
|
|
58
|
+
git.tag(version, 'Release ' + version, function (error) {
|
|
59
|
+
if (error) {
|
|
60
|
+
return cb(error);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
git.push('origin', 'master', { args: '--tags' }, cb);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
gulp.task('build-test-bundle', () => {
|
|
68
|
+
return browserify({ entries: glob.sync('test/specs/**/*.js') })
|
|
69
|
+
.bundle()
|
|
70
|
+
.pipe(source('SpecRunner.js'))
|
|
71
|
+
.pipe(buffer())
|
|
72
|
+
.pipe(gulp.dest('test'));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
gulp.task('execute-browser-tests', () => {
|
|
76
|
+
return gulp.src('test/SpecRunner.js')
|
|
77
|
+
.pipe(jasmine());
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
gulp.task('execute-node-tests', () => {
|
|
81
|
+
return gulp.src(['test/specs/**/*.js'])
|
|
82
|
+
.pipe(jasmine());
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
gulp.task('execute-tests', (cb) => {
|
|
86
|
+
runSequence(
|
|
87
|
+
'build-test-bundle',
|
|
88
|
+
'execute-browser-tests',
|
|
89
|
+
'execute-node-tests',
|
|
90
|
+
|
|
91
|
+
function (error) {
|
|
92
|
+
if (error) {
|
|
93
|
+
console.log(error.message);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
cb(error);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
gulp.task('release', (cb) => {
|
|
101
|
+
runSequence(
|
|
102
|
+
'ensure-clean-working-directory',
|
|
103
|
+
'execute-tests',
|
|
104
|
+
'document',
|
|
105
|
+
'bump-version',
|
|
106
|
+
'commit-changes',
|
|
107
|
+
'push-changes',
|
|
108
|
+
'create-tag',
|
|
109
|
+
|
|
110
|
+
function (error) {
|
|
111
|
+
if (error) {
|
|
112
|
+
console.log(error.message);
|
|
113
|
+
} else {
|
|
114
|
+
console.log('Release complete');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
cb(error);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
gulp.task('lint', () => {
|
|
122
|
+
return gulp.src([ './**/*.js', './test/specs/**/*.js', '!./node_modules/**', '!./docs/**', '!./test/SpecRunner.js' ])
|
|
123
|
+
.pipe(jshint({'esversion': 6}))
|
|
124
|
+
.pipe(jshint.reporter('default'));
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
gulp.task('test', [ 'execute-tests' ]);
|
|
128
|
+
|
|
129
|
+
gulp.task('default', [ 'lint' ]);
|
package/jsdoc.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const Enum = require('@barchart/common-js/lang/Enum'),
|
|
2
|
+
is = require('@barchart/common-js/lang/is');
|
|
3
|
+
|
|
4
|
+
module.exports = (() => {
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
class CorporateActionType extends Enum {
|
|
8
|
+
constructor(code, description, internal) {
|
|
9
|
+
super(code, description);
|
|
10
|
+
|
|
11
|
+
this._internal = is.boolean(internal) && internal;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get internal() {
|
|
15
|
+
return this._internal;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static get DIVIDEND() {
|
|
19
|
+
return dividend;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static get SPLIT() {
|
|
23
|
+
return split;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static get JOB() {
|
|
27
|
+
return job;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const dividend = new CorporateActionType('DIVIDEND', 'Dividend', false);
|
|
32
|
+
const split = new CorporateActionType('SPLIT', 'Split', false);
|
|
33
|
+
const job = new CorporateActionType('JOB', 'Job', true);
|
|
34
|
+
|
|
35
|
+
return CorporateActionType;
|
|
36
|
+
})();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Enum = require('@barchart/common-js/lang/Enum');
|
|
3
|
+
|
|
4
|
+
module.exports = (() => {
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An enumeration used to classify instruments.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
* @extends {Enum}
|
|
12
|
+
* @param {String} description
|
|
13
|
+
* @param {String} code
|
|
14
|
+
* @param {Boolean} canReinvest
|
|
15
|
+
*/
|
|
16
|
+
class InstrumentType extends Enum {
|
|
17
|
+
constructor(code, description, canReinvest) {
|
|
18
|
+
super(code, description);
|
|
19
|
+
|
|
20
|
+
this._canReinvest = canReinvest;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Indicates if the instrument type allows automatic reinvestment.
|
|
25
|
+
*
|
|
26
|
+
* @returns {Boolean}
|
|
27
|
+
*/
|
|
28
|
+
get canReinvest() {
|
|
29
|
+
return this._canReinvest;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Cash.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
* @returns {InstrumentType}
|
|
37
|
+
*/
|
|
38
|
+
static get CASH() {
|
|
39
|
+
return cash;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* An equity issue.
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
* @returns {InstrumentType}
|
|
47
|
+
*/
|
|
48
|
+
static get EQUITY() {
|
|
49
|
+
return equity;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A mutual fund.
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
* @returns {InstrumentType}
|
|
57
|
+
*/
|
|
58
|
+
static get FUND() {
|
|
59
|
+
return fund;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* An undefined asset (e.g. a house, or a collectible, or a salvaged alien spaceship).
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
* @returns {InstrumentType}
|
|
67
|
+
*/
|
|
68
|
+
static get OTHER() {
|
|
69
|
+
return other;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
toString() {
|
|
73
|
+
return '[InstrumentType]';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const cash = new InstrumentType('CASH', 'cash', false);
|
|
78
|
+
const equity = new InstrumentType('EQUITY', 'equity', true);
|
|
79
|
+
const fund = new InstrumentType('FUND', 'mutual fund', true);
|
|
80
|
+
const other = new InstrumentType('OTHER', 'other', false);
|
|
81
|
+
|
|
82
|
+
return InstrumentType;
|
|
83
|
+
})();
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Enum = require('@barchart/common-js/lang/Enum');
|
|
3
|
+
|
|
4
|
+
module.exports = (() => {
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An enumeration used to define timeframes for position summaries.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
* @extends {Enum}
|
|
12
|
+
* @param {String} description
|
|
13
|
+
* @param {String} code
|
|
14
|
+
* @param {Boolean} canReinvest
|
|
15
|
+
*/
|
|
16
|
+
class PositionSummaryFrame extends Enum {
|
|
17
|
+
constructor(code, description) {
|
|
18
|
+
super(code, description);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A summary for a calendar year.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
* @returns {PositionSummaryFrame}
|
|
26
|
+
*/
|
|
27
|
+
static get YEARLY() {
|
|
28
|
+
return yearly;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A summary for a quarter.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
* @returns {PositionSummaryFrame}
|
|
36
|
+
*/
|
|
37
|
+
static get QUARTERLY() {
|
|
38
|
+
return quarterly;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A summary for a calendar month.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
* @returns {PositionSummaryFrame}
|
|
46
|
+
*/
|
|
47
|
+
static get MONTHLY() {
|
|
48
|
+
return monthly;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A summary the current year (to date).
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
* @returns {PositionSummaryFrame}
|
|
56
|
+
*/
|
|
57
|
+
static get YTD() {
|
|
58
|
+
return ytd;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
toString() {
|
|
62
|
+
return '[PositionSummaryFrame]';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const yearly = new PositionSummaryFrame('YEARL', 'year');
|
|
67
|
+
const quarterly = new PositionSummaryFrame('QUARTER', 'quarter');
|
|
68
|
+
const monthly = new PositionSummaryFrame('MONTH', 'month');
|
|
69
|
+
const ytd = new PositionSummaryFrame('YTD', 'year-to-date');
|
|
70
|
+
|
|
71
|
+
return PositionSummaryFrame;
|
|
72
|
+
})();
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Enum = require('@barchart/common-js/lang/Enum');
|
|
3
|
+
|
|
4
|
+
module.exports = (() => {
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An enumeration item that describes a type of transaction.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
* @extends {Enum}
|
|
12
|
+
* @param {String} code
|
|
13
|
+
* @param {String} description
|
|
14
|
+
* @param {Boolean} purchase
|
|
15
|
+
* @param {Boolean} sale
|
|
16
|
+
* @param {Boolean} income
|
|
17
|
+
* @param {Boolean} opening
|
|
18
|
+
* @param {Boolean} closing
|
|
19
|
+
*/
|
|
20
|
+
class TransactionType extends Enum {
|
|
21
|
+
constructor(code, description, purchase, sale, income, opening, closing) {
|
|
22
|
+
super(code, description);
|
|
23
|
+
|
|
24
|
+
assert.argumentIsRequired(purchase, 'purchase', Boolean);
|
|
25
|
+
assert.argumentIsRequired(sale, 'sale', Boolean);
|
|
26
|
+
assert.argumentIsRequired(income, 'income', Boolean);
|
|
27
|
+
assert.argumentIsRequired(opening, 'opening', Boolean);
|
|
28
|
+
assert.argumentIsRequired(closing, 'closing', Boolean);
|
|
29
|
+
|
|
30
|
+
this._purchase = purchase;
|
|
31
|
+
this._sale = sale;
|
|
32
|
+
this._income = income;
|
|
33
|
+
this._opening = opening;
|
|
34
|
+
this._closing = closing;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Indicates if the transaction was a trade.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
* @returns {Boolean}
|
|
42
|
+
*/
|
|
43
|
+
get trade() {
|
|
44
|
+
return this._purchase || this._sale;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Indicates if the trade was a purchase.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
* @returns {Boolean}
|
|
52
|
+
*/
|
|
53
|
+
get purchase() {
|
|
54
|
+
return this._purchase;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Indicates if the trade was a sale.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
* @returns {Boolean}
|
|
62
|
+
*/
|
|
63
|
+
get sale() {
|
|
64
|
+
return this._sale;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Indicates if the transaction was an income payment.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
* @returns {Boolean}
|
|
72
|
+
*/
|
|
73
|
+
get income() {
|
|
74
|
+
return this._income;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Indicates if the transactions opens the position (i.e. increases its
|
|
79
|
+
* magnitude).
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
* @returns {Boolean}
|
|
83
|
+
*/
|
|
84
|
+
get opening() {
|
|
85
|
+
return this._opening;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Indicates if the transactions closes the position (i.e. decreases its
|
|
90
|
+
* magnitude).
|
|
91
|
+
*
|
|
92
|
+
* @public
|
|
93
|
+
* @returns {Boolean}
|
|
94
|
+
*/
|
|
95
|
+
get closing() {
|
|
96
|
+
return this._closing;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* A purchase.
|
|
101
|
+
*
|
|
102
|
+
* @public
|
|
103
|
+
* @static
|
|
104
|
+
* @returns {TransactionType}
|
|
105
|
+
*/
|
|
106
|
+
static get BUY() {
|
|
107
|
+
return buy;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A sale.
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
* @static
|
|
115
|
+
* @returns {TransactionType}
|
|
116
|
+
*/
|
|
117
|
+
static get SELL() {
|
|
118
|
+
return sell;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A purchase (in a short position).
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
* @static
|
|
126
|
+
* @returns {TransactionType}
|
|
127
|
+
*/
|
|
128
|
+
static get BUY_SHORT() {
|
|
129
|
+
return buyShort;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A short sale.
|
|
134
|
+
*
|
|
135
|
+
* @public
|
|
136
|
+
* @static
|
|
137
|
+
* @returns {TransactionType}
|
|
138
|
+
*/
|
|
139
|
+
static get SELL_SHORT() {
|
|
140
|
+
return sellShort;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A cash dividend.
|
|
145
|
+
*
|
|
146
|
+
* @public
|
|
147
|
+
* @static
|
|
148
|
+
* @returns {TransactionType}
|
|
149
|
+
*/
|
|
150
|
+
static get DIVIDEND() {
|
|
151
|
+
return dividend;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* A cash dividend, reinvested.
|
|
156
|
+
*
|
|
157
|
+
* @public
|
|
158
|
+
* @static
|
|
159
|
+
* @returns {TransactionType}
|
|
160
|
+
*/
|
|
161
|
+
static get DIVIDEND_REINVEST() {
|
|
162
|
+
return dividendReinvest;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A stock dividend.
|
|
167
|
+
*
|
|
168
|
+
* @public
|
|
169
|
+
* @static
|
|
170
|
+
* @returns {TransactionType}
|
|
171
|
+
*/
|
|
172
|
+
static get DIVIDEND_STOCK() {
|
|
173
|
+
return dividendStock;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A mutual fund distribution in cash.
|
|
178
|
+
*
|
|
179
|
+
* @public
|
|
180
|
+
* @static
|
|
181
|
+
* @returns {TransactionType}
|
|
182
|
+
*/
|
|
183
|
+
static get DISTRIBUTION_CASH() {
|
|
184
|
+
return distributionCash;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* A mutual fund distribution in units.
|
|
189
|
+
*
|
|
190
|
+
* @public
|
|
191
|
+
* @static
|
|
192
|
+
* @returns {TransactionType}
|
|
193
|
+
*/
|
|
194
|
+
static get DISTRIBUTION_FUND() {
|
|
195
|
+
return distributionFund;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* A split.
|
|
200
|
+
*
|
|
201
|
+
* @public
|
|
202
|
+
* @static
|
|
203
|
+
* @returns {TransactionType}
|
|
204
|
+
*/
|
|
205
|
+
static get SPLIT() {
|
|
206
|
+
return split;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A fee.
|
|
211
|
+
*
|
|
212
|
+
* @public
|
|
213
|
+
* @static
|
|
214
|
+
* @returns {TransactionType}
|
|
215
|
+
*/
|
|
216
|
+
static get FEE() {
|
|
217
|
+
return fee;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* A mutual fund fee, which is paid in units.
|
|
222
|
+
*
|
|
223
|
+
* @public
|
|
224
|
+
* @static
|
|
225
|
+
* @returns {TransactionType}
|
|
226
|
+
*/
|
|
227
|
+
static get FEE_UNITS() {
|
|
228
|
+
return feeUnits;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* A deposit.
|
|
233
|
+
*
|
|
234
|
+
* @public
|
|
235
|
+
* @static
|
|
236
|
+
* @returns {TransactionType}
|
|
237
|
+
*/
|
|
238
|
+
static get DEPOSIT() {
|
|
239
|
+
return deposit;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* A withdrawal.
|
|
244
|
+
*
|
|
245
|
+
* @public
|
|
246
|
+
* @static
|
|
247
|
+
* @returns {TransactionType}
|
|
248
|
+
*/
|
|
249
|
+
static get WITHDRAWAL() {
|
|
250
|
+
return withdrawal;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* A system-generated withdrawal, arising from another transaction.
|
|
255
|
+
*
|
|
256
|
+
* @public
|
|
257
|
+
* @static
|
|
258
|
+
* @returns {TransactionType}
|
|
259
|
+
*/
|
|
260
|
+
static get DEBIT() {
|
|
261
|
+
return debit;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* A system-generated deposit, arising from another transaction.
|
|
266
|
+
*
|
|
267
|
+
* @public
|
|
268
|
+
* @static
|
|
269
|
+
* @returns {TransactionType}
|
|
270
|
+
*/
|
|
271
|
+
static get CREDIT() {
|
|
272
|
+
return credit;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* A valuation event.
|
|
277
|
+
*
|
|
278
|
+
* @public
|
|
279
|
+
* @static
|
|
280
|
+
* @returns {TransactionType}
|
|
281
|
+
*/
|
|
282
|
+
static get VALUATION() {
|
|
283
|
+
return valuation;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Other Income.
|
|
288
|
+
*
|
|
289
|
+
* @public
|
|
290
|
+
* @static
|
|
291
|
+
* @returns {TransactionType}
|
|
292
|
+
*/
|
|
293
|
+
static get INCOME() {
|
|
294
|
+
return income;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
toString() {
|
|
298
|
+
return '[TransactionType]';
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const buy = new TransactionType('B', 'Buy', true, false, false, true, false);
|
|
303
|
+
const sell = new TransactionType('S', 'Sell', false, true, false, false, true);
|
|
304
|
+
const buyShort = new TransactionType('BS', 'Buy To Cover', true, false, false, false, true);
|
|
305
|
+
const sellShort = new TransactionType('SS', 'Sell Short', false, true, false, true, false);
|
|
306
|
+
const dividend = new TransactionType('DV', 'Dividend', false, false, true, false, false);
|
|
307
|
+
const dividendReinvest = new TransactionType('DR', 'Dividend (Reinvested)', false, false, false, true, false);
|
|
308
|
+
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', false, false, false, true, false);
|
|
309
|
+
const split = new TransactionType('SP', 'Split', false, false, false, true, false);
|
|
310
|
+
const fee = new TransactionType('F', 'Fee', false, false, false, true, false);
|
|
311
|
+
const feeUnits = new TransactionType('FU', 'Fee', false, false, false, false, false);
|
|
312
|
+
|
|
313
|
+
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', false, false, true, false, false);
|
|
314
|
+
const distributionFund = new TransactionType('DF', 'Distribution (Units)', false, false, false, true, false);
|
|
315
|
+
|
|
316
|
+
const deposit = new TransactionType('D', 'Deposit', false, false, false, false, false);
|
|
317
|
+
const withdrawal = new TransactionType('W', 'Withdrawal', false, false, false, false, false);
|
|
318
|
+
const debit = new TransactionType('DR', 'Debit', false, false, false, false, false);
|
|
319
|
+
const credit = new TransactionType('CR', 'Credit', false, false, false, false, false);
|
|
320
|
+
|
|
321
|
+
const valuation = new TransactionType('V', 'Valuation', false, false, false, false, false);
|
|
322
|
+
const income = new TransactionType('I', 'Income', false, false, true, false, false);
|
|
323
|
+
|
|
324
|
+
return TransactionType;
|
|
325
|
+
})();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Enum = require('@barchart/common-js/lang/Enum');
|
|
3
|
+
|
|
4
|
+
module.exports = (() => {
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An enumeration item that describes a strategy for calculating basis.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
* @extends {Enum}
|
|
12
|
+
* @param {String} description
|
|
13
|
+
* @param {String} code
|
|
14
|
+
*/
|
|
15
|
+
class ValuationType extends Enum {
|
|
16
|
+
constructor(code, description) {
|
|
17
|
+
super(code, description);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Given a code, returns the enumeration item.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
* @param {String} code
|
|
25
|
+
* @returns {ValuationType|null}
|
|
26
|
+
*/
|
|
27
|
+
static parse(code) {
|
|
28
|
+
return Enum.fromCode(ValuationType, code);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A valuation method that uses average costing.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
* @returns {ValuationType}
|
|
36
|
+
*/
|
|
37
|
+
static get AVERAGE_COST() {
|
|
38
|
+
return averageCost;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A valuation method that uses first-in, first-out methodology.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
* @returns {ValuationType}
|
|
46
|
+
*/
|
|
47
|
+
static get FIFO() {
|
|
48
|
+
return fifo;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toString() {
|
|
52
|
+
return '[ValuationType]';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const fifo = new ValuationType('FIFO', 'first in, first out');
|
|
57
|
+
const averageCost = new ValuationType('AVG', 'average cost');
|
|
58
|
+
|
|
59
|
+
return ValuationType;
|
|
60
|
+
})();
|