サードパーティパッケージのインストール
- 株価分析のためのパッケージ
https://github.com/markcheno/go-talib
インストール
1 2 |
go get github.com/markcheno/go-talib go get github.com/markcheno/go-quote |
インストールされる場所
1 2 3 4 5 6 7 8 9 |
PS C:\Users\yuta\go\src\github.com> ls .\markcheno\ ディレクトリ: C:\Users\yuta\go\src\github.com\markcheno Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2020/07/03 8:45 go-talib |
サンプルコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<span class="k">package</span> <span class="n">main</span> <span class="k">import</span> <span class="p">(</span> <span class="s">"fmt"</span> <span class="s">"github.com/markcheno/go-quote"</span> <span class="s">"github.com/markcheno/go-talib"</span> <span class="p">)</span> <span class="k">func</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">spy</span><span class="p">,</span> <span class="n">_</span> <span class="o">:=</span> <span class="n">quote</span><span class="o">.</span><span class="n">NewQuoteFromYahoo</span><span class="p">(</span><span class="s">"spy"</span><span class="p">,</span> <span class="s">"2016-01-01"</span><span class="p">,</span> <span class="s">"2016-04-01"</span><span class="p">,</span> <span class="n">quote</span><span class="o">.</span><span class="n">Daily</span><span class="p">,</span> <span class="no">true</span><span class="p">)</span> <span class="n">fmt</span><span class="o">.</span><span class="n">Print</span><span class="p">(</span><span class="n">spy</span><span class="o">.</span><span class="n">CSV</span><span class="p">()) </span> <span class="n">rsi2</span> <span class="o">:=</span> <span class="n">talib</span><span class="o">.</span><span class="n">Rsi</span><span class="p">(</span><span class="n">spy</span><span class="o">.</span><span class="n">Close</span><span class="p">,</span> <span class="m">2</span><span class="p">)</span> <span class="n">fmt</span><span class="o">.</span><span class="n">Println</span><span class="p">(</span><span class="n">rsi2</span><span class="p">)</span> <span class="p">}</span> |
出力
1 2 3 4 5 |
datetime,open,high,low,close,volume 2016-01-04 00:00,200.49,201.03,198.59,184.03,222353500.00 2016-01-05 00:00,201.40,201.90,200.05,184.34,110845800.00 2016-01-06 00:00,198.34,200.06,197.60,182.01,152112600.00 2016-01-07 00:00,195.33,197.44,193.59,177.64,213436100.00 |
パッケージ自体を呼ばせない場合
- importしたパッケージが呼ばれないとビルド時にエラーになるため
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<span class="k">package</span> <span class="n">main</span> <span class="k">import</span> <span class="p">(</span> <span class="s">"fmt"</span> <span class="s">"github.com/markcheno/go-quote"</span> <span class="n">_</span> <span class="s">"github.com/markcheno/go-talib"</span> <span class="p">)</span> <span class="k">func</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">spy</span><span class="p">,</span> <span class="n">_</span> <span class="o">:=</span> <span class="n">quote</span><span class="o">.</span><span class="n">NewQuoteFromYahoo</span><span class="p">(</span><span class="s">"spy"</span><span class="p">,</span> <span class="s">"2016-01-01"</span><span class="p">,</span> <span class="s">"2016-04-01"</span><span class="p">, </span><span class="o">.</span><span class="n">Daily</span><span class="p">,</span> <span class="no">true</span><span class="p">)</span> <span class="n">fmt</span><span class="o">.</span><span class="n">Print</span><span class="p">(</span><span class="n">spy</span><span class="o">.</span><span class="n">CSV</span><span class="p">())</span> <span class="c">// rsi2 := talib.Rsi(spy.Close, 2)</span> <span class="c">// fmt.Println(rsi2)</span> <span class="p">}</span> |
godoc
- ローカル環境でgodocを見ることができる
- Example関数などで自分で書いたコードをExampleとしてみることができる
インストール
1 |
go get golang.org/x/tools/cmd/godoc |
利用方法
1 |
godoc -http=:6060 |