-
Notifications
You must be signed in to change notification settings - Fork 566
/
Copy pathForceIndex.js
63 lines (53 loc) · 1.78 KB
/
ForceIndex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use strict"
var ForceIndex = require('../../lib/volume/ForceIndex').ForceIndex;
var assert = require("assert");
var inputForceIndex = {
open : [
],
high : [
],
low : [
],
close : [
14.33,14.23,13.98,13.96,13.93,13.84,13.99,14.31,14.51,14.46,14.61,14.48,14.53,14.56,14.25,14.42
],
volume : [
0,45579,66285,51761,69341,41631,73499,55427,61082,33325,39191,51128,46505,44562,48815,33411
],
period : 1
};
var expectedResult = [
-4558,-16571,-1035,-2080,-3747,11025,17737,12216,-1666,5879,-6647,2325,1337,-15133,5680
];
describe('ForceIndex (Force Index', function () {
it('should calculate ForceIndex using the calculate method', function () {
assert.deepEqual(ForceIndex.calculate(inputForceIndex).map(Math.round), expectedResult, 'Wrong Results');
});
it('should be able to get ForceIndex for the next bar', function () {
var forceIndex = new ForceIndex(inputForceIndex);
assert.deepEqual(forceIndex.getResult().map(Math.round), expectedResult, 'Wrong Results while getting results');
})
it('should be able to get ForceIndex for the next bar using nextValue', function () {
var forceIndex = new ForceIndex({
open : [],
high : [],
low : [],
close : [],
volume : []
});
var results = [];
inputForceIndex.close.forEach((price,index) => {
var result = forceIndex.nextValue({
open : inputForceIndex.open[index],
high : inputForceIndex.high[index],
low : inputForceIndex.low[index],
close : inputForceIndex.close[index],
volume : inputForceIndex.volume[index]
});
if (result != undefined) {
results.push(result)
}
});
assert.deepEqual(results.map(Math.round), expectedResult, 'Wrong Results while getting results');
})
})