Skip to content

Commit

Permalink
Add strategy: forex.analytics, an genetic optimization algorithm for …
Browse files Browse the repository at this point in the history
…TA-lib stats (DeviaVir#389)

* Add a 'noop' strategy, which just does nothing. Can be used to generate e.g. candlestick data for model training.

* - Add option to `sim` to disable output of option
- Add option to `sim` to disable writing HTML results

* Add forex_analytics training, simulation and strategy (see https://github.com/mkmarek/forex.analytics and DeviaVir#385)

* - .gitignore trained models
- Limit width of progressbar in training to 80 cols

* - Added timezone to datetime displays
- Fixed hang when not using a test dataset
- Changed default indicators

* Windows fixes for sim spawn

* Write a final model including sim results (output while training less pretty)

* Made train pretty again. Also write simulation Results as HTML files in models/

* Speed up parseSimulation()

* Properly name simulation result HTML files after training

* - Use the defaults of the forex.analytics project for training
- Add a check for unknown indicators

* forex_analytics documentation

* !!! -> !
  • Loading branch information
crubb authored and DeviaVir committed Jul 27, 2017
1 parent 6816119 commit 4973c24
Show file tree
Hide file tree
Showing 13 changed files with 633 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ conf_*
sim_result*
*_test
backtesting_*
models/*.json
models/*.html
2 changes: 2 additions & 0 deletions commands/_codemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
'list-strategies': require('./list-strategies'),
'backfill': require('./backfill'),
'sim': require('./sim'),
'train': require('./train'),
'balance': require('./balance'),
'trade': require('./trade'),
'buy': require('./buy'),
Expand All @@ -15,6 +16,7 @@ module.exports = {
'list[30]': '#commands.list-strategies',
'list[50]': '#commands.backfill',
'list[60]': '#commands.sim',
'list[62]': '#commands.train',
'list[65]': '#commands.balance',
'list[70]': '#commands.trade',
'list[80]': '#commands.buy',
Expand Down
18 changes: 12 additions & 6 deletions commands/sim.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function container (get, set, clear) {
.option('--conf <path>', 'path to optional conf overrides file')
.option('--strategy <name>', 'strategy to use', String, c.strategy)
.option('--order_type <type>', 'order type to use (maker/taker)', /^(maker|taker)$/i, c.order_type)
.option('--filename <filename>', 'filename for the result output (ex: result.html)', String, c.filename)
.option('--filename <filename>', 'filename for the result output (ex: result.html). "none" to disable', String, c.filename)
.option('--start <timestamp>', 'start at timestamp')
.option('--end <timestamp>', 'end at timestamp')
.option('--days <days>', 'set duration by day count', Number, c.days)
Expand All @@ -35,6 +35,7 @@ module.exports = function container (get, set, clear) {
.option('--max_slippage_pct <pct>', 'avoid selling at a slippage pct above this float', c.max_slippage_pct)
.option('--symmetrical', 'reverse time at the end of the graph, normalizing buy/hold to 0', Boolean, c.symmetrical)
.option('--rsi_periods <periods>', 'number of periods to calculate RSI at', Number, c.rsi_periods)
.option('--disable_options', 'disable printing of options')
.option('--enable_stats', 'enable printing order stats')
.option('--verbose', 'print status lines on every period')
.action(function (selector, cmd) {
Expand Down Expand Up @@ -63,6 +64,7 @@ module.exports = function container (get, set, clear) {
so.start = d.subtract(so.days).toMilliseconds()
}
so.stats = !!cmd.enable_stats
so.show_options = !cmd.disable_options
so.verbose = !!cmd.verbose
so.selector = get('lib.normalize-selector')(selector || c.selector)
so.mode = 'sim'
Expand Down Expand Up @@ -93,8 +95,10 @@ module.exports = function container (get, set, clear) {
option_keys.forEach(function (k) {
options[k] = so[k]
})
var options_json = JSON.stringify(options, null, 2)
output_lines.push(options_json)
if (so.show_options) {
var options_json = JSON.stringify(options, null, 2)
output_lines.push(options_json)
}
if (s.my_trades.length) {
s.my_trades.push({
price: s.period.close,
Expand Down Expand Up @@ -159,9 +163,11 @@ module.exports = function container (get, set, clear) {
.replace('{{output}}', html_output)
.replace(/\{\{symbol\}\}/g, so.selector + ' - zenbot ' + require('../package.json').version)

var out_target = so.filename || 'simulations/sim_result_' + so.selector +'_' + new Date().toISOString().replace(/T/, '_').replace(/\..+/, '').replace(/-/g, '').replace(/:/g, '').replace(/20/, '') + '_UTC.html'
fs.writeFileSync(out_target, out)
console.log('wrote', out_target)
if (so.filename !== 'none') {
var out_target = so.filename || 'simulations/sim_result_' + so.selector +'_' + new Date().toISOString().replace(/T/, '_').replace(/\..+/, '').replace(/-/g, '').replace(/:/g, '').replace(/20/, '') + '_UTC.html'
fs.writeFileSync(out_target, out)
console.log('wrote', out_target)
}
process.exit(0)
}

Expand Down
Loading

0 comments on commit 4973c24

Please sign in to comment.