This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Three strategies have been coded to the best of my ability. + Lightning Fast Threading #709
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
84e7333
Three strategies have been coded to the best of my ability.
3dffb01
Added node-prowl, updated package-lock.json
67eb7f3
Removed unnecessary line.
135f642
Alphabetical order correction
d6318d1
Updated Readme with 3 strategies added
a9f9432
Threading code does not function.
ca0b215
Attempted threading, created fancy ./install.sh file.
3cf97a9
ALMOST THERE!
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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