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

Genetic algorithm to fine tune strategy parameters #299

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
592634f
Added a genetic algorithm to train the parameters of the default stra…
Jun 9, 2017
9781900
Added a genetic algorithm to train the parameters of the default stra…
Jun 9, 2017
7cf94d4
Fixed a problem with pct being ill defined
Jun 9, 2017
b2ff5c2
Improvements to the genetic algorithms persistance, hall of fame adde…
Jun 10, 2017
d72cc47
Improvements to the genetic algorithms persistance, hall of fame adde…
Jun 10, 2017
24b694d
Parameter tuning
Jun 11, 2017
bc9a113
Don't have sex with yourself
Jun 11, 2017
a386b98
Drawing adjustments
Jun 11, 2017
0ff26ff
Improvements to metrics validation training and logging
Jun 11, 2017
ae5f839
Increase hall of fame size
Jun 11, 2017
d77c7c4
Use custom metric
Jun 11, 2017
e76d0c5
Params to conf py
Jun 11, 2017
1cb6396
Merge branch 'master' of https://github.com/carlos8f/zenbot
Jun 12, 2017
a1a3092
Refactor genetic algorithm
Jun 13, 2017
138f7ce
Refactor genetic algorithm
Jun 13, 2017
0a86fad
Refactor genetic algorithm
Jun 13, 2017
8f10078
Refactor genetic algorithm
Jun 13, 2017
fdc2403
initial implementation of deep-learning strategy
miro-ka Jun 13, 2017
4bba339
Merge github.com:carlos8f/zenbot
miro-ka Jun 13, 2017
3be8612
Reduce penalty
Jun 13, 2017
85d58b1
partial commit of q-learning strategy
miro-ka Jun 13, 2017
a07ab14
fuck you git
Jun 14, 2017
09e79a8
somebody keeps erasing my changes.
Jun 14, 2017
9fa1c23
synching
miro-ka Jun 15, 2017
3420221
Now we tell you your browser sucks in your native tongue.
Jun 15, 2017
8c3ce41
Formatting output
Jun 15, 2017
329e72b
Fuzz training across products
Jun 15, 2017
7874e5a
Fuzz training across products
Jun 15, 2017
d584a0c
Remove debug, sort elites
Jun 15, 2017
359434f
adjust slippage
Jun 15, 2017
d9ec7d9
sort elites
Jun 15, 2017
48755fa
started to integrate talib
miro-ka Jun 15, 2017
1dd9c12
One little whitespace gets its very own commit! Oh, life is so erratic!
Jun 16, 2017
96a0303
It only compiles every 2 tries... good luck.
Jun 16, 2017
ade45c5
added some filthy stuff
Jun 16, 2017
8f2934b
aslkdlj
Jun 16, 2017
fd0c9c0
Merge branch 'master' of https://github.com/carlos8f/zenbot
Jun 16, 2017
028db1f
Issues with typing
Jun 16, 2017
2bac433
When you make a pull request, be sure that the damn thing actually works
Jun 16, 2017
5cebf49
Adjust log messages
Jun 16, 2017
f9c24ee
Readd minperiods
Jun 16, 2017
9397f89
adding AD and ADS inticators
miro-ka Jun 16, 2017
5f1a7ff
fixing strategy template bug
miro-ka Jun 16, 2017
d2da758
hey, what's that over there?!
Jun 17, 2017
13dae71
Merge remote-tracking branch 'genetics/master'
gelotus Jun 17, 2017
215da0c
Merge branch 'master' of https://github.com/carlos8f/zenbot
gelotus Jun 17, 2017
de0747a
Merge branch 'master' of https://github.com/carlos8f/zenbot
gelotus Jun 18, 2017
70b2da5
Merge branch 'master' of https://github.com/carlos8f/zenbot
gelotus Jun 18, 2017
af2d5d6
Merge remote-tracking branch 'deep/master'
gelotus Jun 18, 2017
54a0cf0
Sync
gelotus Jun 18, 2017
9043e2e
Merge branch 'master' of https://github.com/carlos8f/zenbot
gelotus Jun 19, 2017
adf6e4c
Merge branch 'master' of https://github.com/carlos8f/zenbot
Jun 20, 2017
bb656e9
minor changes
Jun 20, 2017
a7cf31b
Sync
gelotus Jun 20, 2017
3eab688
fix
gelotus Jun 20, 2017
3d5226d
Merge remote-tracking branch 'genetics/master'
gelotus Jun 20, 2017
85a6949
repair master
Jun 21, 2017
0c16a8b
repair master
Jun 21, 2017
4cb7f07
repair master
Jun 22, 2017
4139f94
Merge remote-tracking branch 'genetics/master'
gelotus Jun 22, 2017
f3b4485
Path fix
gelotus Jun 22, 2017
ee2e157
In population is low len is 0. Is better a fixed value
gelotus Jun 25, 2017
552642c
Working dir variable in conf
gelotus Jun 25, 2017
7d36a00
Merge remote-tracking branch 'lead/master'
gelotus Jun 25, 2017
fdb51a0
Ignore pyc
gelotus Jun 25, 2017
8ae56aa
Merge remote-tracking branch 'lead/master'
gelotus Jun 27, 2017
a6349bb
Replace colorterm with blessings
gelotus Jun 27, 2017
76f80a6
Remove escape characters from hall of fame file
gelotus Jun 27, 2017
14f4218
Merge remote-tracking branch 'lead/master'
gelotus Jun 27, 2017
520bd65
More envinronment agnostic and new syntax for backfill
gelotus Jun 27, 2017
e698dad
Implement auto backfill timer
gelotus Jun 28, 2017
d937be6
Add placeholders
gelotus Jun 28, 2017
2627b18
Merge pull request #2 from gelotus/master
arpheno Jun 28, 2017
d26dc67
Revert "Implement working dir as variable editable in conf."
arpheno Jun 28, 2017
59d35f0
Merge pull request #3 from arpheno/revert-2-master
arpheno Jun 28, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 93 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,97 @@
FROM node:latest

ADD . /app


# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#


# ensure local python is preferred over distribution python
ENV PATH /usr/local/bin:$PATH

# http://bugs.python.org/issue19846
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8

# runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
tcl \
tk \
&& rm -rf /var/lib/apt/lists/*

ENV GPG_KEY 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
ENV PYTHON_VERSION 3.6.0

# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON_PIP_VERSION 9.0.1

RUN set -ex \
&& buildDeps=' \
tcl-dev \
tk-dev \
' \
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
\
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
&& rm -r "$GNUPGHOME" python.tar.xz.asc \
&& mkdir -p /usr/src/python \
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
&& rm python.tar.xz \
\
&& cd /usr/src/python \
&& ./configure \
--enable-loadable-sqlite-extensions \
&& make -j$(nproc) \
&& make install \
&& ldconfig \
\
# explicit path to "pip3" to ensure distribution-provided "pip3" cannot interfere
&& if [ ! -e /usr/local/bin/pip3 ]; then : \
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
&& python3 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
&& rm /tmp/get-pip.py \
; fi \
# we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python
# ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.6/site-packages")
# https://github.com/docker-library/python/pull/143#issuecomment-241032683
&& pip3 install --no-cache-dir --upgrade --force-reinstall "pip==$PYTHON_PIP_VERSION" \
# then we use "pip list" to ensure we don't have more than one pip version installed
# https://github.com/docker-library/python/pull/100
&& [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
\
&& find /usr/local -depth \
\( \
\( -type d -a -name test -o -name tests \) \
-o \
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
\) -exec rm -rf '{}' + \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -rf /usr/src/python ~/.cache

# make some useful symlinks that are expected to exist
RUN cd /usr/local/bin \
&& { [ -e easy_install ] || ln -s easy_install-* easy_install; } \
&& ln -s idle3 idle \
&& ln -s pydoc3 pydoc \
&& ln -s python3 python \
&& ln -s python3-config python-config




RUN apt-get update
RUN apt install -y graphviz libgraphviz-dev pkg-config
RUN PKG_CONFIG_ALLOW_SYSTEM_LIBS=OHYESPLEASE pip install pygraphviz
ADD zen/requirements.txt /
RUN pip3 install -r /requirements.txt
WORKDIR /app
RUN /usr/local/bin/npm install
RUN npm update

Copy link
Owner

Choose a reason for hiding this comment

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

I would suggest to just create your own docker.

Also, to run this, I had to run mkdir -p logs/hof, so perhaps a RUN mkdir -p zen/logs/hof here around the end?

Choose a reason for hiding this comment

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

I get a weird error related to npm in docker. When you guys were building your docker, did you stumble upon this?
server_1 | module.js:471
server_1 | throw err;
server_1 | ^
server_1 |
server_1 | Error: Cannot find module 'semver'

Copy link

Choose a reason for hiding this comment

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

If you are using arphenos dockerfile you need to copy at least package.json into you workdir before the npm install command.

or just copy the app into the working dir:
COPY . /app


RUN npm install
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ rsi
--overbought_rsi=<value> sell when RSI reaches or goes above this value (default: 82)
--rsi_recover=<value> allow RSI to recover this many points before buying (default: 3)
--rsi_drop=<value> allow RSI to fall this many points before selling (default: 0)
--rsi_divisor=<value> sell when RSI reaches high-water reading divided by this value (default: 2)
--rsi_dividend=<value> sell when RSI reaches high-water reading divided by this value (default: 2)

sar
description:
Expand Down Expand Up @@ -452,8 +452,15 @@ zenbot sell gdax.BTC-USD --pct=10
## TODO

- cancel pending orders on SIGINT
- determine and fix what is causing live trading to underperform vs. paper trading/simulations
- improve order execution speed, possibly by using market-type orders (incurring taker fees)
- support for limiting the amount of balance Zenbot can use for trading
- fix partial filled orders sometimes not getting recognized, due to race conditions
- tool to generate graph and stats from live or paper trading sessions
- review PRs
- save sim data to db, for front-end UI
- make error output compact, no stack trace
- review PR for Bitfinex
- more exchange support
- web UI with graphs and logs
- "reaper" to automatically prune trades collection to a certain day length
- "lite mode" for trader, an option to run without MongoDB
Expand Down
1 change: 0 additions & 1 deletion extensions/exchanges/gdax/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ module.exports = function container (get, set, clear) {
side: trade.side
}
})
trades.reverse()
cb(null, trades)
})
},
Expand Down
77 changes: 77 additions & 0 deletions extensions/exchanges/kraken/products.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@
"increment": "0.00000001",
"label": "ETH/XBT"
},
{
"asset": "XETH",
"currency": "XXBT",
"min_size": "0.01",
"increment": "0.00000001",
"label": "ETH/XBT"
},
{
"asset": "XETH",
"currency": "ZCAD",
"min_size": "0.01",
"increment": "0.00000001",
"label": "ETH/CAD"
},
{
"asset": "XETH",
"currency": "ZCAD",
Expand All @@ -104,6 +118,20 @@
"increment": "0.00000001",
"label": "ETH/EUR"
},
{
"asset": "XETH",
"currency": "ZEUR",
"min_size": "0.01",
"increment": "0.00000001",
"label": "ETH/EUR"
},
{
"asset": "XETH",
"currency": "ZGBP",
"min_size": "0.01",
"increment": "0.00000001",
"label": "ETH/GBP"
},
{
"asset": "XETH",
"currency": "ZGBP",
Expand All @@ -118,6 +146,20 @@
"increment": "0.00000001",
"label": "ETH/JPY"
},
{
"asset": "XETH",
"currency": "ZJPY",
"min_size": "0.01",
"increment": "0.00000001",
"label": "ETH/JPY"
},
{
"asset": "XETH",
"currency": "ZUSD",
"min_size": "0.01",
"increment": "0.00000001",
"label": "ETH/USD"
},
{
"asset": "XETH",
"currency": "ZUSD",
Expand Down Expand Up @@ -209,13 +251,34 @@
"increment": "0.00000001",
"label": "XBT/CAD"
},
{
"asset": "XXBT",
"currency": "ZCAD",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XBT/CAD"
},
{
"asset": "XXBT",
"currency": "ZEUR",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XBT/EUR"
},
{
"asset": "XXBT",
"currency": "ZEUR",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XBT/EUR"
},
{
"asset": "XXBT",
"currency": "ZGBP",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XBT/GBP"
},
{
"asset": "XXBT",
"currency": "ZGBP",
Expand All @@ -230,6 +293,20 @@
"increment": "0.00000001",
"label": "XBT/JPY"
},
{
"asset": "XXBT",
"currency": "ZJPY",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XBT/JPY"
},
{
"asset": "XXBT",
"currency": "ZUSD",
"min_size": "0.01",
"increment": "0.00000001",
"label": "XBT/USD"
},
{
"asset": "XXBT",
"currency": "ZUSD",
Expand Down
4 changes: 1 addition & 3 deletions extensions/exchanges/kraken/update-products.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ kraken.api('Assets', null, function (error, data) {
process.exit(1)
} else {
Object.keys(data.result).forEach(function (result) {
if(!result.match('\.d')) {
addProduct(data.result[result].base, data.result[result].quote, data.result[result].altname)
}
addProduct(data.result[result].base, data.result[result].quote, data.result[result].altname)
})
var target = require('path').resolve(__dirname, 'products.json')
require('fs').writeFileSync(target, JSON.stringify(products, null, 2))
Expand Down
4 changes: 2 additions & 2 deletions extensions/strategies/rsi/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function container (get, set, clear) {
this.option('overbought_rsi', 'sell when RSI reaches or goes above this value', Number, 82)
this.option('rsi_recover', 'allow RSI to recover this many points before buying', Number, 3)
this.option('rsi_drop', 'allow RSI to fall this many points before selling', Number, 0)
this.option('rsi_divisor', 'sell when RSI reaches high-water reading divided by this value', Number, 2)
this.option('rsi_dividend', 'sell when RSI reaches high-water reading divided by this value', Number, 2)
},

calculate: function (s) {
Expand All @@ -38,7 +38,7 @@ module.exports = function container (get, set, clear) {
}
if (s.trend === 'long') {
s.rsi_high = Math.max(s.rsi_high, s.period.rsi)
if (s.period.rsi <= s.rsi_high / s.options.rsi_divisor) {
if (s.period.rsi <= s.rsi_high / s.options.rsi_dividend) {
s.trend = 'short'
s.signal = 'sell'
}
Expand Down
37 changes: 37 additions & 0 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import datetime
import shlex

import subprocess
from fabric.api import run, cd,local



Copy link
Owner

Choose a reason for hiding this comment

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

nit: one newline too much

def sim(instrument, days, popsize, strategy):
with cd('zenbot'):
params = dict(instrument=instrument, days=days, strategy=strategy, popsize=popsize,
timestamp=datetime.datetime.now().strftime('%Y-%m-%d-%H-%M'))
cmd = "cd zen && python -m scoop main.py {instrument} {days} {popsize} {strategy}".format(**params)
total = '(nohup docker-compose exec -T server bash -c "{cmd}" > {instrument}_{strategy}_{days}_{popsize}_{timestamp}.out 2>&1 &) && sleep 1'.format(
cmd=cmd, **params)
print(total)
run(total)


def remote(cmd,logfile):
with cd('zenbot'):
total = '(nohup docker-compose exec -T server bash -c "{cmd}" > {logfile} 2>&1 &) && sleep 1'.format(cmd=cmd,
logfile=logfile)
print(total)
run(total)

def backfill_remote(TOTAL_DAYS):
products = ['gdax.BTC-EUR','gdax.BTC-USD','gdax.BTC-GBP']+['gdax.ETH-BTC','poloniex.ETH-BTC']
for instrument in products:
cmd = '/app/zenbot.sh backfill {instrument} --days {days}'.format(days=TOTAL_DAYS, instrument=instrument)
remote(cmd,'backfill_'+instrument)
def backfill_local(TOTAL_DAYS):
products = ['gdax.BTC-EUR','gdax.BTC-USD','gdax.BTC-GBP']+['gdax.ETH-BTC','poloniex.ETH-BTC']
Copy link
Owner

Choose a reason for hiding this comment

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

I understand why this is a constant now (for demo purposes) but if we plan on merging this in at some point, we should try and use the list-selectors from zenbot, perhaps?

for instrument in products:
cmd = '/app/zenbot.sh backfill {instrument} --days {days}'.format(days=TOTAL_DAYS, instrument=instrument)
local(cmd)

4 changes: 0 additions & 4 deletions simulations/README.md

This file was deleted.

7 changes: 7 additions & 0 deletions zen/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions zen/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions zen/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading