README Documentation Testing status Coverage Status License Go Report Card stability-experimental

A Go Technical Analysis library, mostly inspired by python's TA-Lib and the port by markcheno. It Can be used for backtesting or eventually creating strategies for live trading.


  • Tries to be compatible with the python version for testing, however all the functions supports partial updates to help working with live data.
  • Going for a healthy mix of speed and accuracy.
  • Includes option related functions.


go get -u


  • the API is not stable at all
  • Missing a lot of indicators compared to the python version or markcheno's port


  • Port more functions
  • More testing / benchmarks
  • Stablize the API
  • Documentation


package main

import (

func main() {
	spy, _ := quote.NewQuoteFromYahoo("spy", "2016-01-01", "2016-04-01", quote.Daily, true)
	dema, _ := ta.New(spy.Close).DEMA(10)
  • all the *_test.go files should have more examples.



Without those libraries and their documentation, this wouldn't have been possible.






View Source
const (
	Zero = Decimal(0)
	One  = Decimal(1)


This section is empty.


This section is empty.


type AggFunc

type AggFunc = func(*TA) Decimal

type Decimal

type Decimal = decimal.Decimal

    Decimal is an alias to the underlying type we use. For now it's mostly a wrapper around float64, however it may change to big.Float in the future if higher accuracy is needed.

    func BlackScholes

    func BlackScholes(s, k, t, v, r Decimal, isCall bool) Decimal

      BlackScholes option pricing formula for pricing puts and calls See s current price of the underlying k Strike price t time to experiation in years (num days / 365) v volatility r annual risk-free interest rate isCall the type of option, true for Call and false for Put

      func CDF

      func CDF(x Decimal) Decimal

        CDF - Standard normal cumulative distribution function The probability is estimated by expanding the CDF into a series using the first 100 terms. See

        x is the upper bound to integrate over. This is P{Z <= x} where Z is a standard normal random variable. returns the probability that a standard normal random variable will be less than or equal to x

        func ImpliedVolatility

        func ImpliedVolatility(expectedCost, s, k, t, r Decimal, isCall bool) Decimal

          ImpliedVolatility is an alias for ImpliedVolatilityWithEstimate(expectedCost, s, k, t, r, 0.1, isCall)

          func ImpliedVolatilityWithEstimate

          func ImpliedVolatilityWithEstimate(expectedCost, s, k, t, r, estimate Decimal, isCall bool) Decimal

            ImpliedVolatilityWithEstimate calculates a close estimate of implied volatility given an option price A binary search type approach is used to determine the implied volatility expectedCost The market price of the option s current price of the underlying k Strike price t time to experiation in years (num days / 365) v volatility r annual risk-free interest rate estimate a initial estimate of implied volatility isCall the type of option, true for Call and false for Put

            func Omega

            func Omega(s, k, t, v, r Decimal) Decimal

              Omega - calcuates Ω as defined in the Black-Scholes formula s current price of the underlying k Strike price t time to experiation in years (num days / 365) v volatility r annual risk-free interest rate

              type MovingAverage

              type MovingAverage interface {
              	// contains filtered or unexported methods

              func CustomEMA

              func CustomEMA(period int, k Decimal) MovingAverage

                CustomEMA - returns an updatable EMA with the given k

                func CustomWMA

                func CustomWMA(period int, weight Decimal) MovingAverage

                  CustomWMA returns an updatable WMA with the given weight

                  func DEMA

                  func DEMA(period int) MovingAverage

                    DEMA - Double Exponential Moving Average

                    func DoubleMA

                    func DoubleMA(period int, ma MovingAverageFunc) MovingAverage

                      DoubleMA - Double Moving Average

                      func EMA

                      func EMA(period int) MovingAverage

                        EMA - Exponential Moving Average An alias for CustomEMA(period, 2 / (period+1))

                        func SMA

                        func SMA(period int) MovingAverage

                          SMA - Simple Moving Average

                          func TEMA

                          func TEMA(period int) MovingAverage

                            TEMA - Triple Exponential Moving Average

                            func TripleMA

                            func TripleMA(period int, ma MovingAverageFunc) MovingAverage

                              TripleMA - Triple Moving Average

                              func WMA

                              func WMA(period int) MovingAverage

                                WMA - Exponential Moving Average An alias for CustomWMA(period, (period * (period + 1)) >> 1)

                                type MovingAverageFunc

                                type MovingAverageFunc func(period int) MovingAverage

                                  MovingAverageFunc defines a function that returns am updatable moving average for the given period

                                  type MultiVarStudy

                                  type MultiVarStudy interface {
                                  	// UpdateAll same as `Study.Update`, however will return multiple values
                                  	// for example MACD or VWAP with Bands
                                  	UpdateAll(values ...Decimal) []Decimal
                                  	// LenAll returns the different periods of all underlying studies, if any
                                  	LenAll() []int
                                  	// ToStudy can be used to convert the Multi to a normal study if supported
                                  	ToStudy() (Study, bool)

                                    MultiVarStudy represents a study that can accept multiple variables and can return multiple values for example MACD or VWAP

                                    func LockedMulti

                                    func LockedMulti(s MultiVarStudy) MultiVarStudy

                                      LockedMulti returns a thread-safe version of the multi variable study

                                      func MACD

                                      func MACD(fastPeriod, slowPeriod, signalPeriod int) MultiVarStudy

                                        MACD - Moving Average Convergence/Divergence, using EMA for all periods alias for MACDExt(fastPeriod, slowPeriod, signalPeriod, EMA)

                                        func MACDExt

                                        func MACDExt(fastPeriod, slowPeriod, signalPeriod int, ma MovingAverageFunc) MultiVarStudy

                                          MACDExt - MACD using the specified MA func for all periods alias for MACDMulti(ma(fastPeriod), ma(slowPeriod), ma(signalPeriod))

                                          func MACDMulti

                                          func MACDMulti(fast, slow, signal MovingAverage) MultiVarStudy

                                            MACDMulti - MACD that supports different MA funcs for each period returns a multi study, however it can work as a normal Study Update will return the diff value

                                            func VWAPBands

                                            func VWAPBands(up, down Decimal) MultiVarStudy

                                              VWAPBands - Volume Weighted Average Price with upper and lower bands Update/UpdateAll expects 2 values, the volume and price, it will panic otherwise Update returns VWAP UpdateAll returns [VWAP, UPPER, LOWER]

                                              type Stream

                                              type Stream interface {
                                              	Chan() <-chan Decimal
                                              	Update(v Decimal)

                                              func Aggregate

                                              func Aggregate(period int, blockOnFull bool) Stream

                                              func AggregateFn

                                              func AggregateFn(fn AggFunc, period int, blockOnFull bool) Stream

                                              func StreamFromStudy

                                              func StreamFromStudy(s Study, blockOnFull bool) Stream

                                              type Study

                                              type Study interface {
                                              	// Update depends on the study, must studies can accept multiple values and returns the results
                                              	// however some studies, like VWAP, expects exactly 2 values [volume, price]
                                              	Update(values ...Decimal) Decimal
                                              	// Len returns the period the study was created with
                                              	Len() int
                                              	// ToMulti can be used to convert the study to a multi-variable study if it's supported
                                              	ToMulti() (MultiVarStudy, bool)

                                                Study represents a TA study that supports live updates

                                                func LockedStudy

                                                func LockedStudy(s Study) Study

                                                  LockedStudy returns a thread-safe version of the study

                                                  func Mean

                                                  func Mean(period int) Study

                                                    Mean - returns an updatable study where Update returns the mean of total values

                                                    func RSI

                                                    func RSI(period int) Study

                                                      RSI - Relative Strength Index

                                                      func RSIExt

                                                      func RSIExt(ma MovingAverage) Study

                                                        RSIExt - Relative Strength Index using a different moving average func

                                                        func StdDev

                                                        func StdDev(period int) Study

                                                          StdDev - returns an updatable study where Update returns the standard deviation of total values

                                                          func VWAP

                                                          func VWAP(period int) Study

                                                            VWAP - Volume Weighted Average Price alias for VWAPBands(period, -period)

                                                            func Variance

                                                            func Variance(period int) Study

                                                              Variance - returns an updatable study where Update returns the variance of total values

                                                              type StudyWithSetup

                                                              type StudyWithSetup interface {
                                                              	// Setup takes in multiple TAs and returns the result
                                                              	// len(res) == len(out)
                                                              	Setup(tas ...*TA) (out []*TA)

                                                                StudyWithSetup is a study that supports a setup function for the initial data set

                                                                type TA

                                                                type TA struct {
                                                                	// contains filtered or unexported fields

                                                                  TA the base of the techenical analysis library

                                                                  func ApplyMultiVarStudy

                                                                  func ApplyMultiVarStudy(s MultiVarStudy, tas ...*TA) []*TA

                                                                    ApplyMultiVarStudy applies the given study to input(s) and returns the result(s) the returned TA[x].Len() == s.LenAll()[x]

                                                                    func ApplyStudy

                                                                    func ApplyStudy(s Study, tas ...*TA) *TA

                                                                      ApplyStudy applies the given study to the input(s) and returns the result(s) the returned TA.Len() == s.Len()

                                                                      func Average

                                                                      func Average(tas ...*TA) *TA

                                                                        Average - returns the average of the passed in ta's

                                                                        func HLC3

                                                                        func HLC3(high, low, close *TA) *TA

                                                                          HLC3 - alias for Average(high, low, close)

                                                                          func New

                                                                          func New(vs []float64, transformers ...func(float64) float64) *TA

                                                                          func NewCapped

                                                                          func NewCapped(size int) *TA

                                                                          func NewSize

                                                                          func NewSize(size int, cap bool) *TA

                                                                          func (*TA) Acos

                                                                          func (ta *TA) Acos() *TA

                                                                            Acos - Vector Trigonometric ACOS

                                                                            func (*TA) Add

                                                                            func (ta *TA) Add(o *TA) *TA

                                                                            func (*TA) Agg

                                                                            func (ta *TA) Agg(period int, inPlace bool) *TA

                                                                              Agg aggregates the underlyign data to a different period example hundredMinutesOfData.Agg(15, true) returns 7x 15 minutes worth of data where it gets averaged alias for ta.GroupBy(func(i int, _ Decimal) bool { return i%period == period - 1 }, (*TA).Avg, inPlace)

                                                                              func (*TA) Append

                                                                              func (ta *TA) Append(vs ...Decimal) *TA

                                                                                Append appends v to the underlying buffer, if `Capped` was called it i'll act as a ring buffer rather than a slice

                                                                                func (*TA) Asin

                                                                                func (ta *TA) Asin() *TA

                                                                                  Asin - Vector Trigonometric ASIN

                                                                                  func (*TA) Atan

                                                                                  func (ta *TA) Atan() *TA

                                                                                    Atan - Vector Trigonometric ATAN

                                                                                    func (*TA) Avg

                                                                                    func (ta *TA) Avg() Decimal

                                                                                    func (*TA) Cap

                                                                                    func (ta *TA) Cap() int

                                                                                    func (*TA) Ceil

                                                                                    func (ta *TA) Ceil() *TA

                                                                                      Ceil - Vector CEIL

                                                                                      func (*TA) Copy

                                                                                      func (ta *TA) Copy() *TA

                                                                                      func (*TA) Cos

                                                                                      func (ta *TA) Cos() *TA

                                                                                        Cos - Vector Trigonometric COS

                                                                                        func (*TA) Cosh

                                                                                        func (ta *TA) Cosh() *TA

                                                                                          Cosh - Vector Trigonometric COSH

                                                                                          func (*TA) Crossover

                                                                                          func (ta *TA) Crossover(o *TA) bool

                                                                                          func (*TA) Crossunder

                                                                                          func (ta *TA) Crossunder(o *TA) bool

                                                                                          func (*TA) CumProd

                                                                                          func (ta *TA) CumProd() *TA

                                                                                            CumProd finds the cumulative product of the ta

                                                                                            func (*TA) CumSum

                                                                                            func (ta *TA) CumSum() *TA

                                                                                              CumSum finds the cumulative sum of the ta

                                                                                              func (*TA) Div

                                                                                              func (ta *TA) Div(o *TA) *TA

                                                                                              func (*TA) Dot

                                                                                              func (ta *TA) Dot(o *TA) Decimal

                                                                                              func (*TA) Equal

                                                                                              func (ta *TA) Equal(o *TA) bool

                                                                                              func (*TA) Exp

                                                                                              func (ta *TA) Exp() *TA

                                                                                                Exp - Vector arithmetic EXP

                                                                                                func (*TA) Fill

                                                                                                func (ta *TA) Fill(start, length int, v Decimal) *TA

                                                                                                func (*TA) Floats

                                                                                                func (ta *TA) Floats() []float64

                                                                                                  Floats returns the taice as []float64, without a copy if not capped if ta is capped, it'll create a copy

                                                                                                  func (*TA) Floor

                                                                                                  func (ta *TA) Floor() *TA

                                                                                                    Floor - Vector FLOOR

                                                                                                    func (*TA) Format

                                                                                                    func (ta *TA) Format(f fmt.State, c rune)

                                                                                                    func (*TA) Get

                                                                                                    func (ta *TA) Get(i int) Decimal

                                                                                                    func (*TA) GroupBy

                                                                                                    func (ta *TA) GroupBy(fn func(idx int, v Decimal) (group bool), aggFn func(*TA) Decimal, inPlace bool) *TA

                                                                                                    func (*TA) Last

                                                                                                    func (ta *TA) Last() Decimal

                                                                                                    func (*TA) Len

                                                                                                    func (ta *TA) Len() int

                                                                                                    func (*TA) Ln

                                                                                                    func (ta *TA) Ln() *TA

                                                                                                      Ln - Vector natural log LN

                                                                                                      func (*TA) Log10

                                                                                                      func (ta *TA) Log10() *TA

                                                                                                        Log10 - Vector LOG10

                                                                                                        func (*TA) Map

                                                                                                        func (ta *TA) Map(fn func(Decimal) Decimal, inPlace bool) *TA

                                                                                                        func (*TA) Mapf

                                                                                                        func (ta *TA) Mapf(fn func(float64) float64, inPlace bool) *TA

                                                                                                        func (*TA) Max

                                                                                                        func (ta *TA) Max() (idx int, v Decimal)

                                                                                                        func (*TA) Min

                                                                                                        func (ta *TA) Min() (idx int, v Decimal)

                                                                                                        func (*TA) MovingAverage

                                                                                                        func (ta *TA) MovingAverage(fn MovingAverageFunc, period int) (*TA, MovingAverage)

                                                                                                        func (*TA) Mul

                                                                                                        func (ta *TA) Mul(o *TA) *TA

                                                                                                        func (*TA) Product

                                                                                                        func (ta *TA) Product() Decimal

                                                                                                        func (*TA) Random

                                                                                                        func (ta *TA) Random(seed int64, min, max Decimal) *TA

                                                                                                          Random fills the ta with random generated data within the given range example: New(10, false).Random(42, -42, 42)

                                                                                                          func (*TA) Raw

                                                                                                          func (ta *TA) Raw() []Decimal

                                                                                                            Raw returns the underlying data slice if ta is capped, the data will *not* be in order

                                                                                                            func (*TA) Reduce

                                                                                                            func (ta *TA) Reduce(fn func(prev, v Decimal) Decimal, initial Decimal) Decimal

                                                                                                            func (*TA) Reverse

                                                                                                            func (ta *TA) Reverse() *TA

                                                                                                            func (*TA) Set

                                                                                                            func (ta *TA) Set(i int, v Decimal)

                                                                                                            func (*TA) Sin

                                                                                                            func (ta *TA) Sin() *TA

                                                                                                              Sin - Vector Trigonometric SIN

                                                                                                              func (*TA) Sinh

                                                                                                              func (ta *TA) Sinh() *TA

                                                                                                                Sinh - Vector Trigonometric SINH

                                                                                                                func (*TA) Slice

                                                                                                                func (ta *TA) Slice(i, j int) *TA

                                                                                                                func (*TA) Split

                                                                                                                func (ta *TA) Split(segSize int, copy bool) []*TA

                                                                                                                func (*TA) SplitFn

                                                                                                                func (ta *TA) SplitFn(fn func(idx int, v Decimal) (split bool), copy bool) []*TA

                                                                                                                func (*TA) Sqrt

                                                                                                                func (ta *TA) Sqrt() *TA

                                                                                                                  Sqrt - Vector SQRT

                                                                                                                  func (*TA) StdDevSum

                                                                                                                  func (ta *TA) StdDevSum() Decimal

                                                                                                                  func (*TA) Sub

                                                                                                                  func (ta *TA) Sub(o *TA) *TA

                                                                                                                  func (*TA) Sum

                                                                                                                  func (ta *TA) Sum() Decimal

                                                                                                                  func (*TA) Tan

                                                                                                                  func (ta *TA) Tan() *TA

                                                                                                                    Tan - Vector Trigonometric TAN

                                                                                                                    func (*TA) Tanh

                                                                                                                    func (ta *TA) Tanh() *TA

                                                                                                                      Tanh - Vector Trigonometric TANH

                                                                                                                      func (*TA) Trunc

                                                                                                                      func (ta *TA) Trunc(idx int) *TA

                                                                                                                      func (*TA) Uncapped

                                                                                                                      func (ta *TA) Uncapped() *TA

                                                                                                                      func (*TA) Update

                                                                                                                      func (ta *TA) Update(v Decimal) (prev Decimal)

                                                                                                                        Update pushes v to the end of the "buffer" and returns the previous value It will panic unless the ta was created with `NewCapped`

                                                                                                                        func (*TA) VarianceSum

                                                                                                                        func (ta *TA) VarianceSum() Decimal


                                                                                                                        Path Synopsis