Browse Source

prefix tests, split up indicator tests

develop
Mike van Rossum 5 years ago
parent
commit
89251a46b8
13 changed files with 249 additions and 437 deletions
  1. +1
    -0
      core/util.js
  2. +1
    -1
      test/candleBatcher.js
  3. +0
    -249
      test/candleStore.js
  4. +0
    -49
      test/day.js
  5. +1
    -1
      test/exchanges/bitstamp.js
  6. +0
    -135
      test/indicators.js
  7. +34
    -0
      test/indicators/dema.js
  8. +55
    -0
      test/indicators/ema.js
  9. +100
    -0
      test/indicators/macd.js
  10. +55
    -0
      test/indicators/ppo.js
  11. +1
    -1
      test/marketFetcher.js
  12. +0
    -0
      test/plugins/portfolioManager.js
  13. +1
    -1
      test/tradeBatcher.js

+ 1
- 0
core/util.js View File

@ -95,6 +95,7 @@ var util = {
exchanges: ROOT + 'exchanges/',
plugins: ROOT + 'plugins/',
methods: ROOT + 'methods/',
indicators: ROOT + 'methods/indicators/',
budfox: ROOT + 'core/budfox/',
importers: ROOT + 'importers/exchanges/'
}

+ 1
- 1
test/candleBatcher.js View File

@ -24,7 +24,7 @@ var candles = [
{"start":moment("2015-02-15T00:06:00.000Z"),"open":257.46,"high":257.48,"low":257.46,"close":257.48,"vwp":257.47333333333336,"volume":7.5,"trades":4}
];
describe('candleBatcher', function() {
describe('core/candleBatcher', function() {
var cb;
it('should throw when not passed a number', function() {

+ 0
- 249
test/candleStore.js View File

@ -1,249 +0,0 @@
// TODO: rewrite tests for mocha once we use Days.
// var fs = require('fs');
// var zlib = require('zlib');
// var async = require('async');
// var _ = require('lodash');
// var CSVStore = require('../core/candleStore.js');
// var TMPDIR = "./tmp/";
// var CSVNAME = "test.csv";
// var CSVGEN = "gen.csv";
// var DAY_FILE = "day.csv";
// var CSVFILE = TMPDIR + CSVNAME;
// var CSVGENFILE = TMPDIR + CSVGEN;
// var DAY_PATH = TMPDIR + DAY_FILE;
// var LOAD_DAY = "2009-01-12";
// var LOAD_FILE = "history-"+LOAD_DAY+".csv";
// var LOAD_PATH = TMPDIR + LOAD_FILE;
// var CANDLES = [{
// s: 1,
// o: 2,
// h: 3,
// l: 4,
// c: 5,
// p: 6
// }, {
// s: 10,
// o: 20,
// h: 30,
// l: 40,
// c: 50,
// p: 60
// }];
// var DATA = "1,2,3,4,5,6\n" + "10,20,30,40,50,60";
// var GEN_CANDLES = 1440;
// var CANDLES_DAY = _.map(_.range(GEN_CANDLES), function (d) {
// //TODO(yin): Randomness in test is bad, figure out a static seed
// var rnd = function () {
// return Math.random() * 1000
// }
// return {
// s: d,
// o: rnd().toString(),
// h: rnd().toString(),
// l: rnd().toString(),
// c: rnd().toString(),
// p: rnd().toString()
// };
// });
// var timer;
// var csv;
// function cleanUp(path, next) {
// if (fs.existsSync(path)) {
// var files = [];
// files = fs.readdirSync(path);
// files.forEach(function (file, index) {
// var curPath = path + "/" + file;
// if (fs.statSync(curPath).isDirectory()) {
// // recurse
// cleanUp(curPath);
// } else {
// // delete file
// fs.unlinkSync(curPath);
// }
// });
// fs.rmdirSync(path);
// }
// next(null, path);
// }
// function buffersEqual(a, b) {
// if (!Buffer.isBuffer(a)) return undefined;
// if (!Buffer.isBuffer(b)) return undefined;
// if (a.length !== b.length) return false;
// for (var i = 0; i < a.length; i++) {
// if (a[i] !== b[i]) return false;
// }
// return true;
// };
// var Timer = function () {
// this.precision = 3;
// this.checkpoints = [];
// this.time_now = function (note) {
// var elapsed;
// var cp_count = this.checkpoints.length;
// if (cp_count > 0) {
// var last = this.checkpoints[cp_count - 1];
// var diff = process.hrtime(last);
// elapsed = diff[0] * 1000 + diff[1] / 100000;
// console.log("Elapsed: " + elapsed.toFixed(this.precision) + " ms - " + note);
// }
// this.checkpoints.push(process.hrtime());
// }
// }
// function buffersEqual(a, b) {
// if (!Buffer.isBuffer(a)) return undefined;
// if (!Buffer.isBuffer(b)) return undefined;
// if (a.length !== b.length) return false;
// for (var i = 0; i < a.length; i++) {
// if (a[i] !== b[i]) return false;
// }
// return true;
// };
// var Timer = function () {
// this.precision = 3;
// this.checkpoints = [];
// this.time_now = function (note) {
// var elapsed;
// var cp_count = this.checkpoints.length;
// if (cp_count > 0) {
// var last = this.checkpoints[cp_count - 1];
// var diff = process.hrtime(last);
// elapsed = diff[0] * 1000 + diff[1] / 100000;
// console.log("Elapsed: " + elapsed.toFixed(this.precision) + " ms - " + note);
// }
// this.checkpoints.push(process.hrtime());
// }
// }
// //TODO(yin): tearDownCandleFile() at end of tests
// var setupCandleFile = function(filename, data, done) {
// fs.existsSync(TMPDIR) || fs.mkdirSync(TMPDIR);
// zlib.deflate(data, function(err, buffer) {
// fs.writeFile(filename, buffer, function(err) {
// done(err);
// });
// });
// }
// module.exports = {
// // runs before each test method invocation
// setUp: function (done) {
// timer = new Timer();
// csv = new CSVStore();
// csv.directory = TMPDIR;
// done();
// },
// // runs after each test method invocation
// tearDown: function (done) {
// // fs.existsSync(TMPDIR) && cleanUp(TMPDIR, done);
// timer = null;
// done();
// },
// test_loadFile: function (test) {
// setupCandleFile(CSVFILE, DATA, function() {
// timer.time_now();
// try {
// csv.read(CSVNAME, function (candles) {
// timer.time_now('candles parsed');
// // we must catch failed asserts and print ourself
// try {
// test.deepEqual(candles, CANDLES, "Loaded candles seem corrupt: " + candles);
// test.done();
// } catch (err) {
// console.log(err);
// throw err;
// }
// });
// } catch (err) {
// console.log(err);
// throw err;
// }
// });
// },
// test_saveFile: function (test) {
// timer.time_now();
// //TODO(yin):Mock the fs.
// csv.write(CSVGEN, CANDLES, function (err) {
// timer.time_now("candles written");
// fs.readFile(CSVGENFILE, function (err, buffer) {
// if (err) {
// console.log(err);
// throw err;
// }
// zlib.deflate(DATA, function (err, databuf) {
// // ensure assertion's are printed
// try {
// test.ok(buffersEqual(buffer, databuf), "Persisted candles seem corrupt");
// test.done();
// } catch (err) {
// console.log(err);
// throw err;
// }
// });
// });
// });
// },
// test_saveLoadDay: function (test) {
// timer.time_now();
// //TODO(yin):Mock the fs.
// csv.write(DAY_FILE, CANDLES_DAY, function (candles) {
// timer.time_now("candles written");
// csv.read(DAY_FILE, function (candles) {
// timer.time_now('candles parsed');
// // we must catch failed asserts and print ourself
// try {
// test.deepEqual(candles, CANDLES_DAY);
// test.done();
// } catch (err) {
// //TODO(yin):too much output be generated if this is printed
// throw err;
// }
// });
// });
// },
// test_candlesAreNumbers: function (test) {
// setupCandleFile(CSVNAME, DATA, function() {
// timer.time_now();
// csv.read(CSVNAME, function (err, candles) {
// timer.time_now('candles parsed');
// try {
// _.each(candles, function (c) {
// console.log(c);
// //TODO(yin): This generates also too much output
// test.equals(typeof (c.s), 'number');
// test.equals(typeof (c.o), 'number');
// test.equals(typeof (c.h), 'number');
// test.equals(typeof (c.l), 'number');
// test.equals(typeof (c.p), 'number');
// });
// test.done();
// } catch (err) {
// throw err;
// }
// });
// });
// },
// test_loadDay: function(test) {
// setupCandleFile(LOAD_PATH, DATA, function() {
// csv.loadDay(LOAD_DAY, function(err, candles) {
// console.log(10);
// try {
// test.equal(err, null, "No error should happen");
// test.deepEqual(candles, CANDLES, "Store should load candles in from a day");
// test.done();
// } catch(err) {
// console.log(err);
// }
// });
// });
// }
// };

+ 0
- 49
test/day.js View File

@ -1,49 +0,0 @@
// TODO: rewrite tests for mocha once we use Days.
// var Day = require('../core/candleStore.js').Day;
// module.exports = {
// //TODO(yin): Discuss test naming conventions with outhers.
// day_assumptions: function(test) {
// var day = new Day("my-birthsday");
// // NOTE(yin):Yes, usualy you do test for every elementary assumption possible, if
// // not tested by a smaller test.
// // This helps pinpoint the cause faster and aughts to give the developer a meaninful message
// // for each assertion test ('should' is the keyword in assertion messages).
// test.equals(day.candles.length, 0, "Day should be initialized empty (no candles).")
// test.equals(day.state, 'uninitialized', "Day should be initialized in state 'uninitialized'.")
// test.done();
// },
// day_addCandles: function(test) {
// var day = new Day("my-birthsday");
// var candles = [
// { s: 1 },
// { s: 2 },
// { s: 3 }
// ];
// day.addCandles(candles);
// test.deepEqual(day.candles, candles, "Day should contain candles previously appended to it.");
// test.done();
// },
// //NOTE(yin): Test every possibility. If smaller test pass, regrression in this test may
// // may indicate, i.e. addCandles() replaces, and not concatenates candles.
// day_addCandles2: function(test) {
// var day = new Day("my-birthsday");
// var candles = [
// { s: 1 },
// { s: 2 },
// { s: 3 }
// ];
// var candles2 = [
// { s: 10 },
// ];
// var candlesExpect = candles.concat(candles2);
// day.addCandles(candles);
// day.addCandles(candles2);
// test.equals(day.candles.length, candles.length + candles2.length,
// "Day should contain exactly as much candles as we added to it.");
// test.deepEqual(day.candles, candlesExpect,
// "Last candles in to a Day should be the last appended to it.")
// test.done();
// },
// };

+ 1
- 1
test/exchanges/bitstamp.js View File

@ -43,7 +43,7 @@ spoofer = {
bitstamp: FakeExchange
}
describe('bitstamp', function() {
describe('exchanges/bitstamp', function() {
var Bitstamp = proxyquire(dirs.exchanges + 'bitstamp', spoofer);
var bs;

+ 0
- 135
test/indicators.js View File

@ -1,135 +0,0 @@
var chai = require('chai');
var expect = chai.expect;
var should = chai.should;
var sinon = require('sinon');
var _ = require('lodash');
// Fake input prices to verify all indicators
// are working correctly by comparing fresh
// calculated results to pre calculated results.
// The precalculated results are already compared
// to MS Excel results, more info here:
//
// https://github.com/askmike/gekko/issues/161
var prices = [81, 24, 75, 21, 34, 25, 72, 92, 99, 2, 86, 80, 76, 8, 87, 75, 32, 65, 41, 9, 13, 26, 56, 28, 65, 58, 17, 90, 87, 86, 99, 3, 70, 1, 27, 9, 92, 68, 9];
describe('Indicators', function() {
describe('EMA', function() {
var EMA = require('../methods/indicators/EMA.js');
var verified_ema10results = [81,70.63636363636363,71.4297520661157,62.26070623591284,57.12239601120141,51.28196037280115,55.04887666865549,61.767262728899944,68.53685132364541,56.43924199207351,61.81392526624197,65.12048430874341,67.09857807079005,56.35338205791913,61.92549441102474,64.30267724538388,58.42946320076862,59.624106255174325,56.2379051178699,47.649195096439,41.349341442541004,38.55855208935173,41.72972443674232,39.233410902789174,43.91824528410023,46.47856432335473,41.118825355472055,50.00631165447713,56.73243680820856,62.053811933988825,68.77130067326358,56.81288236903384,59.21054012011859,48.626805552824294,44.69465908867441,38.204721072551784,47.985680877542364,51.62464799071648,43.874711992404386];
var verified_ema12results = [81,72.23076923076923,72.65680473372781,64.709604005462,59.98504954308323,54.602734228762735,57.27923665510693,62.620892554321244,68.2176783151949,58.030343189780304,62.33336731442949,65.05131080451726,66.73572452689922,57.69945921506857,62.20723472044264,64.17535245575915,59.2252982317962,60.11371388844294,57.173142520990176,49.761889825453224,44.10621446769119,41.320643011123316,43.57900562479665,41.182235528674084,44.84650698580115,46.87012129567789,42.27471801941975,49.61706909335518,55.368289232839,60.080860120094535,66.06842010161846,56.365586239831,58.46318835678008,49.62269784035237,46.14228278799047,40.42808543599194,48.36222613814702,51.383422116893634,44.86289563737154];
var verified_ema26results = [81,76.77777777777777,76.64609053497942,72.52415790275873,69.67051657662846,66.36158942280413,66.77924946555937,68.64745320885127,70.89579000819562,65.79239815573669,67.28925755160805,68.2307940292667,68.80629076783954,64.30212108133291,65.98344544567863,66.65133837562836,64.08457257002625,64.15238200928357,62.43739074933664,58.479065508645036,55.11024584133799,52.95393133457221,53.17956605052982,51.314413009749835,52.32816019421281,52.748296476122974,50.10027451492868,53.05580973604507,55.57019420004173,57.82425388892753,60.874309156414384,56.58732329297628,57.58085490090396,53.38968046379996,51.4348893183333,48.29156418364194,51.52922609596476,52.74928342218959,49.50859576128666];
it('should correctly calculate EMAs with weight 10', function() {
var ema = new EMA(10);
_.each(prices, function(p, i) {
ema.update(p);
expect(ema.result).to.equal(verified_ema10results[i]);
});
});
it('should correctly calculate EMAs with weight 12', function() {
var ema = new EMA(12);
_.each(prices, function(p, i) {
ema.update(p);
expect(ema.result).to.equal(verified_ema12results[i]);
});
});
it('should correctly calculate EMAs with weight 26', function() {
var ema = new EMA(26);
_.each(prices, function(p, i) {
ema.update(p);
expect(ema.result).to.equal(verified_ema26results[i]);
});
});
});
describe('MACD', function() {
var MACD = require('../methods/indicators/MACD.js');
var verified_macd12v26v9diff = [0,-4.547008547008545,-3.9892858012516115,-7.814553897296733,-9.68546703354523,-11.758855194041395,-9.500012810452446,-6.02656065453003,-2.678111693000716,-7.762054965956388,-4.955890237178558,-3.179483224749447,-2.070566240940323,-6.6026618662643415,-3.776210725235984,-2.4759859198692027,-4.859274338230051,-4.038668120840633,-5.264248228346467,-8.717175683191812,-11.004031373646804,-11.633288323448895,-9.600560425733171,-10.13217748107575,-7.4816532084116645,-5.8781751804450835,-7.825556495508927,-3.4387406426898934,-0.20190496720273643,2.256606231167005,5.1941109452040735,-0.2217370531452758,0.8823334558761218,-3.766982623447589,-5.29260653034283,-7.863478747649999,-3.166999957817737,-1.365861305295958,-4.64570012391512];
var verified_macd12v26v9signal = [0,-0.9094017094017091,-1.5253785277716898,-2.7832136016766986,-4.163664288050406,-5.6827024692486034,-6.446164537489373,-6.362243760897504,-5.625417347318147,-6.052744871045796,-5.833373944272349,-5.30259580036777,-4.65618988848228,-5.045484284038693,-4.791629572278152,-4.328500841796362,-4.4346555410831,-4.355458057034607,-4.537216091296979,-5.373208009675945,-6.499372682470117,-7.526155810665873,-7.941036733679333,-8.379264883158616,-8.199742548209226,-7.735429074656398,-7.753454558826904,-6.890511775599502,-5.55279041392015,-3.990911084902719,-2.153906678881361,-1.767472753734144,-1.2375115118120907,-1.7434057341391904,-2.4532458933799184,-3.535292464233935,-3.4616339629506956,-3.0424794314197485,-3.363123569918823];
var verified_macd12v26v9result = [0,-3.6376068376068362,-2.4639072734799217,-5.031340295620034,-5.521802745494824,-6.076152724792792,-3.053848272963074,0.33568310636747434,2.9473056543174314,-1.7093100949105917,0.8774837070937913,2.1231125756183227,2.585623647541957,-1.5571775822256484,1.0154188470421683,1.8525149219271597,-0.42461879714695083,0.3167899361939739,-0.7270321370494885,-3.3439676735158663,-4.504658691176687,-4.107132512783021,-1.6595236920538383,-1.7529125979171347,0.7180893397975616,1.8572538942113148,-0.07210193668202258,3.4517711329096086,5.350885446717413,6.247517316069724,7.3480176240854345,1.5457357005888681,2.1198449676882127,-2.0235768893083987,-2.839360636962912,-4.3281862834160645,0.2946340051329588,1.6766181261237905,-1.2825765539962966];
it('should correctly calculate MACD diffs with 12/26/9', function() {
var macd = new MACD({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
macd.update(p);
expect(macd.diff).to.equal(verified_macd12v26v9diff[i]);
});
});
it('should correctly calculate MACD signals with 12/26/9', function() {
var macd = new MACD({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
macd.update(p);
expect(macd.signal.result).to.equal(verified_macd12v26v9signal[i]);
});
});
it('should correctly calculate MACD results with 12/26/9', function() {
var macd = new MACD({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
macd.update(p);
expect(macd.result).to.equal(verified_macd12v26v9result[i]);
});
});
});
describe('PPO', function() {
var PPO = require('../methods/indicators/PPO.js');
var verified_ppo12v26v9 = [0,-5.922297673383055,-5.204813152773915,-10.775104631720897,-13.901816018390623,-17.719369436924076,-14.22599518036208,-8.779001074074772,-3.7775327599722406,-11.79779911287454,-7.3650541223130555,-4.659894802610166,-3.0092688006197794,-10.268186733549467,-5.72296687408477,-3.714833010426942,-7.582596159036941,-6.295429716477546,-8.431243146403258,-14.906489369094212,-19.9673059077387,-21.968696242678835,-18.053100351760996,-19.745285752660987,-14.297565938958984,-11.143819939485432,-15.619787658403148,-6.481364924591247,-0.3633332042639952,3.9025254618963814,8.5325172756507,-0.3918493405267646,1.5323382353294481,-7.05563807597937,-10.289915270521151,-16.28333826120637,-6.14602662946988,-2.589345706109427,-9.383623293044062];
var verified_ppo12v26v9signal = [0,-1.184459534676611,-1.9885302582960718,-3.745845132981037,-5.777039310062954,-8.16550533543518,-9.37760330442056,-9.257882858351403,-8.161812838675571,-8.889010093515365,-8.584218899274903,-7.799354079941956,-6.8413370240775215,-7.526706965971911,-7.165958947594484,-6.475733760160976,-6.697106239936169,-6.616770935244445,-6.979665377476208,-8.565030175799809,-10.845485322187589,-13.07012750628584,-14.066722075380872,-15.202434810836897,-15.021461036461314,-14.245932817066137,-14.52070378533354,-12.912836013185082,-10.402935451400865,-7.541843268741416,-4.3269711598629925,-3.539946795995747,-2.5254897897307083,-3.431519446980441,-4.8031986116885825,-7.099226541592141,-6.908586559167689,-6.044738388556036,-6.712515369453642];
var verified_ppo12v26v9hist = [0,-4.737838138706444,-3.2162828944778434,-7.02925949873986,-8.12477670832767,-9.553864101488896,-4.84839187594152,0.47888178427663064,4.3842800787033305,-2.9087890193591743,1.2191647769618479,3.13945927733179,3.832068223457742,-2.7414797675775553,1.4429920735097133,2.760900749734034,-0.8854899191007712,0.32134121876689914,-1.4515777689270495,-6.341459193294403,-9.121820585551113,-8.898568736392996,-3.9863782763801243,-4.54285094182409,0.7238950975023304,3.102112877580705,-1.099083873069608,6.431471088593835,10.03960224713687,11.444368730637798,12.859488435513693,3.1480974554689825,4.057828025060156,-3.6241186289989296,-5.486716658832568,-9.18411171961423,0.762559929697809,3.455392682446609,-2.6711079235904203];
it('should correctly calculate PPOs with 12/26/9', function() {
var ppo = new PPO({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
ppo.update(p);
expect(ppo.ppo).to.equal(verified_ppo12v26v9[i]);
});
});
it('should correctly calculate PPO signals with 12/26/9', function() {
var ppo = new PPO({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
ppo.update(p);
expect(ppo.PPOsignal.result).to.equal(verified_ppo12v26v9signal[i]);
});
});
it('should correctly calculate PPO hists with 12/26/9', function() {
var ppo = new PPO({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
ppo.update(p);
expect(ppo.PPOhist).to.equal(verified_ppo12v26v9hist[i]);
});
});
});
xdescribe('DEMA', function() {
var DEMA = require('../methods/indicators/DEMA.js');
xit('should correctly calculate DEMAs', function() {
// TODO!
});
});
});

+ 34
- 0
test/indicators/dema.js View File

@ -0,0 +1,34 @@
var chai = require('chai');
var expect = chai.expect;
var should = chai.should;
var sinon = require('sinon');
var _ = require('lodash');
var util = require('../../core/util');
var dirs = util.dirs();
var INDICATOR_PATH = dirs.indicators;
// Fake input prices to verify all indicators
// are working correctly by comparing fresh
// calculated results to pre calculated results.
// The precalculated results are already compared
// to MS Excel results, more info here:
//
// https://github.com/askmike/gekko/issues/161
var prices = [81, 24, 75, 21, 34, 25, 72, 92, 99, 2, 86, 80, 76, 8, 87, 75, 32, 65, 41, 9, 13, 26, 56, 28, 65, 58, 17, 90, 87, 86, 99, 3, 70, 1, 27, 9, 92, 68, 9];
xdescribe('indicators/DEMA', function() {
var DEMA = require(INDICATOR_PATH + 'DEMA');
xit('should correctly calculate DEMAs', function() {
// TODO!
});
});

+ 55
- 0
test/indicators/ema.js View File

@ -0,0 +1,55 @@
var chai = require('chai');
var expect = chai.expect;
var should = chai.should;
var sinon = require('sinon');
var _ = require('lodash');
var util = require('../../core/util');
var dirs = util.dirs();
var INDICATOR_PATH = dirs.indicators;
// Fake input prices to verify all indicators
// are working correctly by comparing fresh
// calculated results to pre calculated results.
// The precalculated results are already compared
// to MS Excel results, more info here:
//
// https://github.com/askmike/gekko/issues/161
var prices = [81, 24, 75, 21, 34, 25, 72, 92, 99, 2, 86, 80, 76, 8, 87, 75, 32, 65, 41, 9, 13, 26, 56, 28, 65, 58, 17, 90, 87, 86, 99, 3, 70, 1, 27, 9, 92, 68, 9];
describe('indicators/EMA', function() {
var EMA = require(INDICATOR_PATH + 'EMA');
var verified_ema10results = [81,70.63636363636363,71.4297520661157,62.26070623591284,57.12239601120141,51.28196037280115,55.04887666865549,61.767262728899944,68.53685132364541,56.43924199207351,61.81392526624197,65.12048430874341,67.09857807079005,56.35338205791913,61.92549441102474,64.30267724538388,58.42946320076862,59.624106255174325,56.2379051178699,47.649195096439,41.349341442541004,38.55855208935173,41.72972443674232,39.233410902789174,43.91824528410023,46.47856432335473,41.118825355472055,50.00631165447713,56.73243680820856,62.053811933988825,68.77130067326358,56.81288236903384,59.21054012011859,48.626805552824294,44.69465908867441,38.204721072551784,47.985680877542364,51.62464799071648,43.874711992404386];
var verified_ema12results = [81,72.23076923076923,72.65680473372781,64.709604005462,59.98504954308323,54.602734228762735,57.27923665510693,62.620892554321244,68.2176783151949,58.030343189780304,62.33336731442949,65.05131080451726,66.73572452689922,57.69945921506857,62.20723472044264,64.17535245575915,59.2252982317962,60.11371388844294,57.173142520990176,49.761889825453224,44.10621446769119,41.320643011123316,43.57900562479665,41.182235528674084,44.84650698580115,46.87012129567789,42.27471801941975,49.61706909335518,55.368289232839,60.080860120094535,66.06842010161846,56.365586239831,58.46318835678008,49.62269784035237,46.14228278799047,40.42808543599194,48.36222613814702,51.383422116893634,44.86289563737154];
var verified_ema26results = [81,76.77777777777777,76.64609053497942,72.52415790275873,69.67051657662846,66.36158942280413,66.77924946555937,68.64745320885127,70.89579000819562,65.79239815573669,67.28925755160805,68.2307940292667,68.80629076783954,64.30212108133291,65.98344544567863,66.65133837562836,64.08457257002625,64.15238200928357,62.43739074933664,58.479065508645036,55.11024584133799,52.95393133457221,53.17956605052982,51.314413009749835,52.32816019421281,52.748296476122974,50.10027451492868,53.05580973604507,55.57019420004173,57.82425388892753,60.874309156414384,56.58732329297628,57.58085490090396,53.38968046379996,51.4348893183333,48.29156418364194,51.52922609596476,52.74928342218959,49.50859576128666];
it('should correctly calculate EMAs with weight 10', function() {
var ema = new EMA(10);
_.each(prices, function(p, i) {
ema.update(p);
expect(ema.result).to.equal(verified_ema10results[i]);
});
});
it('should correctly calculate EMAs with weight 12', function() {
var ema = new EMA(12);
_.each(prices, function(p, i) {
ema.update(p);
expect(ema.result).to.equal(verified_ema12results[i]);
});
});
it('should correctly calculate EMAs with weight 26', function() {
var ema = new EMA(26);
_.each(prices, function(p, i) {
ema.update(p);
expect(ema.result).to.equal(verified_ema26results[i]);
});
});
});

+ 100
- 0
test/indicators/macd.js View File

@ -0,0 +1,100 @@
var chai = require('chai');
var expect = chai.expect;
var should = chai.should;
var sinon = require('sinon');
var _ = require('lodash');
var util = require('../../core/util');
var dirs = util.dirs();
var INDICATOR_PATH = dirs.indicators;
// Fake input prices to verify all indicators
// are working correctly by comparing fresh
// calculated results to pre calculated results.
// The precalculated results are already compared
// to MS Excel results, more info here:
//
// https://github.com/askmike/gekko/issues/161
var prices = [81, 24, 75, 21, 34, 25, 72, 92, 99, 2, 86, 80, 76, 8, 87, 75, 32, 65, 41, 9, 13, 26, 56, 28, 65, 58, 17, 90, 87, 86, 99, 3, 70, 1, 27, 9, 92, 68, 9];
describe('indicators/MACD', function() {
var MACD = require(INDICATOR_PATH + 'MACD');
var verified_macd12v26v9diff = [0,-4.547008547008545,-3.9892858012516115,-7.814553897296733,-9.68546703354523,-11.758855194041395,-9.500012810452446,-6.02656065453003,-2.678111693000716,-7.762054965956388,-4.955890237178558,-3.179483224749447,-2.070566240940323,-6.6026618662643415,-3.776210725235984,-2.4759859198692027,-4.859274338230051,-4.038668120840633,-5.264248228346467,-8.717175683191812,-11.004031373646804,-11.633288323448895,-9.600560425733171,-10.13217748107575,-7.4816532084116645,-5.8781751804450835,-7.825556495508927,-3.4387406426898934,-0.20190496720273643,2.256606231167005,5.1941109452040735,-0.2217370531452758,0.8823334558761218,-3.766982623447589,-5.29260653034283,-7.863478747649999,-3.166999957817737,-1.365861305295958,-4.64570012391512];
var verified_macd12v26v9signal = [0,-0.9094017094017091,-1.5253785277716898,-2.7832136016766986,-4.163664288050406,-5.6827024692486034,-6.446164537489373,-6.362243760897504,-5.625417347318147,-6.052744871045796,-5.833373944272349,-5.30259580036777,-4.65618988848228,-5.045484284038693,-4.791629572278152,-4.328500841796362,-4.4346555410831,-4.355458057034607,-4.537216091296979,-5.373208009675945,-6.499372682470117,-7.526155810665873,-7.941036733679333,-8.379264883158616,-8.199742548209226,-7.735429074656398,-7.753454558826904,-6.890511775599502,-5.55279041392015,-3.990911084902719,-2.153906678881361,-1.767472753734144,-1.2375115118120907,-1.7434057341391904,-2.4532458933799184,-3.535292464233935,-3.4616339629506956,-3.0424794314197485,-3.363123569918823];
var verified_macd12v26v9result = [0,-3.6376068376068362,-2.4639072734799217,-5.031340295620034,-5.521802745494824,-6.076152724792792,-3.053848272963074,0.33568310636747434,2.9473056543174314,-1.7093100949105917,0.8774837070937913,2.1231125756183227,2.585623647541957,-1.5571775822256484,1.0154188470421683,1.8525149219271597,-0.42461879714695083,0.3167899361939739,-0.7270321370494885,-3.3439676735158663,-4.504658691176687,-4.107132512783021,-1.6595236920538383,-1.7529125979171347,0.7180893397975616,1.8572538942113148,-0.07210193668202258,3.4517711329096086,5.350885446717413,6.247517316069724,7.3480176240854345,1.5457357005888681,2.1198449676882127,-2.0235768893083987,-2.839360636962912,-4.3281862834160645,0.2946340051329588,1.6766181261237905,-1.2825765539962966];
it('should correctly calculate MACD diffs with 12/26/9', function() {
var macd = new MACD({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
macd.update(p);
expect(macd.diff).to.equal(verified_macd12v26v9diff[i]);
});
});
it('should correctly calculate MACD signals with 12/26/9', function() {
var macd = new MACD({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
macd.update(p);
expect(macd.signal.result).to.equal(verified_macd12v26v9signal[i]);
});
});
it('should correctly calculate MACD results with 12/26/9', function() {
var macd = new MACD({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
macd.update(p);
expect(macd.result).to.equal(verified_macd12v26v9result[i]);
});
});
});
describe('indicators/PPO', function() {
var PPO = require(INDICATOR_PATH + 'PPO');
var verified_ppo12v26v9 = [0,-5.922297673383055,-5.204813152773915,-10.775104631720897,-13.901816018390623,-17.719369436924076,-14.22599518036208,-8.779001074074772,-3.7775327599722406,-11.79779911287454,-7.3650541223130555,-4.659894802610166,-3.0092688006197794,-10.268186733549467,-5.72296687408477,-3.714833010426942,-7.582596159036941,-6.295429716477546,-8.431243146403258,-14.906489369094212,-19.9673059077387,-21.968696242678835,-18.053100351760996,-19.745285752660987,-14.297565938958984,-11.143819939485432,-15.619787658403148,-6.481364924591247,-0.3633332042639952,3.9025254618963814,8.5325172756507,-0.3918493405267646,1.5323382353294481,-7.05563807597937,-10.289915270521151,-16.28333826120637,-6.14602662946988,-2.589345706109427,-9.383623293044062];
var verified_ppo12v26v9signal = [0,-1.184459534676611,-1.9885302582960718,-3.745845132981037,-5.777039310062954,-8.16550533543518,-9.37760330442056,-9.257882858351403,-8.161812838675571,-8.889010093515365,-8.584218899274903,-7.799354079941956,-6.8413370240775215,-7.526706965971911,-7.165958947594484,-6.475733760160976,-6.697106239936169,-6.616770935244445,-6.979665377476208,-8.565030175799809,-10.845485322187589,-13.07012750628584,-14.066722075380872,-15.202434810836897,-15.021461036461314,-14.245932817066137,-14.52070378533354,-12.912836013185082,-10.402935451400865,-7.541843268741416,-4.3269711598629925,-3.539946795995747,-2.5254897897307083,-3.431519446980441,-4.8031986116885825,-7.099226541592141,-6.908586559167689,-6.044738388556036,-6.712515369453642];
var verified_ppo12v26v9hist = [0,-4.737838138706444,-3.2162828944778434,-7.02925949873986,-8.12477670832767,-9.553864101488896,-4.84839187594152,0.47888178427663064,4.3842800787033305,-2.9087890193591743,1.2191647769618479,3.13945927733179,3.832068223457742,-2.7414797675775553,1.4429920735097133,2.760900749734034,-0.8854899191007712,0.32134121876689914,-1.4515777689270495,-6.341459193294403,-9.121820585551113,-8.898568736392996,-3.9863782763801243,-4.54285094182409,0.7238950975023304,3.102112877580705,-1.099083873069608,6.431471088593835,10.03960224713687,11.444368730637798,12.859488435513693,3.1480974554689825,4.057828025060156,-3.6241186289989296,-5.486716658832568,-9.18411171961423,0.762559929697809,3.455392682446609,-2.6711079235904203];
it('should correctly calculate PPOs with 12/26/9', function() {
var ppo = new PPO({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
ppo.update(p);
expect(ppo.ppo).to.equal(verified_ppo12v26v9[i]);
});
});
it('should correctly calculate PPO signals with 12/26/9', function() {
var ppo = new PPO({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
ppo.update(p);
expect(ppo.PPOsignal.result).to.equal(verified_ppo12v26v9signal[i]);
});
});
it('should correctly calculate PPO hists with 12/26/9', function() {
var ppo = new PPO({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
ppo.update(p);
expect(ppo.PPOhist).to.equal(verified_ppo12v26v9hist[i]);
});
});
});
xdescribe('indicators/DEMA', function() {
var DEMA = require(INDICATOR_PATH + 'DEMA');
xit('should correctly calculate DEMAs', function() {
// TODO!
});
});

+ 55
- 0
test/indicators/ppo.js View File

@ -0,0 +1,55 @@
var chai = require('chai');
var expect = chai.expect;
var should = chai.should;
var sinon = require('sinon');
var _ = require('lodash');
var util = require('../../core/util');
var dirs = util.dirs();
var INDICATOR_PATH = dirs.indicators;
// Fake input prices to verify all indicators
// are working correctly by comparing fresh
// calculated results to pre calculated results.
// The precalculated results are already compared
// to MS Excel results, more info here:
//
// https://github.com/askmike/gekko/issues/161
var prices = [81, 24, 75, 21, 34, 25, 72, 92, 99, 2, 86, 80, 76, 8, 87, 75, 32, 65, 41, 9, 13, 26, 56, 28, 65, 58, 17, 90, 87, 86, 99, 3, 70, 1, 27, 9, 92, 68, 9];
describe('indicators/PPO', function() {
var PPO = require(INDICATOR_PATH + 'PPO');
var verified_ppo12v26v9 = [0,-5.922297673383055,-5.204813152773915,-10.775104631720897,-13.901816018390623,-17.719369436924076,-14.22599518036208,-8.779001074074772,-3.7775327599722406,-11.79779911287454,-7.3650541223130555,-4.659894802610166,-3.0092688006197794,-10.268186733549467,-5.72296687408477,-3.714833010426942,-7.582596159036941,-6.295429716477546,-8.431243146403258,-14.906489369094212,-19.9673059077387,-21.968696242678835,-18.053100351760996,-19.745285752660987,-14.297565938958984,-11.143819939485432,-15.619787658403148,-6.481364924591247,-0.3633332042639952,3.9025254618963814,8.5325172756507,-0.3918493405267646,1.5323382353294481,-7.05563807597937,-10.289915270521151,-16.28333826120637,-6.14602662946988,-2.589345706109427,-9.383623293044062];
var verified_ppo12v26v9signal = [0,-1.184459534676611,-1.9885302582960718,-3.745845132981037,-5.777039310062954,-8.16550533543518,-9.37760330442056,-9.257882858351403,-8.161812838675571,-8.889010093515365,-8.584218899274903,-7.799354079941956,-6.8413370240775215,-7.526706965971911,-7.165958947594484,-6.475733760160976,-6.697106239936169,-6.616770935244445,-6.979665377476208,-8.565030175799809,-10.845485322187589,-13.07012750628584,-14.066722075380872,-15.202434810836897,-15.021461036461314,-14.245932817066137,-14.52070378533354,-12.912836013185082,-10.402935451400865,-7.541843268741416,-4.3269711598629925,-3.539946795995747,-2.5254897897307083,-3.431519446980441,-4.8031986116885825,-7.099226541592141,-6.908586559167689,-6.044738388556036,-6.712515369453642];
var verified_ppo12v26v9hist = [0,-4.737838138706444,-3.2162828944778434,-7.02925949873986,-8.12477670832767,-9.553864101488896,-4.84839187594152,0.47888178427663064,4.3842800787033305,-2.9087890193591743,1.2191647769618479,3.13945927733179,3.832068223457742,-2.7414797675775553,1.4429920735097133,2.760900749734034,-0.8854899191007712,0.32134121876689914,-1.4515777689270495,-6.341459193294403,-9.121820585551113,-8.898568736392996,-3.9863782763801243,-4.54285094182409,0.7238950975023304,3.102112877580705,-1.099083873069608,6.431471088593835,10.03960224713687,11.444368730637798,12.859488435513693,3.1480974554689825,4.057828025060156,-3.6241186289989296,-5.486716658832568,-9.18411171961423,0.762559929697809,3.455392682446609,-2.6711079235904203];
it('should correctly calculate PPOs with 12/26/9', function() {
var ppo = new PPO({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
ppo.update(p);
expect(ppo.ppo).to.equal(verified_ppo12v26v9[i]);
});
});
it('should correctly calculate PPO signals with 12/26/9', function() {
var ppo = new PPO({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
ppo.update(p);
expect(ppo.PPOsignal.result).to.equal(verified_ppo12v26v9signal[i]);
});
});
it('should correctly calculate PPO hists with 12/26/9', function() {
var ppo = new PPO({short: 12, long: 26, signal: 9});
_.each(prices, function(p, i) {
ppo.update(p);
expect(ppo.PPOhist).to.equal(verified_ppo12v26v9hist[i]);
});
});
});

+ 1
- 1
test/marketFetcher.js View File

@ -46,7 +46,7 @@ spoofer[util.dirs().budfox + 'tradeBatcher'] = TradeBatcher;
var MarketFetcher = proxyquire(dirs.budfox + 'marketFetcher', spoofer);
describe('marketFetcher', function() {
describe('budfox/marketFetcher', function() {
it('should throw when not passed a config', function() {
expect(function() {
new MarketFetcher();

+ 0
- 0
test/plugins/portfolioManager.js View File


+ 1
- 1
test/tradeBatcher.js View File

@ -23,7 +23,7 @@ var trades_tid_2 = [
{tid: 5, price: 10, amount: 1, date: 1466115797}
];
describe('tradeBatcher', function() {
describe('budfox/tradeBatcher', function() {
var tb;
it('should throw when not passed a number', function() {

Loading…
Cancel
Save