ad

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 1 Imported by: 2

README

Go Reference Go Report Card

go-ad

The Accumulation Distribution Line technical analysis algorithm implemented in Golang.

import "github.com/MicahParks/go-ad"

Usage

For full examples, please see the examples directory.

Step 1

Gather the input for the current period.

input := ad.Input{
	Close:  closePrices[i],
	Low:    low[i],
	High:   high[i],
	Volume: volume[i],
}

Step 2

Create the A/D data structure and get the first result

adLine, result := ad.New(input)

Step 3

Use the next period's data to calculate the next point on the A/D line. Repeat for all periods.

result = adLine.Calculate(input)

Somewhat complete example (without data)

package main

import (
	"log"
	"os"

	"github.com/MicahParks/go-ad"
)

func main() {
	// Create a logger.
	logger := log.New(os.Stdout, "", 0)

	// Iterate through the rest of the periods' data and calculate the A/D line's point for the given period.
	var adLine *ad.AD
	var result float64
	for i := range open {
		input := ad.Input{
			Close:  closePrices[i],
			Low:    low[i],
			High:   high[i],
			Volume: volume[i],
		}

		if adLine == nil {
			adLine, result = ad.New(input)
		} else {
			result = adLine.Calculate(input)
		}
		logger.Printf("Index: %d AD: %.4f", i, result)
	}
}

Testing

There is 100% test coverage and benchmarks for this project. Here is an example benchmark result:

$ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/MicahParks/go-ad
cpu: Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz
BenchmarkAD_Calculate-6         1000000000               0.0000010 ns/op
BenchmarkBigAD_Calculate-6      1000000000               0.0000765 ns/op
PASS
ok      github.com/MicahParks/go-ad     0.004s

Other Technical Algorithms

Looking for some other technical analysis algorithms? Here are some other ones I've implemented:

  • Accumulation/Distribution (A/D): go-ad
  • Chaikin: go-chaikin
  • Moving Average Convergence Divergence (MACD), Exponential Moving Average (EMA), Simple Moving Average (SMA): go-ma
  • Relative Strength Index (RSI): go-rsi

Resources

I built and tested this package using these resources:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

AD represents the state of an Accumulation Distribution Line.

func New

func New(initial Input) (ad *AD, result float64)

New creates a new AD data structure and returns the initial result.

func (*AD) Calculate

func (ad *AD) Calculate(next Input) float64

Calculate produces the next point on the Accumulation Distribution Line given the current period's information.

type BigAD

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

BigAD represents the state of an Accumulation Distribution Line.

func NewBig

func NewBig(input BigInput) (ad *BigAD, result *big.Float)

NewBig creates a new AD data structure and returns the initial result.

func (*BigAD) Calculate

func (ad *BigAD) Calculate(next BigInput) *big.Float

Calculate produces the next point on the Accumulation Distribution Line given the current period's information.

type BigInput

type BigInput struct {
	Close  *big.Float
	Low    *big.Float
	High   *big.Float
	Volume *big.Float
}

BigInput is the required input to calculate a point on the Accumulation Distribution Line.

type Input

type Input struct {
	Close  float64
	Low    float64
	High   float64
	Volume float64
}

Input is the required input to calculate a point on the Accumulation Distribution Line.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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