github.com/MicahParks/go-rsi@v1.0.7/README.md (about) 1 [](https://pkg.go.dev/github.com/MicahParks/go-rsi) [](https://goreportcard.com/report/github.com/MicahParks/go-rsi) 2 # go-rsi 3 The Relative Strength Index (RSI) technical analysis algorithm implemented in Golang. 4 5 # Usage 6 For full examples, please see the `examples` directory. 7 8 ## Preconditions 9 1. Gather test data. 10 2. Decide on the number of periods for the averages for the RSI algorithm. 11 12 ```go 13 // Gather some test data. 14 // 15 // For production systems, it'd be best to gather test data asynchronously. 16 avgGains, avgLosses, _ := testData() 17 18 // Determine the number of periods for the initial inputs. Defaults to 14. 19 periods := rsi.DefaultPeriods 20 ``` 21 22 ## Step 1 23 Create the initial input. This is the average of the gains and losses over a given number of periods. 24 ```go 25 // Average the gains and losses over the given period. 26 avgGain := avg(avgGains[0:periods]) 27 avgLoss := avg(avgLosses[0:periods]) 28 initialInput := rsi.Input{ 29 AverageGain: avgGain, 30 AverageLoss: avgLoss, 31 } 32 ``` 33 34 ## Step 2 35 Create the RSI data structure and get the first result. 36 ```go 37 // Create the RSI data structure and get the first result. 38 // 39 // If the first argument, the initial periods is 0, the default value, 14, will be used. 40 r, result := rsi.New(uint(periods), initialInput) 41 ``` 42 43 ## Step 3 44 Use the remaining data per period to calculate the RSI result at that period. 45 ```go 46 // Use the remaining data to generate the RSI for each period. 47 for i := periods; i < len(avgGains); i++ { 48 avgGain = avgGains[i] 49 avgLoss = avgLosses[i] 50 result = r.Calculate(rsi.Input{ 51 AverageGain: avgGain, 52 AverageLoss: avgLoss, 53 }) 54 } 55 ``` 56 57 # Testing 58 There is 100% test coverage and benchmarks for this project. Here is an example benchmark result: 59 ``` 60 $ go test -bench . 61 goos: linux 62 goarch: amd64 63 pkg: github.com/MicahParks/go-rsi 64 cpu: Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz 65 BenchmarkBigRSI_Calculate-6 1000000000 0.0001274 ns/op 66 BenchmarkRSI_Calculate-6 1000000000 0.0000007 ns/op 67 PASS 68 ok github.com/MicahParks/go-rsi 0.006s 69 ``` 70 71 # Resources 72 I built and tested this package using these resources: 73 * [Investopedia](https://www.investopedia.com/terms/r/rsi.asp) 74 * [Invest Excel](https://investexcel.net/relative-strength-index-spreadsheet/)