The Relative Strength Index (RSI) technical analysis algorithm implemented in Golang.
import "github.com/MicahParks/go-rsi/v2"
For full examples, please see the examples
directory.
- Gather test data.
- Decide on the number of periods,
p
, for the RSI algorithm. Populate a slice of prices whose length isp + 1
.
// Determine the number of periods for the initial inputs. Defaults to 14.
const initialLength = rsi.DefaultPeriods + 1
initial := prices[:initialLength]
Create the RSI data structure and get the first result.
r, result := rsi.New(initial)
Use the remaining data to calculate the RSI value for that period.
remaining := prices[initialLength:]
for i, next := range remaining {
result = r.Calculate(next)
}
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-rsi/v2
cpu: Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz
BenchmarkBigRSI_Calculate-6 1000000000 0.0001744 ns/op
BenchmarkRSI_Calculate-6 1000000000 0.0000017 ns/op
PASS
ok github.com/MicahParks/go-rsi/v2 0.005s
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
I built and tested this package using these resources: