征服計画

仮想通貨戦記

zenbotを試してみる。 (3)

products.json

[
  {
    "asset": "BTC",
    "currency": "JPY",
    "min_size": "0.005",
    "max_size": "2000.0",
    "increment": "0.0001",
    "label": "BTC/JPY"
  },
  {
    "asset": "FX_BTC",
    "currency": "JPY",
    "min_size": "0.005",
    "max_size": "2000.0",
    "increment": "0.0001",
    "label": "FX_BTC/JPY"
  }
]

exchange.js

ふぉ

const pri = require('blac/lightning/builder/pub.js')
const moment = require('moment')

はっ

  function joinProduct (product_id) {
    return product_id.split('-')[0] + '_' + product_id.split('-')[1]
  }

ふぉっふぉ

    getTrades: function (opts, cb) {
      if (!pair) { pair = joinProduct(opts.product_id) }
      // Backfilling using the REST API
      if (opts.to || opts.to === null) {
        //var func_args = [].slice.call(arguments)

        if(!opts.from) {
          opts.from = 1
        }

        if(!opts.to) {
          opts.to = 999999999
        }

        body = new pri.getexecutions()
          .product_code(pair)
          .count(1000)
          .before(opts.to)
          .after(opts.from)
          .executeSync();
        
        var trades = body.map(function(trade) {
          return {
            trade_id: trade.id,
            time: moment(trade.exec_date).valueOf(),
            size: trade.size,
            price: trade.price,
            side: trade.side == 'BUY' ? 'buy' : 'sell'
          }
        })

        cb(null, trades)

      } else {
        console.log("???")
      }
    }

ほいっ

    getCursor: function (trade) {
      return (trade.trade_id || trade)
    }

まとめ

bitflyerのヒストリカルデータが取れるようになりました! githubに上げろって話だけど、まあ、そのうちね。

zenbotを試してみる。 (2) ふむー

bitfinexでシミュレーション

f:id:supersatan:20171107213512p:plain

全デフォルトでスタート

./zenbot.sh sim bitfinex.BTC-USD

結果

{
  "asset_capital": 0,
  "avg_slippage_pct": 0.045,
  "buy_pct": 99,
  "buy_stop_pct": 0,
  "currency_capital": 1000,
  "days": 14,
  "markup_pct": 0,
  "max_sell_loss_pct": 25,
  "max_slippage_pct": 5,
  "min_periods": 52,
  "mode": "sim",
  "neutral_rate": "auto",
  "order_adjust_time": 5000,
  "order_type": "maker",
  "oversold_rsi": 10,
  "oversold_rsi_periods": 14,
  "period": "2m",
  "profit_stop_enable_pct": 0,
  "profit_stop_pct": 1,
  "rsi_periods": 14,
  "selector": "bitfinex.BTC-USD",
  "sell_pct": 99,
  "sell_stop_pct": 0,
  "show_options": true,
  "start": 1508803200000,
  "stats": false,
  "strategy": "trend_ema",
  "trend_ema": 26,
  "verbose": false
}
end balance: 526.25989296 (-47.37%)
buy hold: 1180.69168656 (18.07%)
vs. buy hold: -55.43%
487 trades over 15 days (avg 32.47 trades/day)
win/loss: 64/180
error rate: 73.77%

ふむー。トレンドなのに負けてる?

買いだけにしてみましょう

呪文

./zenbot.sh sim bitfinex.BTC-USD --sell_pct 0.0
end balance: 1195.47894448 (19.55%)
buy hold: 1180.69168656 (18.07%)
vs. buy hold: 1.25%
2 trades over 15 days (avg 0.13 trades/day)
win/loss: 1/0
error rate: 0.00%

ガチホより1.25%勝てる。んーというか2回しか買ってないですね。

まあまあうまく行ったの

呪文

./zenbot.sh sim bitfinex.BTC-USD --strategy srsi_macd --days 60
end balance: 1398.98465924 (39.90%)
buy hold: 1511.76955089 (51.18%)
vs. buy hold: -7.46%
45 trades over 65 days (avg 0.69 trades/day)
win/loss: 13/10
error rate: 43.48%

error rateってなんでしょうか。ガチホ強すぎますね。ドローダウンとかが良ければいいけど、そのへんは出てこない。

zenbotを試してみる。 (1)

はじめに

たぶん日本語の情報がないので、zenbotを試してみましょう。

zenbotはこちら。

github.com

Zenbot is a command-line cryptocurrency trading bot using Node.js and MongoDB. It features:

Fully-automated technical-analysis-based trading approach Full support for GDAX, Poloniex, Kraken, Bittrex, Quadriga, Gemini, Bitfinex, CEX.IO and Bitstamp, work on further exchange support is ongoing. Plugin architecture for implementing exchange support, or writing new strategies Simulator for Backtesting strategies against historical data "Paper" trading mode, operates on a simulated balance while watching the live market Configurable sell stops, buy stops, and (trailing) profit stops Flexible sampling period and trade frequency - averages 1-2 trades/day with 1h period, 15-50/day with 5m period

なにやらアメリカ語でいろいろ書いてありますが、いろんな仮想通貨取引所に対応している仮想通貨用のトレーディングボットであり、バックテストに対応しており、拡張もしやすいよ、ということですね。

Current Status

Zenbot 4 is functional, but is having trouble reliably making profit. At this point, I would recommend against trading with large amounts until some of these issues can be worked out:

Many people are reporting losses in live trading even if the simulation results and/or paper trading is positive. This is my highest priority right now, since an unprofitable bot is not worth much, but please understand that reliably making profit is hard, and so is making a realistic simulator. The losses may be due to the default strategy not working well in sideways (non-trending) market conditions, slippage during limit order execution, or both. Currently I would recommend against using Zenbot on a market that is non-trending or trending generally downwards. The limit-order strategy that Zenbot uses to avoid taker fees, is prone to race conditions and delays. A mode for using market-type orders will probably need to be made, which may make frequent-trade strategies less viable due to fees, but more reliable execution overall. An upcoming feature will allow Zenbot to use a limited amount of your balance, which will help with experimenting with live trading, but mitigating the possible losses from the issues above.

この辺はてきとうに訳しておきましょうか。

現在の状況:

zenbotはまあ動くけど、確実に利益を出すには問題がある。大きな資金でトレードするなら、以下の問題が解決してからのほうがいい。

  • 多くの人々が、シミュレーションやペーパートレードで利益がでていても、リアルトレードでは損失がでると報告している。

  • 利益のでないbotなんで役立たずだから、これは最優先課題だ。ただし、アルなシミュレータを作るのも確実に利益を出すのもとてもむずかしいのをわかってほしい。

  • 損失の原因は、デフォルトの戦略がトレンドがないマーケットで通用しないことだったり、リミットオーダのスリッページによるものだったりする。今はトレンドのないマーケットや下方向のマーケットで使うことをおすすめしない。

  • Zenbotが受取手数料を避けるために使用するリミットオーダ戦略は、競争条件や遅延が発生しやすい。マーケットタイプの注文を使用するためのモードが必要になる。これにより、頻繁な取引戦略は手数料のために実行可能にならない可能性があるが、全体としてより信頼性の高い実行が可能になる。

  • 今後の機能により、Zenbotは残高の限られた金額を使用することができ、ライブ取引の実験に役立ちつつも、上記の問題による損失の可能性を軽減する。

ウーム。要は、at your own riskってことでしょうか。まあ少し、実験ならできるでしょうか

とりあえずシミュレーションしてみよう。

仮想通貨であれ株であれFXであれ、システムトレードの前には検証が必要です。検証のないシステムトレードはカンでやっているのとかわらないです。どっかの本で見ました。

シミュレーションのためのデータ取得。

./zenbot.sh backfill bitfinex.BTC-USD --days 30

bitfinex.BTC-USD のところは、

./zenbot.sh list-selectors

するとリストが出てきます。

bitfinex.BTC-USD saved 1000 trades 30 days left
............................................................

結構 ちょっと時間かかりますね。今日は寝よう。zzz...

環境構築 (node, zenbot, blac)

召喚呪文を詠唱します。

zenbotもblacもnodeでうごくので、nodeを入れます。ubuntu仕様なので他の人は読み替えてください。Windowsだと多分動かないと思います。(インジケータライブラリの関係らしい)

sudo apt-get install build-essential libssl-dev
sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.2/install.sh | bash
nvm install 9.0.0

参考: Node.jsをubuntuにインストール : ネットサーフィンの壺

git && mongodbも入ってないのでイレマース

sudo apt-get install git
sudo apt-get install mongodb

さて、clone && npm installしていきます。 APIしかいらないけど、とりあえずcloneします。node_modulesん中入れたのは好みです。

git clone https://github.com/carlos8f/zenbot
cd zenbot
npm install
# ちょっと時間がかかる。
cd node_modules
git clone https://github.com/yamorijp/blac
cd blac
npm install

攻撃呪文を作成します。

改造すべきところはこんな感じ。

~/zenbot/extensions/exchanges$ ls
bitfinex  bittrex  cexio  gemini  kraken    quadriga
bitstamp  btce     gdax   hitbtc  poloniex  therock

ここにbitflyerを追加すればいいのです。

zenbot/developers.md at master · carlos8f/zenbot · GitHub やり方はこの辺に買いてあります。

力尽きたのでまたこんどやりましょう。

仮想通貨でシステムトレード

仮想通貨でシステムトレード

みなさん、仮想通貨でシステムトレードしてますか。

みなさん5000兆円ほしいですか。 私はほしいです。 そんな私ですが、5000兆円ほしいと思い、bitflyerのFXKKD(勘と経験と度胸と愛しさと切なさと)で突撃しましたが、みごとに撃沈しました。 ちゃんと取引ルールやバックテストで検証しないとだめですね。 そんなわけで生半可プログラミングの知識を使い作ってみることにしました。

世界は広い

同じことを考えている人は世界にもおり、たとえば、

github.com とか github.com とか github.com とか github.com とか cryptotrader.org とか

そのうち使い方とかの記事を書きたいと思いますが、問題があります。 私が使っているbitflyerのFXに対応していない、ということです。 ところが、世の中は広いもので、APIを書いてくれている奇特な人々がいます。ありがたく使いましょう。

というわけで、計画。

一番改造しやすそうな github.com これと

GitHub - yamorijp/blac: bitFlyer Lightning API Console これをくっつけます。

まとめ。

がんばっていきましょう。