Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
rename periodLength to period_length (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
FunFR authored and DeviaVir committed Jan 4, 2018
1 parent 860dfc5 commit fccae8e
Show file tree
Hide file tree
Showing 25 changed files with 192 additions and 192 deletions.
2 changes: 1 addition & 1 deletion commands/sim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions commands/trade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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), ' ')
Expand Down Expand Up @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions commands/train.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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' })
Expand All @@ -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' })
Expand Down
2 changes: 1 addition & 1 deletion extensions/exchanges/bittrex/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
214 changes: 107 additions & 107 deletions extensions/strategies/cci_srsi/strategy.js
Original file line number Diff line number Diff line change
@@ -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*/
4 changes: 2 additions & 2 deletions extensions/strategies/crossover_vwap/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions extensions/strategies/forex_analytics/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -85,4 +85,4 @@ module.exports = function container (get, set, clear) {
return cols
}
}
}
}
6 changes: 3 additions & 3 deletions extensions/strategies/macd/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -83,4 +83,4 @@ module.exports = function container (get, set, clear) {
return cols
}
}
}
}
4 changes: 2 additions & 2 deletions extensions/strategies/neural/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions extensions/strategies/noop/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions extensions/strategies/rsi/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -71,4 +71,4 @@ module.exports = function container (get, set, clear) {
return cols
}
}
}
}
Loading

0 comments on commit fccae8e

Please sign in to comment.