forked from askmike/gekko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gekko-backtest.js
109 lines (78 loc) · 2.93 KB
/
gekko-backtest.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
Gekko is a Bitcoin trading bot for Mt. Gox written
in node, it features multiple trading methods using
technical analysis.
Disclaimer:
USE AT YOUR OWN RISK!
The author of this project is NOT responsible for any damage or loss caused
by this software. There can be bugs and the bot may not perform as expected
or specified. Please consider testing it first with paper trading /
backtesting on historical data. Also look at the code to see what how
it's working.
*/
// helpers
var moment = require('moment');
var _ = require('lodash');
var util = require('./util');
var log = require('./log');
var async = require('async');
var Manager = require('./portfolioManager');
var config = util.getConfig();
// function range1(i){return i?range1(i-1).concat(i):[]}
// var short = range1(26);
// var long = range1(30);
// var sellTreshold = [-0.30,-0.25,-0.20,-0.15,-0.10,-0.05];
// var buyTreshold = [0.30,0.25,0.20,0.15,0.10,0.05];
// options = [short, long, sellTreshold, buyTreshold]
// function range1(i){return i?range1(i-1).concat(i):[]}
// var recursiveSearch;
// var possibilities = [];
// recursiveSearch = function (text, depth )
// {
// text = text || "";
// depth = depth || 0;
// for ( var i = 0; i < options[depth].length; i++ )
// {
// // is there one more layer?
// if ( depth +1 < options.length )
// // yes: iterate the layer
// recursiveSearch ( text + ((text=="") ? "" : ",") + options[depth][i] , depth +1 );
// else
// // no: this is the last layer. we add the result to the array
// possibilities.push ( text + "," + options[depth][i] );
// }
// }
// recursiveSearch ( );
// log.info(possibilities)
//log.info(short)
// process.argv.forEach(function (val, index, array) {
// console.log(index + ': ' + val);
// });
// config.EMA.short = process.argv[2];
// config.EMA.long = process.argv[3];
// config.EMA.sellTreshold = process.argv[4];
// config.EMA.buyTreshold = process.argv[5];
// overwrite the watcher in case of normal setup
if(config.normal.enabled)
config.watch = config.normal;
// set backtesting reminder
config.backtest.enabled = true;
// set updated config
util.setConfig(config);
//process.stdout.write(str(config);
if(config.talib)
var Consultant = require('./methods/talib');
else
var Consultant = require('./methods/' + config.tradingMethod.toLowerCase().split(' ').join('-'));
// log.info('I\'m gonna make you rich, Bud Fox.');
// log.info('Let me show you some ' + config.tradingMethod + '.\n\n');
// log.info('Preparing backtester to test strategy against historical data.');
// implement a trading method to create a consultant.
var consultant = new Consultant();
var Logger = require('./logger');
var logger = new Logger(_.extend(config.profitCalculator, config.watch));
consultant.on('advice', logger.inform);
if(config.profitCalculator.enabled)
consultant.on('advice', logger.trackProfits);
consultant.on('finish', logger.finish);
consultant.emit('prepare');