talib

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

README

Talib

Talib is a technical analysis library for Go

Features

  • Calculations using decimal No loss of precision
  • Basic and advanced technical analysis indicators
  • Cache everything including created indicators and calculated results
  • Automatically clean up the previous data when the boundary number is reached
Installation
go get github.com/gowsp/talib

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HUNDRED = decimal.NewFromInt(100)

Functions

This section is empty.

Types

type Bar

type Bar interface {
	// the time period of the bar
	Period() time.Duration
	// the begin time of the bar period
	BeginTime() time.Time
	// the end time of the bar period
	EndTime() time.Time
	// the open price of the period
	OpenPrice() decimal.Decimal
	// the close price of the period
	ClosePrice() decimal.Decimal
	// the high price of the period
	HighPrice() decimal.Decimal
	// the low price of the period
	LowPrice() decimal.Decimal
	// the whole tradeNum volume in the period
	Volume() decimal.Decimal
	// the whole traded amount of the period
	Amount() decimal.Decimal
	// the number of trades in the period
	Trades() decimal.Decimal
}

func NewBar

func NewBar(period time.Duration, begin time.Time, open, high, low, close decimal.Decimal) Bar

type BaseBar

type BaseBar struct {
	PeriodVal     time.Duration
	BeginTimeVal  time.Time
	EndTimeVal    time.Time
	OpenPriceVal  decimal.Decimal
	ClosePriceVal decimal.Decimal
	HighPriceVal  decimal.Decimal
	LowPriceVal   decimal.Decimal
	VolumeVal     decimal.Decimal
	AmountVal     decimal.Decimal
	TradesVal     decimal.Decimal
}

func (*BaseBar) Amount

func (candle *BaseBar) Amount() decimal.Decimal

func (*BaseBar) BeginTime

func (candle *BaseBar) BeginTime() time.Time

func (*BaseBar) ClosePrice

func (candle *BaseBar) ClosePrice() decimal.Decimal

func (*BaseBar) EndTime

func (candle *BaseBar) EndTime() time.Time

func (*BaseBar) HighPrice

func (candle *BaseBar) HighPrice() decimal.Decimal

func (*BaseBar) LowPrice

func (candle *BaseBar) LowPrice() decimal.Decimal

func (*BaseBar) OpenPrice

func (candle *BaseBar) OpenPrice() decimal.Decimal

func (*BaseBar) Period

func (candle *BaseBar) Period() time.Duration

func (*BaseBar) Trades

func (candle *BaseBar) Trades() decimal.Decimal

func (*BaseBar) Volume

func (candle *BaseBar) Volume() decimal.Decimal

type CachedIndicator

type CachedIndicator struct {
	// contains filtered or unexported fields
}

func NewCacheFrom

func NewCacheFrom(series *TimeSeries, loader Loader) *CachedIndicator

func NewCachedIndicator

func NewCachedIndicator(indicator Indicator, loader Loader) *CachedIndicator

func (*CachedIndicator) BarSeries

func (s *CachedIndicator) BarSeries() *TimeSeries

func (*CachedIndicator) Delete

func (i *CachedIndicator) Delete(times []uint64)

func (*CachedIndicator) LoadOrStore

func (series *CachedIndicator) LoadOrStore(key string, supplier func() Indicator) Indicator

func (*CachedIndicator) Offset

func (i *CachedIndicator) Offset(offset uint64) decimal.Decimal

func (*CachedIndicator) OutOfBounds

func (s *CachedIndicator) OutOfBounds(offset uint64) bool

type Indicator

type Indicator interface {
	// Offset value forward based on the latest value,
	// Offset(0) The latest value added, Offset(1) The value of the previous period
	Offset(offset uint64) decimal.Decimal
	// OutOfBounds returns true if the offset is out of bounds
	OutOfBounds(offset uint64) bool
	// BarSeries get time series data
	BarSeries() *TimeSeries
	// Load the associated indicator in the current indicator cache,
	// use the supply function to generate and save when it does not exist
	LoadOrStore(id string, supplier func() Indicator) Indicator
	// Delete remove expired data
	Delete(expired []uint64)
}

func BaseEma

func BaseEma(indicator Indicator, length uint64, alpha decimal.Decimal) Indicator

func Ema

func Ema(indicator Indicator, length uint64) Indicator

Ema The ema function returns the exponentially weighted moving average. In ema weighting factors decrease exponentially

func Gain

func Gain(i Indicator) Indicator

Gain

func Highest

func Highest(i Indicator, length uint64) Indicator

Highest Highest value indicator

func Loss

func Loss(i Indicator) Indicator

Loss

func Lowest

func Lowest(i Indicator, length uint64) Indicator

Lowest Lowest value indicator

func Rma

func Rma(indicator Indicator, length uint64) Indicator

Rma Moving average used in RSI. It is the exponentially weighted moving average with alpha = 1 / length.

func Roc

func Roc(i Indicator, length uint64) Indicator

Roc roc (rate of change) showing the difference between current value of x and the value of x that was y days ago.

func Rsi

func Rsi(i Indicator, length uint64) Indicator

Rsi Relative strength index. It is calculated based on rma's of upward and downward change of x.

func Sma

func Sma(indicator Indicator, length uint64) Indicator

Sma function returns the moving average

type Loader

type Loader func(Indicator, uint64) decimal.Decimal

type Rule

type Rule func(offset uint64) bool

A rule for strategy building. A trading rule may be composed of a combination of other rules.

func (Rule) And

func (r Rule) And(other Rule) Rule

a rule which is the AND combination of this rule with the provided one

func (Rule) Or

func (r Rule) Or(other Rule) Rule

a rule which is the OR combination of this rule with the provided one

type Strategy

type Strategy interface {
	// true to recommend to enter, false otherwise
	ShouldEnter(offset uint64) bool
	// true to recommend to exit, false otherwise
	ShouldExit(offset uint64) bool
}

A trading strategy. A strategy is a pair of complementary rules. It may recommend to enter or to exit.

func NewStrategy

func NewStrategy(entryRule, exitRule Rule) Strategy

type TimeSeries

type TimeSeries struct {
	// contains filtered or unexported fields
}

func NewLimitSeries

func NewLimitSeries(period time.Duration, capacity, threshold uint64) *TimeSeries

func NewSeries

func NewSeries(period time.Duration) *TimeSeries

func (*TimeSeries) Add

func (series *TimeSeries) Add(bar Bar)

func (*TimeSeries) Atr

func (series *TimeSeries) Atr(length uint64) Indicator

Atr (average true range) returns the RMA of true range.

func (*TimeSeries) ClosePriceIndicator

func (series *TimeSeries) ClosePriceIndicator() Indicator

func (*TimeSeries) Cursor

func (series *TimeSeries) Cursor(i uint64) uint64

func (*TimeSeries) HighPriceIndicator

func (series *TimeSeries) HighPriceIndicator() Indicator

func (*TimeSeries) LoadOrStore

func (series *TimeSeries) LoadOrStore(id string, supplier func() Indicator) Indicator

func (*TimeSeries) LowPriceIndicator

func (series *TimeSeries) LowPriceIndicator() Indicator

func (*TimeSeries) MedianPriceIndicator

func (series *TimeSeries) MedianPriceIndicator() Indicator

func (*TimeSeries) NewIndicator

func (series *TimeSeries) NewIndicator(id string, method func(Bar) decimal.Decimal) Indicator

func (*TimeSeries) Offset

func (series *TimeSeries) Offset(i uint64) Bar

func (*TimeSeries) OpenPriceIndicator

func (series *TimeSeries) OpenPriceIndicator() Indicator

func (*TimeSeries) Size

func (series *TimeSeries) Size() uint64

func (*TimeSeries) Tr

func (series *TimeSeries) Tr() Indicator

Tr True range

func (*TimeSeries) TypicalPriceIndicator

func (series *TimeSeries) TypicalPriceIndicator() Indicator

func (*TimeSeries) VolumeIndicator

func (series *TimeSeries) VolumeIndicator() Indicator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL