Documentation ¶
Index ¶
- Constants
- type AggFunc
- type Decimal
- func BlackScholes(s, k, t, v, r Decimal, isCall bool) Decimal
- func CDF(x Decimal) Decimal
- func ImpliedVolatility(expectedCost, s, k, t, r Decimal, isCall bool) Decimal
- func ImpliedVolatilityWithEstimate(expectedCost, s, k, t, r, estimate Decimal, isCall bool) Decimal
- func Omega(s, k, t, v, r Decimal) Decimal
- type MovingAverage
- func CustomEMA(period int, k Decimal) MovingAverage
- func CustomWMA(period int, weight Decimal) MovingAverage
- func DEMA(period int) MovingAverage
- func DoubleMA(period int, ma MovingAverageFunc) MovingAverage
- func EMA(period int) MovingAverage
- func SMA(period int) MovingAverage
- func TEMA(period int) MovingAverage
- func TripleMA(period int, ma MovingAverageFunc) MovingAverage
- func WMA(period int) MovingAverage
- type MovingAverageFunc
- type MultiVarStudy
- func LockedMulti(s MultiVarStudy) MultiVarStudy
- func MACD(fastPeriod, slowPeriod, signalPeriod int) MultiVarStudy
- func MACDExt(fastPeriod, slowPeriod, signalPeriod int, ma MovingAverageFunc) MultiVarStudy
- func MACDMulti(fast, slow, signal MovingAverage) MultiVarStudy
- func VWAPBands(up, down Decimal) MultiVarStudy
- type Stream
- type Study
- type StudyWithSetup
- type TA
- func (ta *TA) Acos() *TA
- func (ta *TA) Add(o *TA) *TA
- func (ta *TA) Agg(period int, inPlace bool) *TA
- func (ta *TA) Append(vs ...Decimal) *TA
- func (ta *TA) Asin() *TA
- func (ta *TA) Atan() *TA
- func (ta *TA) Avg() Decimal
- func (ta *TA) Cap() int
- func (ta *TA) Ceil() *TA
- func (ta *TA) Copy() *TA
- func (ta *TA) Cos() *TA
- func (ta *TA) Cosh() *TA
- func (ta *TA) Crossover(o *TA) bool
- func (ta *TA) Crossunder(o *TA) bool
- func (ta *TA) CumProd() *TA
- func (ta *TA) CumSum() *TA
- func (ta *TA) Div(o *TA) *TA
- func (ta *TA) Dot(o *TA) Decimal
- func (ta *TA) Equal(o *TA) bool
- func (ta *TA) Exp() *TA
- func (ta *TA) Fill(start, length int, v Decimal) *TA
- func (ta *TA) Floats() []float64
- func (ta *TA) Floor() *TA
- func (ta *TA) Format(f fmt.State, c rune)
- func (ta *TA) Get(i int) Decimal
- func (ta *TA) GroupBy(fn func(idx int, v Decimal) (group bool), aggFn func(*TA) Decimal, ...) *TA
- func (ta *TA) Last() Decimal
- func (ta *TA) Len() int
- func (ta *TA) Ln() *TA
- func (ta *TA) Log10() *TA
- func (ta *TA) Map(fn func(Decimal) Decimal, inPlace bool) *TA
- func (ta *TA) Mapf(fn func(float64) float64, inPlace bool) *TA
- func (ta *TA) Max() (idx int, v Decimal)
- func (ta *TA) Min() (idx int, v Decimal)
- func (ta *TA) MovingAverage(fn MovingAverageFunc, period int) (*TA, MovingAverage)
- func (ta *TA) Mul(o *TA) *TA
- func (ta *TA) Product() Decimal
- func (ta *TA) Random(seed int64, min, max Decimal) *TA
- func (ta *TA) Raw() []Decimal
- func (ta *TA) Reduce(fn func(prev, v Decimal) Decimal, initial Decimal) Decimal
- func (ta *TA) Reverse() *TA
- func (ta *TA) Set(i int, v Decimal)
- func (ta *TA) Sin() *TA
- func (ta *TA) Sinh() *TA
- func (ta *TA) Slice(i, j int) *TA
- func (ta *TA) Split(segSize int, copy bool) []*TA
- func (ta *TA) SplitFn(fn func(idx int, v Decimal) (split bool), copy bool) []*TA
- func (ta *TA) Sqrt() *TA
- func (ta *TA) StdDevSum() Decimal
- func (ta *TA) Sub(o *TA) *TA
- func (ta *TA) Sum() Decimal
- func (ta *TA) Tan() *TA
- func (ta *TA) Tanh() *TA
- func (ta *TA) Trunc(idx int) *TA
- func (ta *TA) Uncapped() *TA
- func (ta *TA) Update(v Decimal) (prev Decimal)
- func (ta *TA) VarianceSum() Decimal
Constants ¶
const ( Zero = Decimal(0) One = Decimal(1) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type 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 ¶ added in v0.0.6
BlackScholes option pricing formula for pricing puts and calls See https://en.wikipedia.org/wiki/Black%E2%80%93Scholes_model#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 isCall the type of option, true for Call and false for Put
func CDF ¶ added in v0.0.6
CDF - Standard normal cumulative distribution function The probability is estimated by expanding the CDF into a series using the first 100 terms. See https://en.wikipedia.org/wiki/Normal_distribution#Cumulative_distribution_function
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 ¶ added in v0.0.6
ImpliedVolatility is an alias for ImpliedVolatilityWithEstimate(expectedCost, s, k, t, r, 0.1, isCall)
func ImpliedVolatilityWithEstimate ¶ added in v0.0.6
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
type MovingAverage ¶ added in v0.0.5
type MovingAverage interface { Study // 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 DoubleMA ¶ added in v0.0.6
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 TripleMA ¶ added in v0.0.6
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 ¶ added in v0.0.6
type MultiVarStudy interface { Study // 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 ¶ added in v0.0.6
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 ¶ added in v0.0.5
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 ¶ added in v0.0.5
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 ¶ added in v0.0.6
func AggregateFn ¶ added in v0.0.6
func StreamFromStudy ¶ added in v0.0.6
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 ¶ added in v0.0.6
LockedStudy returns a thread-safe version of the study
func Mean ¶ added in v0.0.5
Mean - returns an updatable study where Update returns the mean of total values
func RSIExt ¶
func RSIExt(ma MovingAverage) Study
RSIExt - Relative Strength Index using a different moving average func
func StdDev ¶ added in v0.0.5
StdDev - returns an updatable study where Update returns the standard deviation of total values
type StudyWithSetup ¶ added in v0.0.6
type StudyWithSetup interface { Study // 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 ¶ added in v0.0.6
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 ¶ added in v0.0.6
ApplyStudy applies the given study to the input(s) and returns the result(s) the returned TA.Len() == s.Len()
func (*TA) Agg ¶ added in v0.0.6
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 ¶
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) Crossunder ¶
func (*TA) Floats ¶
Floats returns the taice as []float64, without a copy if not capped if ta is capped, it'll create a copy
func (*TA) MovingAverage ¶
func (ta *TA) MovingAverage(fn MovingAverageFunc, period int) (*TA, MovingAverage)
func (*TA) Random ¶ added in v0.0.6
Random fills the ta with random generated data within the given range example: New(10, false).Random(42, -42, 42)
func (*TA) Raw ¶
Raw returns the underlying data slice if ta is capped, the data will *not* be in order
func (*TA) Update ¶ added in v0.0.5
Update pushes v to the end of the "buffer" and returns the previous value It will panic unless the ta was created with `NewCapped`