iamjinlei / go-tart

Technical indicators with streaming update support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-tart (go-TA RealTime)

Build Status Go Report Card License: MIT Go Reference

Intro

go-talib project provides a nice port of the C-implementation TA-Lib. However, its code is very verbose and hard to read due to the straight translation from the "C" code of TA-Lib. More often, streaming incremental updates to indicators is desirable. We don't want to recalculate the full result if the sliding window only moves forward a single value while history values are not changed at all. Recalculation of the history for every new value is expensive. With those in mind, go-tart intends to support streaming updates of new values with a concise implementation. Most of the indicators from go-talib are realized except a few trivial ones and those involves Hilbert Transform. Results are verified using TA-Lib's output. MACD's "stability" issue from go-talib is fixed.

Performance

A benchmark is written to compare the performance for the set of indicators from both go-talib and go-talib. This is not a scientific evaluation but gives a sense of how they perform in case of a full recalculation. As shown below, go-tart is about 3X slower in full recalculation, which is due to function call to Update in each iteration. go-talib holds advantage because its code is inlined.

gotest -run ^$ -bench=.
BenchmarkTart-4             2019            496703 ns/op
BenchmarkTalib-4            7944            150311 ns/op

After the initial full calculation, go-tart should perform better as it only needs a single iteration cost to compute a new update.

Install

Install the package with:

go get github.com/iamjinlei/go-tart

Import it with:

import "github.com/iamjinlei/go-tart"

and use tart as the package name

Exmaple

package main

import (
	"fmt"

	"github.com/iamjinlei/go-tart"
)

func main() {
	sma := tart.NewSma(5)
	for i := 0; i < 20; i++ {
		fmt.Printf("sma[%v] = %.4f\n", i, sma.Update(float64(i%7)))
	}
}

About

Technical indicators with streaming update support

License:MIT License


Languages

Language:Go 100.0%