diff --git a/commands/sim.js b/commands/sim.js index 88de36f8b3..c989eefc30 100644 --- a/commands/sim.js +++ b/commands/sim.js @@ -79,7 +79,7 @@ module.exports = function container (get, set, clear) { var engine = get('lib.engine')(s) if (!so.min_periods) so.min_periods = 1 var cursor, reversing, reverse_point - var query_start = so.start ? tb(so.start).resize(so.periodLength).subtract(so.min_periods + 2).toMilliseconds() : null + var query_start = so.start ? tb(so.start).resize(so.period_length).subtract(so.min_periods + 2).toMilliseconds() : null function exitSim () { console.log() diff --git a/commands/trade.js b/commands/trade.js index c145945e6d..74997ea557 100644 --- a/commands/trade.js +++ b/commands/trade.js @@ -112,7 +112,7 @@ module.exports = function container (get, set, clear) { ].join('') + '\n') process.stdout.write([ z(15, (so.mode === 'paper' ? ' ' : (so.mode === 'live' && (so.manual === false || typeof so.manual === 'undefined')) ? ' ' + 'AUTO'.black.bgRed + ' ' : ' ' + 'MANUAL'.black.bgGreen + ' '), ' '), - z(13, so.periodLength, ' '), + z(13, so.period_length, ' '), z(29, (so.order_type === 'maker' ? so.order_type.toUpperCase().green : so.order_type.toUpperCase().red), ' '), z(31, (so.mode === 'paper' ? 'avg. '.grey + so.avg_slippage_pct + '%' : 'max '.grey + so.max_slippage_pct + '%'), ' '), z(20, (so.order_type === 'maker' ? so.order_type + ' ' + s.exchange.makerFee : so.order_type + ' ' + s.exchange.takerFee), ' ') @@ -308,7 +308,7 @@ module.exports = function container (get, set, clear) { } var db_cursor, trade_cursor - var query_start = tb().resize(so.periodLength).subtract(so.min_periods * 2).toMilliseconds() + var query_start = tb().resize(so.period_length).subtract(so.min_periods * 2).toMilliseconds() var days = Math.ceil((new Date().getTime() - query_start) / 86400000) var session = null var sessions = get('db.sessions') diff --git a/commands/train.js b/commands/train.js index 2835884a09..3db11b15ed 100644 --- a/commands/train.js +++ b/commands/train.js @@ -131,13 +131,13 @@ module.exports = function container (get, set, clear) { if (!so.min_periods) so.min_periods = 1 var cursor, reversing, reverse_point - var query_start = so.start_training ? tb(so.start_training).resize(so.periodLength).subtract(so.min_periods + 2).toMilliseconds() : null + var query_start = so.start_training ? tb(so.start_training).resize(so.period_length).subtract(so.min_periods + 2).toMilliseconds() : null function writeTempModel (strategy) { var tempModelString = JSON.stringify( { "selector": so.selector.normalized, - "period": so.periodLength, + "period": so.period_length, "start_training": moment(so.start_training), "end_training": moment(so.end_training), "options": fa_getTrainOptions(so), @@ -159,7 +159,7 @@ module.exports = function container (get, set, clear) { var finalModelString = JSON.stringify( { "selector": so.selector.normalized, - "period": so.periodLength, + "period": so.period_length, "start_training": moment(so.start_training).utc(), "end_training": moment(end_training).utc(), "result_training": trainingResult, @@ -172,7 +172,7 @@ module.exports = function container (get, set, clear) { var testVsBuyHold = typeof(testResult) !== "undefined" ? testResult.vsBuyHold : 'noTest' var finalModelFile = 'models/forex.model_' + so.selector.normalized - + '_period=' + so.periodLength + + '_period=' + so.period_length + '_from=' + moment(so.start_training).utc().format('YYYYMMDD_HHmmssZZ') + '_to=' + moment(end_training).utc().format('YYYYMMDD_HHmmssZZ') + '_trainingVsBuyHold=' + trainingResult.vsBuyHold @@ -234,7 +234,7 @@ module.exports = function container (get, set, clear) { '--modelfile', path.resolve(__dirname, '..', tempModelFile), '--start', so.start_training, '--end', so.end_training, - '--period', so.periodLength, + '--period', so.period_length, '--filename', path.resolve(__dirname, '..', tempModelFile) + '-simTrainingResult.html' ] var trainingSimulation = spawn(path.resolve(__dirname, '..', zenbot_cmd), trainingArgs, { stdio: 'inherit' }) @@ -260,7 +260,7 @@ module.exports = function container (get, set, clear) { '--disable_options', '--modelfile', path.resolve(__dirname, '..', tempModelFile), '--start', so.end_training, - '--period', so.periodLength, + '--period', so.period_length, '--filename', path.resolve(__dirname, '..', tempModelFile) + '-simTestResult.html', ] var testSimulation = spawn(path.resolve(__dirname, '..', zenbot_cmd), testArgs, { stdio: 'inherit' }) diff --git a/extensions/exchanges/bittrex/exchange.js b/extensions/exchanges/bittrex/exchange.js index 8f4bedc6ee..40332b673a 100644 --- a/extensions/exchanges/bittrex/exchange.js +++ b/extensions/exchanges/bittrex/exchange.js @@ -64,7 +64,7 @@ module.exports = function container(get, set, clear) { bittrex_public.getmarkethistory(args, function( data ) { if (!shownWarning) { console.log('please note: the bittrex api does not support backfilling (trade/paper only).') - console.log('please note: make sure to set the --periodLength=1m to make sure data for trade/paper is fetched.') + console.log('please note: make sure to set the --period_length=1m to make sure data for trade/paper is fetched.') shownWarning = true } if (typeof data !== 'object') { diff --git a/extensions/strategies/cci_srsi/strategy.js b/extensions/strategies/cci_srsi/strategy.js index 3eddff6155..5f84cd0496 100644 --- a/extensions/strategies/cci_srsi/strategy.js +++ b/extensions/strategies/cci_srsi/strategy.js @@ -1,107 +1,107 @@ -let z = require('zero-fill') - , n = require('numbro') - -module.exports = function container (get, set, clear) { - return { - name: 'cci_srsi', - description: 'Stochastic CCI Strategy', - - getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '20m') - this.option('periodLength', 'period length, same as --period', String, '20m') - this.option('min_periods', 'min. number of history periods', Number, 30) - this.option('ema_acc', 'sideways threshold (0.2-0.4)', Number, 0.03) - this.option('cci_periods', 'number of RSI periods', Number, 14) - this.option('rsi_periods', 'number of RSI periods', Number, 14) - this.option('srsi_periods', 'number of RSI periods', Number, 9) - this.option('srsi_k', '%K line', Number, 5) - this.option('srsi_d', '%D line', Number, 3) - this.option('oversold_rsi', 'buy when RSI reaches or drops below this value', Number, 18) - this.option('overbought_rsi', 'sell when RSI reaches or goes above this value', Number, 85) - this.option('oversold_cci', 'buy when CCI reaches or drops below this value', Number, -90) - this.option('overbought_cci', 'sell when CCI reaches or goes above this value', Number, 140) - this.option('constant', 'constant', Number, 0.015) - console.log('If you have questions about this strategy, contact me... @talvasconcelos'); - }, - - calculate: function (s) { - //get market trend - get('lib.ema')(s, 'trend_ema', s.options.min_periods) - if (typeof s.period.trend_ema !== 'undefined') - s.trend = s.period.trend_ema > s.lookback[0].trend_ema ? 'up' : 'down' - - // compute Stochastic RSI - get('lib.srsi')(s, 'srsi', s.options.rsi_periods, s.options.srsi_k, s.options.srsi_d) - - // compute CCI - get('lib.cci')(s, 'cci', s.options.cci_periods, s.options.constant) - - if (typeof s.period.cci !== 'undefined' && typeof s.period.srsi_K !== 'undefined') { - s.cci_fromAbove = s.period.cci < s.lookback[0]['cci'] - s.rsi_fromAbove = s.period.srsi_K < s.lookback[0]['srsi_K'] - } - - if (s.period.trend_ema && s.lookback[0] && s.lookback[0].trend_ema) { - s.period.acc = Math.abs((s.period.trend_ema - s.lookback[0].trend_ema) / s.lookback[0].trend_ema * 100) - } - }, - - onPeriod: function (s, cb) { - if (!s.in_preroll && typeof s.trend !== 'undefined') { - - // Sideways Market - if (s.period.acc < s.options.ema_acc) { - // Buy signal - if (s.period.cci <= s.options.oversold_cci && /*s.period.srsi_K > s.period.srsi_D &&*/ s.period.srsi_K <= s.options.oversold_rsi) { - if (!s.cci_fromAbove && !s.rsi_fromAbove) { - s.signal = 'buy' - } - } - // Sell signal - if (s.period.cci >= s.options.overbought_cci && /*s.period.srsi_K < s.period.srsi_D &&*/ s.period.srsi_K >= s.options.overbought_rsi) { - if (s.cci_fromAbove || s.rsi_fromAbove) { - s.signal = 'sell' - } - } - //cb() - } - // Buy signal - if (s.trend === 'up') { - if (s.period.cci <= s.options.oversold_cci && /*s.period.srsi_K > s.period.srsi_D &&*/ s.period.srsi_K <= s.options.oversold_rsi) { - if (!s.cci_fromAbove && !s.rsi_fromAbove) { - s.signal = 'buy' - } - } - } - // Sell signal - if (s.trend === 'down') { - if (s.period.cci >= s.options.overbought_cci && /*s.period.srsi_K < s.period.srsi_D &&*/ s.period.srsi_K >= s.options.overbought_rsi) { - if (s.cci_fromAbove || s.rsi_fromAbove) { - s.signal = 'sell' - } - } - } - } - cb() - }, - onReport: function (s) { - var cols = [] - if (typeof s.period.cci === 'number') { - var color = 'grey' - if (s.period.cci > 0) { - color = 'green' - } - else if (s.period.cci < 0) { - color = 'red' - } - cols.push(z(8, n(s.period.cci).format('000'), ' ')[color]) - cols.push(s.period.acc > s.options.ema_acc ? z(8, n(s.period.srsi_K).format('000'), ' ')[color] : ' --> ') - } - else { - cols.push(' ') - } - return cols - } - } -} -/* Made by talvasconcelos*/ +let z = require('zero-fill') + , n = require('numbro') + +module.exports = function container (get, set, clear) { + return { + name: 'cci_srsi', + description: 'Stochastic CCI Strategy', + + getOptions: function () { + this.option('period', 'period length, same as --period_length', String, '20m') + this.option('period_length', 'period length, same as --period', String, '20m') + this.option('min_periods', 'min. number of history periods', Number, 30) + this.option('ema_acc', 'sideways threshold (0.2-0.4)', Number, 0.03) + this.option('cci_periods', 'number of RSI periods', Number, 14) + this.option('rsi_periods', 'number of RSI periods', Number, 14) + this.option('srsi_periods', 'number of RSI periods', Number, 9) + this.option('srsi_k', '%K line', Number, 5) + this.option('srsi_d', '%D line', Number, 3) + this.option('oversold_rsi', 'buy when RSI reaches or drops below this value', Number, 18) + this.option('overbought_rsi', 'sell when RSI reaches or goes above this value', Number, 85) + this.option('oversold_cci', 'buy when CCI reaches or drops below this value', Number, -90) + this.option('overbought_cci', 'sell when CCI reaches or goes above this value', Number, 140) + this.option('constant', 'constant', Number, 0.015) + console.log('If you have questions about this strategy, contact me... @talvasconcelos'); + }, + + calculate: function (s) { + //get market trend + get('lib.ema')(s, 'trend_ema', s.options.min_periods) + if (typeof s.period.trend_ema !== 'undefined') + s.trend = s.period.trend_ema > s.lookback[0].trend_ema ? 'up' : 'down' + + // compute Stochastic RSI + get('lib.srsi')(s, 'srsi', s.options.rsi_periods, s.options.srsi_k, s.options.srsi_d) + + // compute CCI + get('lib.cci')(s, 'cci', s.options.cci_periods, s.options.constant) + + if (typeof s.period.cci !== 'undefined' && typeof s.period.srsi_K !== 'undefined') { + s.cci_fromAbove = s.period.cci < s.lookback[0]['cci'] + s.rsi_fromAbove = s.period.srsi_K < s.lookback[0]['srsi_K'] + } + + if (s.period.trend_ema && s.lookback[0] && s.lookback[0].trend_ema) { + s.period.acc = Math.abs((s.period.trend_ema - s.lookback[0].trend_ema) / s.lookback[0].trend_ema * 100) + } + }, + + onPeriod: function (s, cb) { + if (!s.in_preroll && typeof s.trend !== 'undefined') { + + // Sideways Market + if (s.period.acc < s.options.ema_acc) { + // Buy signal + if (s.period.cci <= s.options.oversold_cci && /*s.period.srsi_K > s.period.srsi_D &&*/ s.period.srsi_K <= s.options.oversold_rsi) { + if (!s.cci_fromAbove && !s.rsi_fromAbove) { + s.signal = 'buy' + } + } + // Sell signal + if (s.period.cci >= s.options.overbought_cci && /*s.period.srsi_K < s.period.srsi_D &&*/ s.period.srsi_K >= s.options.overbought_rsi) { + if (s.cci_fromAbove || s.rsi_fromAbove) { + s.signal = 'sell' + } + } + //cb() + } + // Buy signal + if (s.trend === 'up') { + if (s.period.cci <= s.options.oversold_cci && /*s.period.srsi_K > s.period.srsi_D &&*/ s.period.srsi_K <= s.options.oversold_rsi) { + if (!s.cci_fromAbove && !s.rsi_fromAbove) { + s.signal = 'buy' + } + } + } + // Sell signal + if (s.trend === 'down') { + if (s.period.cci >= s.options.overbought_cci && /*s.period.srsi_K < s.period.srsi_D &&*/ s.period.srsi_K >= s.options.overbought_rsi) { + if (s.cci_fromAbove || s.rsi_fromAbove) { + s.signal = 'sell' + } + } + } + } + cb() + }, + onReport: function (s) { + var cols = [] + if (typeof s.period.cci === 'number') { + var color = 'grey' + if (s.period.cci > 0) { + color = 'green' + } + else if (s.period.cci < 0) { + color = 'red' + } + cols.push(z(8, n(s.period.cci).format('000'), ' ')[color]) + cols.push(s.period.acc > s.options.ema_acc ? z(8, n(s.period.srsi_K).format('000'), ' ')[color] : ' --> ') + } + else { + cols.push(' ') + } + return cols + } + } +} +/* Made by talvasconcelos*/ diff --git a/extensions/strategies/crossover_vwap/strategy.js b/extensions/strategies/crossover_vwap/strategy.js index 8a508d37e8..72a53f0f07 100644 --- a/extensions/strategies/crossover_vwap/strategy.js +++ b/extensions/strategies/crossover_vwap/strategy.js @@ -19,8 +19,8 @@ module.exports = function container (get, set, clear) { zenbot sim kraken.XXRP-ZEUR --period="120m" --strategy=crossover_vwap --currency_capital=700 --asset_capital=0 --max_slippage_pct=100 --days=60 --avg_slippage_pct=0.045 --vwap_max=8000 --markup_sell_pct=0.5 --markdown_buy_pct=0.5 --emalen1=50 zenbot sim kraken.XXRP-ZEUR --period="120m" --strategy=crossover_vwap --currency_capital=700 --asset_capital=0 --max_slippage_pct=100 --days=60 --avg_slippage_pct=0.045 --vwap_max=8000 --markup_sell_pct=0.5 --markdown_buy_pct=0.5 --emalen1=30 */ - this.option('period', 'period length, same as --periodLength', String, '120m') - this.option('periodLength', 'period length, same as --period', String, '120m') + this.option('period', 'period length, same as --period_length', String, '120m') + this.option('period_length', 'period length, same as --period', String, '120m') this.option('emalen1', 'Length of EMA 1', Number, 30 )//green this.option('smalen1', 'Length of SMA 1', Number, 108 )//red this.option('smalen2', 'Length of SMA 2', Number, 60 )//purple diff --git a/extensions/strategies/forex_analytics/strategy.js b/extensions/strategies/forex_analytics/strategy.js index f3c0102538..16d59098bc 100644 --- a/extensions/strategies/forex_analytics/strategy.js +++ b/extensions/strategies/forex_analytics/strategy.js @@ -11,8 +11,8 @@ module.exports = function container (get, set, clear) { getOptions: function (s) { this.option('modelfile', 'modelfile (generated by running `train`), should be in models/', String, 'none') - this.option('period', 'period length of a candlestick (default: 30m), same as --periodLength', String, '30m') - this.option('periodLength', 'period length of a candlestick (default: 30m), same as --period', String, '30m') + this.option('period', 'period length of a candlestick (default: 30m), same as --period_length', String, '30m') + this.option('period_length', 'period length of a candlestick (default: 30m), same as --period', String, '30m') this.option('min_periods', 'min. number of history periods', Number, 100) if (s.options) { @@ -85,4 +85,4 @@ module.exports = function container (get, set, clear) { return cols } } -} \ No newline at end of file +} diff --git a/extensions/strategies/macd/strategy.js b/extensions/strategies/macd/strategy.js index 9f77c16be9..79bb69ddd9 100644 --- a/extensions/strategies/macd/strategy.js +++ b/extensions/strategies/macd/strategy.js @@ -7,8 +7,8 @@ module.exports = function container (get, set, clear) { description: 'Buy when (MACD - Signal > 0) and sell when (MACD - Signal < 0).', getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '1h') - this.option('periodLength', 'period length, same as --period', String, '1h') + this.option('period', 'period length, same as --period_length', String, '1h') + this.option('period_length', 'period length, same as --period', String, '1h') this.option('min_periods', 'min. number of history periods', Number, 52) this.option('ema_short_period', 'number of periods for the shorter EMA', Number, 12) this.option('ema_long_period', 'number of periods for the longer EMA', Number, 26) @@ -83,4 +83,4 @@ module.exports = function container (get, set, clear) { return cols } } -} \ No newline at end of file +} diff --git a/extensions/strategies/neural/strategy.js b/extensions/strategies/neural/strategy.js index f3ad05561b..7dd8e4dd46 100644 --- a/extensions/strategies/neural/strategy.js +++ b/extensions/strategies/neural/strategy.js @@ -14,8 +14,8 @@ module.exports = function container (get, set, clear) { name: 'neural', description: 'Use neural learning to predict future price. Buy = mean(last 3 real prices) < mean(current & last prediction)', getOptions: function () { - this.option('period', 'period length - make sure to lower your poll trades time to lower than this value. Same as --periodLength', String, '1m') - this.option('periodLength', 'period length - make sure to lower your poll trades time to lower than this value. Same as --period', String, '1m') + this.option('period', 'period length - make sure to lower your poll trades time to lower than this value. Same as --period_length', String, '1m') + this.option('period_length', 'period length - make sure to lower your poll trades time to lower than this value. Same as --period', String, '1m') this.option('activation_1_type', "Neuron Activation Type: sigmoid, tanh, relu", String, 'sigmoid') this.option('neurons_1', "Neurons in layer 1 Shoot for atleast 100", Number, 1) this.option('depth', "Rows of data to predict ahead for matches/learning", Number, 1) diff --git a/extensions/strategies/noop/strategy.js b/extensions/strategies/noop/strategy.js index c2d216acd0..27d99f5d71 100644 --- a/extensions/strategies/noop/strategy.js +++ b/extensions/strategies/noop/strategy.js @@ -4,8 +4,8 @@ module.exports = function container (get, set, clear) { description: 'Just do nothing. Can be used to e.g. generate candlesticks for training the genetic forex strategy.', getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '30m') - this.option('periodLength', 'period length, same as --period', String, '30m') + this.option('period', 'period length, same as --period_length', String, '30m') + this.option('period_length', 'period length, same as --period', String, '30m') }, calculate: function (s) { diff --git a/extensions/strategies/rsi/strategy.js b/extensions/strategies/rsi/strategy.js index 571363f88b..8dfa8b4330 100644 --- a/extensions/strategies/rsi/strategy.js +++ b/extensions/strategies/rsi/strategy.js @@ -7,8 +7,8 @@ module.exports = function container (get, set, clear) { description: 'Attempts to buy low and sell high by tracking RSI high-water readings.', getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '2m') - this.option('periodLength', 'period length, same as --period', String, '2m') + this.option('period', 'period length, same as --period_length', String, '2m') + this.option('period_length', 'period length, same as --period', String, '2m') this.option('min_periods', 'min. number of history periods', Number, 52) this.option('rsi_periods', 'number of RSI periods', 14) this.option('oversold_rsi', 'buy when RSI reaches or drops below this value', Number, 30) @@ -71,4 +71,4 @@ module.exports = function container (get, set, clear) { return cols } } -} \ No newline at end of file +} diff --git a/extensions/strategies/sar/strategy.js b/extensions/strategies/sar/strategy.js index 2c44af523d..c8e64fde04 100644 --- a/extensions/strategies/sar/strategy.js +++ b/extensions/strategies/sar/strategy.js @@ -7,8 +7,8 @@ module.exports = function container (get, set, clear) { description: 'Parabolic SAR', getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '2m') - this.option('periodLength', 'period length, same as --period', String, '2m') + this.option('period', 'period length, same as --period_length', String, '2m') + this.option('period_length', 'period length, same as --period', String, '2m') this.option('min_periods', 'min. number of history periods', Number, 52) this.option('sar_af', 'acceleration factor for parabolic SAR', Number, 0.015) this.option('sar_max_af', 'max acceleration factor for parabolic SAR', Number, 0.3) diff --git a/extensions/strategies/speed/strategy.js b/extensions/strategies/speed/strategy.js index 2fc7980aca..d89f3881fe 100644 --- a/extensions/strategies/speed/strategy.js +++ b/extensions/strategies/speed/strategy.js @@ -7,8 +7,8 @@ module.exports = function container (get, set, clear) { description: 'Trade when % change from last two 1m periods is higher than average.', getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '1m') - this.option('periodLength', 'period length, same as --period', String, '1m') + this.option('period', 'period length, same as --period_length', String, '1m') + this.option('period_length', 'period length, same as --period', String, '1m') this.option('min_periods', 'min. number of history periods', Number, 3000) this.option('baseline_periods', 'lookback periods for volatility baseline', Number, 3000) this.option('trigger_factor', 'multiply with volatility baseline EMA to get trigger value', Number, 1.6) @@ -53,4 +53,4 @@ module.exports = function container (get, set, clear) { return cols } } -} \ No newline at end of file +} diff --git a/extensions/strategies/srsi_macd/strategy.js b/extensions/strategies/srsi_macd/strategy.js index 18828e403c..c184fcba42 100644 --- a/extensions/strategies/srsi_macd/strategy.js +++ b/extensions/strategies/srsi_macd/strategy.js @@ -7,8 +7,8 @@ module.exports = function container (get, set, clear) { description: 'Stochastic MACD Strategy', getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '30m') - this.option('periodLength', 'period length, same as --period', String, '30m') + this.option('period', 'period length, same as --period_length', String, '30m') + this.option('period_length', 'period length, same as --period', String, '30m') this.option('min_periods', 'min. number of history periods', Number, 200) this.option('rsi_periods', 'number of RSI periods', 14) this.option('srsi_periods', 'number of RSI periods', Number, 9) diff --git a/extensions/strategies/stddev/strategy.js b/extensions/strategies/stddev/strategy.js index 1a1b1e58d8..cdd7cd899c 100644 --- a/extensions/strategies/stddev/strategy.js +++ b/extensions/strategies/stddev/strategy.js @@ -7,8 +7,8 @@ module.exports = function container (get, set, clear) { name: 'stddev', description: 'Buy when standard deviation and mean increase, sell on mean decrease.', getOptions: function () { - this.option('period', 'period length, set poll trades to 100ms, poll order 1000ms. Same as --periodLength', String, '100ms') - this.option('periodLength', 'period length, set poll trades to 100ms, poll order 1000ms. Same as --period', String, '100ms') + this.option('period', 'period length, set poll trades to 100ms, poll order 1000ms. Same as --period_length', String, '100ms') + this.option('period_length', 'period length, set poll trades to 100ms, poll order 1000ms. Same as --period', String, '100ms') this.option('trendtrades_1', "Trades for array 1 to be subtracted stddev and mean from", Number, 5) this.option('trendtrades_2', "Trades for array 2 to be calculated stddev and mean from", Number, 53) this.option('min_periods', "min_periods", Number, 1250) diff --git a/extensions/strategies/ta_ema/strategy.js b/extensions/strategies/ta_ema/strategy.js index 081c24d914..48b9f5a749 100644 --- a/extensions/strategies/ta_ema/strategy.js +++ b/extensions/strategies/ta_ema/strategy.js @@ -7,8 +7,8 @@ module.exports = function container (get, set, clear) { description: 'Buy when (EMA - last(EMA) > 0) and sell when (EMA - last(EMA) < 0). Optional buy on low RSI.', getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '10m') - this.option('periodLength', 'period length, same as --period', String, '10m') + this.option('period', 'period length, same as --period_length', String, '10m') + this.option('period_length', 'period length, same as --period', String, '10m') this.option('min_periods', 'min. number of history periods', Number, 52) this.option('trend_ema', 'number of periods for trend EMA', Number, 20) this.option('neutral_rate', 'avoid trades if abs(trend_ema) under this float (0 to disable, "auto" for a variable filter)', Number, 0.06) diff --git a/extensions/strategies/ta_macd/strategy.js b/extensions/strategies/ta_macd/strategy.js index 1cb20e28bd..7f9a44f87d 100644 --- a/extensions/strategies/ta_macd/strategy.js +++ b/extensions/strategies/ta_macd/strategy.js @@ -7,8 +7,8 @@ module.exports = function container (get, set, clear) { description: 'Buy when (MACD - Signal > 0) and sell when (MACD - Signal < 0).', getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '1h') - this.option('periodLength', 'period length, same as --period', String, '1h') + this.option('period', 'period length, same as --period_length', String, '1h') + this.option('period_length', 'period length, same as --period', String, '1h') this.option('min_periods', 'min. number of history periods', Number, 52) this.option('ema_short_period', 'number of periods for the shorter EMA', Number, 12) this.option('ema_long_period', 'number of periods for the longer EMA', Number, 26) diff --git a/extensions/strategies/trend_ema/strategy.js b/extensions/strategies/trend_ema/strategy.js index fd282abbaf..6acbcad0a9 100644 --- a/extensions/strategies/trend_ema/strategy.js +++ b/extensions/strategies/trend_ema/strategy.js @@ -7,8 +7,8 @@ module.exports = function container (get, set, clear) { description: 'Buy when (EMA - last(EMA) > 0) and sell when (EMA - last(EMA) < 0). Optional buy on low RSI.', getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '2m') - this.option('periodLength', 'period length, same as --period', String, '2m') + this.option('period', 'period length, same as --period_length', String, '2m') + this.option('period_length', 'period length, same as --period', String, '2m') this.option('min_periods', 'min. number of history periods', Number, 52) this.option('trend_ema', 'number of periods for trend EMA', Number, 26) this.option('neutral_rate', 'avoid trades if abs(trend_ema) under this float (0 to disable, "auto" for a variable filter)', Number, 'auto') diff --git a/extensions/strategies/trendline/strategy.js b/extensions/strategies/trendline/strategy.js index f34bbfa023..1b20bffe0a 100644 --- a/extensions/strategies/trendline/strategy.js +++ b/extensions/strategies/trendline/strategy.js @@ -11,7 +11,7 @@ module.exports = function container (get, set, clear) { getOptions: function () { this.option('period', 'period length', String, '30s') - this.option('periodLength', 'period length', String, '30s') + this.option('period_length', 'period length', String, '30s') this.option('lastpoints', "Number of trades for short trend average", Number, 100) this.option('avgpoints', "Number of trades for long trend average", Number, 1000) this.option('lastpoints2', "Number of trades for short trend average", Number, 10) @@ -100,4 +100,4 @@ module.exports = function container (get, set, clear) { return cols }, } -} \ No newline at end of file +} diff --git a/extensions/strategies/trust_distrust/strategy.js b/extensions/strategies/trust_distrust/strategy.js index caed23be31..dab2824f32 100644 --- a/extensions/strategies/trust_distrust/strategy.js +++ b/extensions/strategies/trust_distrust/strategy.js @@ -7,8 +7,8 @@ module.exports = function container (get, set, clear) { description: 'Sell when price higher than $sell_min% and highest point - $sell_threshold% is reached. Buy when lowest price point + $buy_threshold% reached.', getOptions: function () { - this.option('period', 'period length, same as --periodLength', String, '30m') - this.option('periodLength', 'period length, same as --period', String, '30m') + this.option('period', 'period length, same as --period_length', String, '30m') + this.option('period_length', 'period length, same as --period', String, '30m') this.option('min_periods', 'min. number of history periods', Number, 52) this.option('sell_threshold', 'sell when the top drops at least below this percentage', Number, 2) this.option('sell_threshold_max', 'sell when the top drops lower than this max, regardless of sell_min (panic sell, 0 to disable)', Number, 0) diff --git a/lib/engine.js b/lib/engine.js index 731cde592c..6ded4cd1a4 100644 --- a/lib/engine.js +++ b/lib/engine.js @@ -19,10 +19,10 @@ module.exports = function container (get, set, clear) { s.asset = so.selector.asset s.currency = so.selector.currency - if (typeof so.periodLength == 'undefined') - so.periodLength = so.period + if (typeof so.period_length == 'undefined') + so.period_length = so.period else - so.period = so.periodLength + so.period = so.period_length var products = s.exchange.getProducts() products.forEach(function (product) { @@ -123,10 +123,10 @@ module.exports = function container (get, set, clear) { } function initBuffer (trade) { - var d = tb(trade.time).resize(so.periodLength) + var d = tb(trade.time).resize(so.period_length) s.period = { period_id: d.toString(), - size: so.periodLength, + size: so.period_length, time: d.toMilliseconds(), open: trade.price, high: trade.price, @@ -688,7 +688,7 @@ module.exports = function container (get, set, clear) { } readline.clearLine(process.stdout) readline.cursorTo(process.stdout, 0) - process.stdout.write(moment(is_progress ? s.period.close_time : tb(s.period.time).resize(so.periodLength).add(1).toMilliseconds()).format('YYYY-MM-DD HH:mm:ss')[is_progress && !blink_off ? 'bgBlue' : 'grey']) + process.stdout.write(moment(is_progress ? s.period.close_time : tb(s.period.time).resize(so.period_length).add(1).toMilliseconds()).format('YYYY-MM-DD HH:mm:ss')[is_progress && !blink_off ? 'bgBlue' : 'grey']) process.stdout.write(' ' + fc(s.period.close, true, true, true) + ' ' + s.product_id.grey) if (s.lookback[0]) { var diff = (s.period.close - s.lookback[0].close) / s.lookback[0].close @@ -800,7 +800,7 @@ module.exports = function container (get, set, clear) { if (s.period && trade.time < s.period.time) { return done() } - var period_id = tb(trade.time).resize(so.periodLength).toString() + var period_id = tb(trade.time).resize(so.period_length).toString() var day = tb(trade.time).resize('1d') if (s.last_day && s.last_day.toString() && day.toString() !== s.last_day.toString()) { s.day_count++ diff --git a/scripts/auto_backtester/backtester.js b/scripts/auto_backtester/backtester.js index 7d4b3bf914..8f21a1ab80 100755 --- a/scripts/auto_backtester/backtester.js +++ b/scripts/auto_backtester/backtester.js @@ -82,7 +82,7 @@ let runCommand = (strategy, cb) => { trend_ema: `--trend_ema=${strategy.trend_ema} --oversold_rsi=${strategy.oversold_rsi} --oversold_rsi_periods=${strategy.oversold_rsi_periods} --neutral_rate=${strategy.neutral_rate}` }; let zenbot_cmd = process.platform === 'win32' ? 'zenbot.bat' : './zenbot.sh'; // Use 'win32' for 64 bit windows too - let command = `${zenbot_cmd} sim ${simArgs} ${strategyArgs[strategyName]} --periodLength=${strategy.periodLength} --min_periods=${strategy.min_periods}`; + let command = `${zenbot_cmd} sim ${simArgs} ${strategyArgs[strategyName]} --period_length=${strategy.period_length} --min_periods=${strategy.min_periods}`; console.log(`[ ${countArr.length}/${strategies[strategyName].length} ] ${command}`); shell.exec(command, {silent:true, async:true}, (code, stdout, stderr) => { @@ -189,7 +189,7 @@ let processOutput = output => { oversoldRsi: params.oversold_rsi, days: days, - periodLength: params.periodLength, + period_length: params.period_length, min_periods: params.min_periods, roi: roi, wlRatio: losses > 0 ? roundp(wins / losses, 3) : 'Infinity', @@ -199,7 +199,7 @@ let processOutput = output => { let strategies = { cci_srsi: objectProduct({ - periodLength: ['20m'], + period_length: ['20m'], min_periods: [52, 200], rsi_periods: [14, 20], srsi_periods: [14, 20], @@ -212,7 +212,7 @@ let strategies = { constant: [0.015] }), srsi_macd: objectProduct({ - periodLength: ['30m'], + period_length: ['30m'], min_periods: [52, 200], rsi_periods: [14, 20], srsi_periods: [14, 20], @@ -227,7 +227,7 @@ let strategies = { down_trend_threshold: [0] }), macd: objectProduct({ - periodLength: ['1h'], + period_length: ['1h'], min_periods: [52], ema_short_period: range(10, 15), ema_long_period: range(20, 30), @@ -238,7 +238,7 @@ let strategies = { overbought_rsi: range(70, 70) }), rsi: objectProduct({ - periodLength: ['2m'], + period_length: ['2m'], min_periods: [52], rsi_periods: range(10, 30), oversold_rsi: range(20, 35), @@ -248,19 +248,19 @@ let strategies = { rsi_divisor: range(2, 2) }), sar: objectProduct({ - periodLength: ['2m'], + period_length: ['2m'], min_periods: [52], sar_af: range(0.01, 0.055, 0.005), sar_max_af: range(0.1, 0.55, 0.05) }), speed: objectProduct({ - periodLength: ['1m'], + period_length: ['1m'], min_periods: [52], baseline_periods: range(1000, 5000, 200), trigger_factor: range(1.0, 2.0, 0.1) }), trend_ema: objectProduct({ - periodLength: ['2m'], + period_length: ['2m'], min_periods: [52], trend_ema: range(TREND_EMA_MIN, TREND_EMA_MAX), neutral_rate: (NEUTRAL_RATE_AUTO ? new Array('auto') : []).concat(range(NEUTRAL_RATE_MIN, NEUTRAL_RATE_MAX).map(r => r / 100)), diff --git a/scripts/auto_backtester/backtester_trust_distrust.js b/scripts/auto_backtester/backtester_trust_distrust.js index 0c4f9f738b..68523f8006 100644 --- a/scripts/auto_backtester/backtester_trust_distrust.js +++ b/scripts/auto_backtester/backtester_trust_distrust.js @@ -8,7 +8,7 @@ * EMA Parameters: "trend_ema", "neutral_rate" * RSI Parameters: "oversold_rsi", "oversold_rsi_periods" * - * Example: ./backtester.js gdax.ETH-USD --days=10 --currency_capital=5 --periodLength=1m + * Example: ./backtester.js gdax.ETH-USD --days=10 --currency_capital=5 --period_length=1m */ let shell = require('shelljs'); @@ -67,7 +67,7 @@ let objectProduct = obj => { let runCommand = (strategy, cb) => { countArr.push(1); - let command = `./zenbot.sh sim ${simArgs} --strategy=trust_distrust --periodLength=${strategy.periodLength}m --sell_threshold=${strategy.sell_threshold} --sell_threshold_max=${strategy.sell_threshold_max} --sell_min=${strategy.sell_min} --buy_threshold=${strategy.buy_threshold} --days=30`; + let command = `./zenbot.sh sim ${simArgs} --strategy=trust_distrust --period_length=${strategy.period_length}m --sell_threshold=${strategy.sell_threshold} --sell_threshold_max=${strategy.sell_threshold_max} --sell_min=${strategy.sell_min} --buy_threshold=${strategy.buy_threshold} --days=30`; console.log(`[ ${countArr.length}/${strategies.length} ] ${command}`); shell.exec(command, {silent:true, async:true}, (code, stdout, stderr) => { @@ -114,7 +114,7 @@ let processOutput = output => { sellMin: params.sell_min, buyThreshold: params.buy_threshold, days: days, - periodLength: params.periodLength, + period_length: params.period_length, roi: roi, wlRatio: losses > 0 ? roundp(wins / losses, 3) : 'Infinity', frequency: roundp((wins + losses) / days, 3) @@ -126,7 +126,7 @@ let strategies = objectProduct({ sell_threshold_max: range(SELL_THRESHOLD_MAX_MIN, SELL_THRESHOLD_MAX_MAX), sell_min: range(SELL_MIN_MIN, SELL_MIN_MAX), buy_threshold: range(BUY_THRESHOLD_MIN, BUY_THRESHOLD_MAX), - periodLength: range(PERIOD_MIN, PERIOD_MAX) + period_length: range(PERIOD_MIN, PERIOD_MAX) }); let tasks = strategies.map(strategy => { diff --git a/scripts/genetic_backtester/darwin.js b/scripts/genetic_backtester/darwin.js index f99a7afc36..49a9fd9a25 100755 --- a/scripts/genetic_backtester/darwin.js +++ b/scripts/genetic_backtester/darwin.js @@ -39,7 +39,7 @@ let NEUTRAL_RATE_AUTO = false; let iterationCount = 0; let runCommand = (taskStrategyName, phenotype, cb) => { - let commonArgs = `--strategy=${taskStrategyName} --periodLength=${phenotype.periodLength} --min_periods=${phenotype.min_periods} --markup_pct=${phenotype.markup_pct} --order_type=${phenotype.order_type} --sell_stop_pct=${phenotype.sell_stop_pct} --buy_stop_pct=${phenotype.buy_stop_pct} --profit_stop_enable_pct=${phenotype.profit_stop_enable_pct} --profit_stop_pct=${phenotype.profit_stop_pct}`; + let commonArgs = `--strategy=${taskStrategyName} --period_length=${phenotype.period_length} --min_periods=${phenotype.min_periods} --markup_pct=${phenotype.markup_pct} --order_type=${phenotype.order_type} --sell_stop_pct=${phenotype.sell_stop_pct} --buy_stop_pct=${phenotype.buy_stop_pct} --profit_stop_enable_pct=${phenotype.profit_stop_enable_pct} --profit_stop_pct=${phenotype.profit_stop_pct}`; let strategyArgs = { crossover_vwap: `--emalen1=${phenotype.emalen1} --vwap_length=${phenotype.vwap_length} --vwap_max=${phenotype.vwap_max} --markdown_buy_pct=${phenotype.markdown_buy_pct} --markup_sell_pct=${phenotype.markup_sell_pct}`, trendline: `--lastpoints=${phenotype.lastpoints} --avgpoints=${phenotype.avgpoints} --lastpoints2=${phenotype.lastpoints2} --avgpoints2=${phenotype.avgpoints2} --markdown_buy_pct=${phenotype.markdown_buy_pct} --markup_sell_pct=${phenotype.markup_sell_pct}`, @@ -149,7 +149,7 @@ let processOutput = output => { losses: losses, errorRate: parseFloat(errorRate), days: days, - periodLength: params.periodLength, + period_length: params.period_length, min_periods: params.min_periods, markup_pct: params.markup_pct, order_type: params.order_type, @@ -199,12 +199,12 @@ let RangeFloat = (min, max) => { return r; }; -let RangePeriod = (min, max, periodLength) => { +let RangePeriod = (min, max, period_length) => { var r = { - type: 'periodLength', + type: 'period_length', min: min, max: max, - periodLength: periodLength + period_length: period_length }; return r; }; @@ -226,7 +226,7 @@ let RangeNeuralActivation = () => { let strategies = { crossover_vwap: { // -- common - periodLength: RangePeriod(1, 400, 'm'), + period_length: RangePeriod(1, 400, 'm'), min_periods: Range(1, 200), markdown_buy_pct: RangeFloat(-1, 5), markup_sell_pct: RangeFloat(-1, 5), @@ -243,7 +243,7 @@ let strategies = { }, cci_srsi: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(1, 200), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -266,7 +266,7 @@ let strategies = { }, srsi_macd: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(1, 200), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -290,7 +290,7 @@ let strategies = { }, macd: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(1, 200), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -310,7 +310,7 @@ let strategies = { }, neural: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(1, 200), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -329,7 +329,7 @@ let strategies = { }, rsi: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(1, 200), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -348,7 +348,7 @@ let strategies = { }, sar: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(2, 100), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -363,7 +363,7 @@ let strategies = { }, speed: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(1, 100), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -378,7 +378,7 @@ let strategies = { }, trend_ema: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(1, 100), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -394,7 +394,7 @@ let strategies = { }, trust_distrust: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(1, 100), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -413,7 +413,7 @@ let strategies = { }, ta_macd: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(1, 200), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -434,7 +434,7 @@ let strategies = { }, trendline: { // -- common - periodLength: RangePeriod(1, 400, 'm'), + period_length: RangePeriod(1, 400, 'm'), min_periods: Range(1, 200), markdown_buy_pct: RangeFloat(-1, 5), markup_sell_pct: RangeFloat(-1, 5), @@ -452,7 +452,7 @@ let strategies = { }, ta_ema: { // -- common - periodLength: RangePeriod(1, 120, 'm'), + period_length: RangePeriod(1, 120, 'm'), min_periods: Range(1, 100), markup_pct: RangeFloat(0, 5), order_type: RangeMakerTaker(), @@ -613,7 +613,7 @@ let simulateGeneration = () => { results.sort((a, b) => (a.fitness < b.fitness) ? 1 : ((b.fitness < a.fitness) ? -1 : 0)); - let fieldsGeneral = ['selector', 'fitness', 'vsBuyHold', 'wlRatio', 'frequency', 'strategy', 'order_type', 'endBalance', 'buyHold', 'wins', 'losses', 'periodLength', 'min_periods', 'days', 'params']; + let fieldsGeneral = ['selector', 'fitness', 'vsBuyHold', 'wlRatio', 'frequency', 'strategy', 'order_type', 'endBalance', 'buyHold', 'wins', 'losses', 'period_length', 'min_periods', 'days', 'params']; let fieldNamesGeneral = ['Selector', 'Fitness', 'VS Buy Hold (%)', 'Win/Loss Ratio', '# Trades/Day', 'Strategy', 'Order Type', 'Ending Balance ($)', 'Buy Hold ($)', '# Wins', '# Losses', 'Period', 'Min Periods', '# Days', 'Full Parameters']; let dataCSV = json2csv({ diff --git a/scripts/genetic_backtester/phenotype.js b/scripts/genetic_backtester/phenotype.js index 54ac1beac2..71cfd72592 100644 --- a/scripts/genetic_backtester/phenotype.js +++ b/scripts/genetic_backtester/phenotype.js @@ -31,9 +31,9 @@ module.exports = { var items = ['sigmoid', 'tanh', 'relu']; var index = Math.floor(Math.random() * items.length); r[k] = items[index]; - } else if (v.type === 'periodLength') { + } else if (v.type === 'period_length') { var s = Math.floor((Math.random() * (v.max - v.min + 1)) + v.min); - r[k] = s + v.periodLength; + r[k] = s + v.period_length; } } return r;