Code Monkey home page Code Monkey logo

go_fx_v2's Introduction

Go FX V2

front側の起動

yarn serve --port 5500

app側の起動

go run main.go

これはなに

go_fx_v1を再構築する. 変化点は下記の通り.

  • 日足のトレード専用にする
  • 扱う通貨はUSD/JPYのみ
  • talibのテクニカルを使って、売買ルールを指定する
  • 売買ルールのベースはRubyで構築したトレードシミュレーションと基本は同じにする
  • Frontはおまけ
    • シミュレーションはバックエンドとデータベースだけで完結させる
    • Frontに表示したくなったらAPIHandlerを定義して、Vue.jsからAPI呼び出しをするようにする

その他

  • databaseはpostgresql
  • 日足データはクリック証券かな(??)から取ってきたものを使う

config.iniの設定

[fxtrading]
currency_code = USD_JPY


[db]
SQLDriver = postgres
DbName = exchange_v2

config.go

package config

import (
	"log"

	"gopkg.in/ini.v1"
)

type ConfigList struct {
	SQLDriver    string
	DbName       string
	CurrencyCode string
}

var Config ConfigList

func init() {
	cfg, err := ini.Load("config.ini")
	if err != nil {
		log.Fatalln(err)
	}

	Config = ConfigList{
		SQLDriver:    cfg.Section("db").Key("SQLDriver").String(),
		DbName:       cfg.Section("db").Key("DbName").String(),
		CurrencyCode: cfg.Section("fxtrading").Key("currency_code").String(),
		Port : cfg.Section("web").Key("port").MustInt(),
	}

}

データベースの設定

postgresqlを使用する(sqlite3よりは使い慣れているので)

import (
  "github.com/lib/pq"
)


func init() {
  conStr := "user=takuyakinoshita dbname=exchangerates sslmode=disable"
  DbConnection, err = sql.Open(config.Config.SQLDriver, conStr)
  // ここで := を使うとnil pointer dereference errorが出るので注意
}

Databaseへのデータ取り込み

1dのローソクからデータベースを作成する

SQL.open時には、connectionとerrorはグローバル登録して、 型推論はしないようにしないとエラーが発生するので注意する.

// 下記はぬるぽ
DbConnection, err := sql.Open(config.Config.SQLDriver, connectionStr)

DataFrameの作成

データベースから情報を取ってきてメモリに格納するDataFrameを作成する.

candle.go データベースから値を読み出して、candle構造体に1本のcandle情報を格納する

  • time
  • open
  • high
  • low
  • close
  • swap

データベースから値を読み出して、DataFrameCandle構造体を返すグローバル関数もここに定義する.

dfcandle.go candleの配列の形をとる.

  • duration
  • events(購買情報,後で追加)
  • SMA(technical, 後で追加)
  • EMA(technical, 後で追加)
  • ...
  • candles []candle

[models/dfcandle.go]

[models/candle.go]

SignalEventsの実装

抜き出したデータフレームにSignalEventsを渡す.

個々のSignalEventは、データフレーム内で条件に合致した場合に データベースに売買情報が保存される.
なので、SignalEventsテーブルを参照することで、 売買ルールの有効性が確認できる.

シミュレーションの実行

  • シミュレーションの開始時点を指定: startDate
  • 保有ロット、建玉の価格、現在の価格profitを計算して、Accountの値をウォッチする (単純化のため、ひとまずswapは計算対象にしない)

startDataだけを指定して、startDate以降のデータをすべて抽出。
startDateを最初の建玉を建てる日付(midPriceで購入)して、 一括決済に至るまでを一つのスパンとする.

日付を進めながらシミュレーションを繰り返すことで、 包括的なシミュレーションを実行できる.

シミュレーションルール

  • 指定した期間startで1lot購入
  • 1円下がるごとに追加で1lot購入
  • 最大10lotまで購入
  • 利益が30%を超えたら売却
  • 利益が-50%を超えたら売却

go_fx_v2's People

Contributors

tker-78 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.