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

Three strategies have been coded to the best of my ability. + Lightning Fast Threading #709

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ macd
--overbought_rsi_periods=<value> number of periods for overbought RSI (default: 25)
--overbought_rsi=<value> sold when RSI exceeds this value (default: 70)

neural
description:
Use neural learning to predict future price. Buy = mean(last 3 real prices) < mean(current & last prediction)
options:
--period=<value> period length - make sure to lower your poll trades time to lower than this value (default: 5s)
--activation_1_type=<value> Neuron Activation Type: sigmoid, tanh, relu (default: sigmoid)
--neurons_1=<value> Neurons in layer 1 Shoot for atleast 100 (default: 5)
--depth=<value> Rows of data to predict ahead for matches/learning (default: 1)
--selector=<value> Selector (default: Gdax.BTC-USD)
--min_periods=<value> Periods to calculate learn from (default: 25)
--min_predict=<value> Periods to predict next number from (default: 3)
--momentum=<value> momentum of prediction (default: 0.2)
--decay=<value> decay of prediction, use teeny tiny increments (default: 0)

rsi
description:
Attempts to buy low and sell high by tracking RSI high-water readings.
Expand Down Expand Up @@ -329,6 +343,15 @@ srsi_macd
--up_trend_threshold=<value> threshold to trigger a buy signal (default: 0)
--down_trend_threshold=<value> threshold to trigger a sold signal (default: 0)

stddev
description:
Buy when standard deviation and mean increase, sell on mean decrease.
options:
--period=<value> period length, set poll trades to 100ms, poll order 1000ms (default: 100ms)
--trendtrades_1=<value> Trades for array 1 to be subtracted stddev and mean from (default: 5)
--trendtrades_2=<value> Trades for array 2 to be calculated stddev and mean from (default: 53)
--min_periods=<value> min_periods (default: 1250)

ta_ema
description:
Buy when (EMA - last(EMA) > 0) and sell when (EMA - last(EMA) < 0). Optional buy on low RSI.
Expand Down Expand Up @@ -365,6 +388,16 @@ trend_ema (default)
--oversold_rsi_periods=<value> number of periods for oversold RSI (default: 14)
--oversold_rsi=<value> buy when RSI reaches this value (default: 10)

trendline
description:
Calculate a trendline and trade when trend is positive vs negative.
options:
--period=<value> period length (default: 10s)
--trendtrades_1=<value> Number of trades to load into data (default: 100)
--lastpoints=<value> Number of short points at beginning of trendline (default: 3)
--avgpoints=<value> Number of long points at end of trendline (default: 53)
--min_periods=<value> Minimum trades to backfill with (trendtrades_1 + about ~10) (default: 1250)

trust_distrust
description:
Sell when price higher than $sell_min% and highest point - $sell_threshold% is reached. Buy when lowest price point + $buy_threshold% reached.
Expand Down
6 changes: 6 additions & 0 deletions extensions/strategies/neural/_codemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
_ns: 'zenbot',

'strategies.neural': require('./strategy'),
'strategies.list[]': '#strategies.neural'
}
96 changes: 96 additions & 0 deletions extensions/strategies/neural/strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
var convnetjs = require('convnetjs')
var z = require('zero-fill')
var stats = require('stats-lite')
var n = require('numbro')
var math = require('mathjs')
var napa = require('napajs');
var zone2 = napa.zone.create('zone2', {
workers: 1
});
// the beow line is for calculating the last mean vs the now mean.
var oldmean = 0
module.exports = function container (get, set, clear) {
return {
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', String, '5s')
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, 5)
this.option('depth', "Rows of data to predict ahead for matches/learning", Number, 1)
this.option('selector', "Selector", String, 'Gdax.BTC-USD')
this.option('min_periods', "Periods to calculate learn from", Number, 25)
this.option('min_predict', "Periods to predict next number from", Number, 3)
this.option('momentum', "momentum of prediction", Number, 0.2)
this.option('decay', "decay of prediction, use teeny tiny increments", Number, 0)
},
calculate: function (s) {

},
onPeriod: function (s, cb) {
// do the network thing
var tlp = []
var tll = []
// Create the net the first time it is needed and NOT on every run
global.net = new convnetjs.Net(),
global.defs = [{type:'input', out_sx:1, out_sy:1, out_depth:s.options.depth}, {type:'fc', num_neurons:s.options.neurons_1, activation:s.options.activation_1_type}, {type:'regression', num_neurons:1}]
global.neuralDepth = s.options.depth
global.net.makeLayers(global.defs);
global.trainer = new convnetjs.SGDTrainer(global.net, {learning_rate:0.01, momentum:s.options.momentum, batch_size:1, l2_decay:s.options.decay});
if (s.lookback[s.options.min_periods]) {
for (let i = 0; i < s.options.min_periods; i++) { tll.push(s.lookback[i].close) }
for (let i = 0; i < s.options.min_predict; i++) { tlp.push(s.lookback[i].close) }
global.my_data = tll.reverse()
global.length = global.my_data.length
var predict = function(data){
var x = new convnetjs.Vol(data);
var predicted_value = global.net.forward(x);
return predicted_value.w[0];
}
//threading below by napajs for 500 training rounds a thread, the first line broadcasts the function, the second executes.
for (var j = 0; j < 500; j++){
function test() {
for (var i = 0; i < global.length - global.neuralDepth; i++) {
var data = global.my_data.slice(i, i + global.neuralDepth);
var real_value = [global.my_data[i + global.neuralDepth]];
var x = new convnetjs.Vol(data);
global.trainer.train(x, real_value);
var predicted_values = global.net.forward(x);
};
};
zone2.broadcast(test.toString());
zone2.execute(() => { global.test(global.my_data, global.length, global.neuralDepth, global.trainer, global.net); }, []);
}
var item = tlp.reverse();
s.prediction = predict(item)
s.mean = math.mean(tll[0], tll[1], tll[2])
s.meanp = math.mean(s.prediction, oldmean)
s.sig0 = s.meanp > s.mean
oldmean = s.prediction
}


// NORMAL onPeriod STUFF here
if (
s.sig0 === false
)
{
s.signal = 'sell'
}
else if
(
s.sig0 === true
)
{
s.signal = 'buy'
}
cb()
},
onReport: function (s) {
cols = []
cols.push(z(8, n(s.mean).format('0000.00'), ' ')[s.meanp > s.mean ? 'green' : 'red'])
cols.push(z(8, n(s.meanp).format('0000.00'), ' ')[s.meanp > s.mean ? 'green' : 'red'])
return cols
},
}
}
6 changes: 6 additions & 0 deletions extensions/strategies/stddev/_codemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
_ns: 'zenbot',

'strategies.stddev': require('./strategy'),
'strategies.list[]': '#strategies.stddev'
}
52 changes: 52 additions & 0 deletions extensions/strategies/stddev/strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var z = require('zero-fill')
var stats = require('stats-lite')
var n = require('numbro')
var math = require('mathjs');
module.exports = function container (get, set, clear) {
return {
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', 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)
},
calculate: function (s) {
get('lib.ema')(s, 'stddev', s.options.stddev)
var tl0 = []
var tl1 = []
if (s.lookback[s.options.min_periods]) {
for (let i = 0; i < s.options.trendtrades_1; i++) { tl0.push(s.lookback[i].close) }
for (let i = 0; i < s.options.trendtrades_2; i++) { tl1.push(s.lookback[i].close) }
s.std0 = stats.stdev(tl0) / 2
s.std1 = stats.stdev(tl1) / 2
s.mean0 = math.mean(tl0)
s.mean1 = math.mean(tl1)
s.sig0 = s.std0 > s.std1 ? 'Up' : 'Down';
s.sig1 = s.mean0 > s.mean1 ? 'Up' : 'Down';
}
},
onPeriod: function (s, cb) {
if (
s.sig1 === 'Down'
)
{
s.signal = 'sell'
}
else if (
s.sig0 === 'Up'
&& s.sig1 === 'Up'
)
{
s.signal = 'buy'
}
cb()
},
onReport: function (s) {
var cols = []
cols.push(z(s.signal, ' ')[s.signal === false ? 'red' : 'green'])
return cols
},
}
}
6 changes: 6 additions & 0 deletions extensions/strategies/trendline/_codemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
_ns: 'zenbot',

'strategies.trendline': require('./strategy'),
'strategies.list[]': '#strategies.trendline'
}
54 changes: 54 additions & 0 deletions extensions/strategies/trendline/strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var stats = require('stats-lite')
var math = require('mathjs')
var trend = require('trend')
var z = require('zero-fill')
module.exports = function container (get, set, clear) {
return {
name: 'trendline',
description: 'Calculate a trendline and trade when trend is positive vs negative.',
getOptions: function () {
this.option('period', 'period length', String, '10s')
this.option('trendtrades_1', "Number of trades to load into data", Number, 100)
this.option('lastpoints', "Number of short points at beginning of trendline", Number, 3)
this.option('avgpoints', "Number of long points at end of trendline", Number, 53)
this.option('min_periods', "Minimum trades to backfill with (trendtrades_1 + about ~10)", Number, 1250)
},
calculate: function (s) {
get('lib.ema')(s, 'trendline', s.options.trendline)
var tl1 = []
if (s.lookback[s.options.min_periods]) {
for (let i = 0; i < s.options.trendtrades_1; i++) { tl1.push(s.lookback[i].close) }

var chart = tl1

growth = trend(chart, {
lastPoints: s.options.lastpoints,
avgPoints: s.options.avgpoints,
avgMinimum: 10,
reversed: true
}),
s.growth = growth
}
},
onPeriod: function (s, cb) {
if (
s.growth < 0.9999
)
{
s.signal = 'sell'
}
else if (
s.growth > 1.0001
)
{
s.signal = 'buy'
}
cb()
},
onReport: function (s) {
var cols = []
cols.push(z(s.signal, ' ')[s.signal === 'Sell' ? 'red' : 'green'])
return cols
},
}
}
6 changes: 6 additions & 0 deletions install.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Hit:2 http://us.archive.ubuntu.com/ubuntu xenial InRelease
Hit:3 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease
Get:5 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Hit:6 https://deb.nodesource.com/node_7.x xenial InRelease
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add *.log to the .gitignore to ignore these kind of files