Skip to content

Commit f1f64fb

Browse files
author
Carlos Rodriguez
committed
strat abstraction, regression of -1.50% over buy/hold
1 parent 9b7dc72 commit f1f64fb

File tree

13 files changed

+239
-188
lines changed

13 files changed

+239
-188
lines changed

_codemap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module.exports = {
33
_maps: [
44
require('./commands/_codemap'),
55
require('./db/_codemap'),
6-
require('./lib/_codemap')
6+
require('./lib/_codemap'),
7+
require('./strategies/_codemap')
78
],
89
'conf': null,
910
'exchanges.list': []

boot.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ module.exports = function (cb) {
44
var c = require('./conf')
55
}
66
catch (e) {
7-
var err = new Error('conf error')
8-
err.code = 'CONF'
9-
return cb(err, zenbot)
7+
c = {}
108
}
119
var defaults = require('./defaults')
1210
Object.keys(defaults).forEach(function (k) {

commands/_codemap.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@ module.exports = {
22
_ns: 'zenbot',
33
_folder: 'commands',
44

5-
'list[0]': '#commands.init',
65
'list[10]': '#commands.extend',
76
'list[20]': '#commands.list-selectors',
8-
'list[30]': '#commands.watch',
9-
'list[40]': '#commands.watcher',
107
'list[50]': '#commands.backfill',
118
'list[60]': '#commands.sim',
129

13-
'init': require('./init'),
1410
'extend': require('./extend'),
1511
'list-selectors': require('./list-selectors'),
1612
'ls': '#commands.list-selectors',
17-
'watch': require('./watch'),
18-
'watcher': require('./watcher'),
1913
'backfill': require('./backfill'),
2014
'sim': require('./sim')
2115
}

commands/sim.js

Lines changed: 104 additions & 149 deletions
Large diffs are not rendered by default.

conf.js.tpl

Lines changed: 0 additions & 8 deletions
This file was deleted.

defaults.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
var path = require('path')
2-
31
module.exports = {
4-
watcher_poll_selectors: 10000,
2+
mongo_host: 'localhost',
3+
mongo_port: 27017,
4+
mongo_db: 'zenbot4',
5+
mongo_username: null,
6+
mongo_password: null,
7+
8+
strategy: 'trend_ema_rate',
59
watcher_error_backoff: 30000,
610
watcher_poll_new: 10000,
711
backfill_days: 90,
812
request_timeout: 10000,
9-
backfill_min_gap: 600000,
10-
default_strategy: path.resolve(__dirname, 'strategies', 'incremental_speculation.js'),
11-
lookback_size: 200
13+
lookback_size: 200,
14+
fee_pct: 0.25,
15+
start_capital: 1000,
16+
markup_pct: 0.01,
17+
markdown_pct: 0.01,
18+
bid_adjust_time: 300000,
19+
max_sell_loss_pct: -10
1220
}

lib/_codemap.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ module.exports = {
22
_ns: 'zenbot',
33
_folder: 'lib',
44

5+
'ema': require('./ema'),
56
'list-selectors': require('./list-selectors'),
67
'load-strategy': require('./load-strategy'),
7-
'normalize-selector': require('./normalize-selector')
8+
'normalize-selector': require('./normalize-selector'),
9+
'rsi': require('./rsi')
810
}

lib/ema.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = function container (get, set, clear) {
2+
return function ema (s, key, length) {
3+
if (s.lookback.length >= length) {
4+
var prev_ema = s.lookback[0][key]
5+
if (!prev_ema) {
6+
var sum = 0
7+
s.lookback.slice(0, length).forEach(function (period) {
8+
sum += period.close
9+
})
10+
prev_ema = sum / length
11+
}
12+
var multiplier = 2 / (length + 1)
13+
s.period[key] = (s.period.close - prev_ema) * multiplier + prev_ema
14+
}
15+
}
16+
}

lib/rsi.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module.exports = function container (get, set, clear) {
2+
return function rsi (s, key, length) {
3+
if (s.lookback.length >= length) {
4+
var avg_gain = s.lookback[0][key + '_avg_gain']
5+
var avg_loss = s.lookback[0][key + '_avg_loss']
6+
if (typeof avg_gain === 'undefined') {
7+
var gain_sum = 0
8+
var loss_sum = 0
9+
var last_close
10+
s.lookback.slice(0, length).forEach(function (period) {
11+
if (last_close) {
12+
if (period.close > last_close) {
13+
gain_sum += period.close - last_close
14+
}
15+
else {
16+
loss_sum += last_close - period.close
17+
}
18+
}
19+
last_close = period.close
20+
})
21+
s.period[key + '_avg_gain'] = gain_sum / length
22+
s.period[key + '_avg_loss'] = loss_sum / length
23+
}
24+
else {
25+
var current_gain = s.period.close - s.lookback[0].close
26+
s.period[key + '_avg_gain'] = ((avg_gain * (length - 1)) + (current_gain > 0 ? current_gain : 0)) / length
27+
var current_loss = s.lookback[0].close - s.period.close
28+
s.period[key + '_avg_loss'] = ((avg_loss * (length - 1)) + (current_loss > 0 ? current_loss : 0)) / length
29+
}
30+
var rs = s.period[key + '_avg_gain'] / s.period[key + '_avg_loss']
31+
s.period[key] = Math.round(100 - (100 / (1 + rs)))
32+
}
33+
}
34+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"mongodb": "^2.2.25",
1616
"numbro": "git+https://github.com/carlos8f/numbro.git",
1717
"run-parallel": "^1.1.6",
18+
"run-series": "^1.1.4",
1819
"sosa_mongo": "^1.0.3",
1920
"timebucket": "^0.4.0",
2021
"zero-fill": "^2.2.3"

0 commit comments

Comments
 (0)