-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving Standard Deviation and Bollinger Bands are added.
- Loading branch information
Showing
14 changed files
with
990 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<!-- Code generated by gomarkdoc. DO NOT EDIT --> | ||
|
||
# volatility | ||
|
||
```go | ||
import "github.com/cinar/indicator/volatility" | ||
``` | ||
|
||
Package volatility contains the volatility indicator functions. | ||
|
||
This package belongs to the Indicator project. Indicator is a Golang module that supplies a variety of technical indicators, strategies, and a backtesting framework for analysis. | ||
|
||
### License | ||
|
||
``` | ||
Copyright (c) 2021-2023 Onur Cinar. | ||
The source code is provided under GNU AGPLv3 License. | ||
https://github.com/cinar/indicator | ||
``` | ||
|
||
### Disclaimer | ||
|
||
The information provided on this project is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security. | ||
|
||
## Index | ||
|
||
- [Constants](<#constants>) | ||
- [type BollingerBands](<#BollingerBands>) | ||
- [func NewBollingerBands\[T helper.Number\]\(\) \*BollingerBands\[T\]](<#NewBollingerBands>) | ||
- [func \(b \*BollingerBands\[T\]\) Compute\(c \<\-chan T\) \(\<\-chan T, \<\-chan T, \<\-chan T\)](<#BollingerBands[T].Compute>) | ||
- [func \(b \*BollingerBands\[T\]\) IdlePeriod\(\) int](<#BollingerBands[T].IdlePeriod>) | ||
- [type MovingStd](<#MovingStd>) | ||
- [func NewMovingStd\[T helper.Number\]\(\) \*MovingStd\[T\]](<#NewMovingStd>) | ||
- [func NewMovingStdWithPeriod\[T helper.Number\]\(period int\) \*MovingStd\[T\]](<#NewMovingStdWithPeriod>) | ||
- [func \(m \*MovingStd\[T\]\) Compute\(c \<\-chan T\) \<\-chan T](<#MovingStd[T].Compute>) | ||
- [func \(m \*MovingStd\[T\]\) IdlePeriod\(\) int](<#MovingStd[T].IdlePeriod>) | ||
|
||
|
||
## Constants | ||
|
||
<a name="DefaultBollingerBandsPeriod"></a> | ||
|
||
```go | ||
const ( | ||
// DefaultBollingerBandsPeriod is the default period for the Bollinger Bands. | ||
DefaultBollingerBandsPeriod = 20 | ||
) | ||
``` | ||
|
||
<a name="BollingerBands"></a> | ||
## type [BollingerBands](<https://github.com/cinar/indicator/blob/v2/volatility/bollinger_bands.go#L29-L32>) | ||
|
||
BollingerBands represents the configuration parameters for calculating the Bollinger Bands. It is a technical analysis tool used to gauge a market's volatility and identify overbought and oversold conditions. Returns the upper band, the middle band, and the lower band. | ||
|
||
``` | ||
Middle Band = 20-Period SMA. | ||
Upper Band = 20-Period SMA + 2 (20-Period Std) | ||
Lower Band = 20-Period SMA - 2 (20-Period Std) | ||
``` | ||
|
||
Example: | ||
|
||
``` | ||
bollingerBands := NewBollingerBands[float64]() | ||
bollingerBands.Compute(values) | ||
``` | ||
|
||
```go | ||
type BollingerBands[T helper.Number] struct { | ||
// Time period. | ||
Period int | ||
} | ||
``` | ||
|
||
<a name="NewBollingerBands"></a> | ||
### func [NewBollingerBands](<https://github.com/cinar/indicator/blob/v2/volatility/bollinger_bands.go#L35>) | ||
|
||
```go | ||
func NewBollingerBands[T helper.Number]() *BollingerBands[T] | ||
``` | ||
|
||
NewBollingerBands function initializes a new Bollinger Bands instance with the default parameters. | ||
|
||
<a name="BollingerBands[T].Compute"></a> | ||
### func \(\*BollingerBands\[T\]\) [Compute](<https://github.com/cinar/indicator/blob/v2/volatility/bollinger_bands.go#L42>) | ||
|
||
```go | ||
func (b *BollingerBands[T]) Compute(c <-chan T) (<-chan T, <-chan T, <-chan T) | ||
``` | ||
|
||
Compute function takes a channel of numbers and computes the Bollinger Bands over the specified period. | ||
|
||
<a name="BollingerBands[T].IdlePeriod"></a> | ||
### func \(\*BollingerBands\[T\]\) [IdlePeriod](<https://github.com/cinar/indicator/blob/v2/volatility/bollinger_bands.go#L74>) | ||
|
||
```go | ||
func (b *BollingerBands[T]) IdlePeriod() int | ||
``` | ||
|
||
IdlePeriod is the initial period that Bollinger Bands won't yield any results. | ||
|
||
<a name="MovingStd"></a> | ||
## type [MovingStd](<https://github.com/cinar/indicator/blob/v2/volatility/moving_std.go#L19-L22>) | ||
|
||
MovingStd represents the configuration parameters for calculating the Moving Standard Deviation over the specified period. | ||
|
||
``` | ||
Std = Sqrt(1/Period * Sum(Pow(value - sma), 2)) | ||
``` | ||
|
||
Example: | ||
|
||
```go | ||
type MovingStd[T helper.Number] struct { | ||
// Time period. | ||
Period int | ||
} | ||
``` | ||
|
||
<a name="NewMovingStd"></a> | ||
### func [NewMovingStd](<https://github.com/cinar/indicator/blob/v2/volatility/moving_std.go#L25>) | ||
|
||
```go | ||
func NewMovingStd[T helper.Number]() *MovingStd[T] | ||
``` | ||
|
||
NewMovingStd function initializes a new Moving Standard Deviation instance with the default parameters. | ||
|
||
<a name="NewMovingStdWithPeriod"></a> | ||
### func [NewMovingStdWithPeriod](<https://github.com/cinar/indicator/blob/v2/volatility/moving_std.go#L30>) | ||
|
||
```go | ||
func NewMovingStdWithPeriod[T helper.Number](period int) *MovingStd[T] | ||
``` | ||
|
||
NewMovingStdWithPeriod function initializes a new Moving Standard Deviation instance with the given period. | ||
|
||
<a name="MovingStd[T].Compute"></a> | ||
### func \(\*MovingStd\[T\]\) [Compute](<https://github.com/cinar/indicator/blob/v2/volatility/moving_std.go#L37>) | ||
|
||
```go | ||
func (m *MovingStd[T]) Compute(c <-chan T) <-chan T | ||
``` | ||
|
||
Compute function takes a channel of numbers and computes the Moving Standard Deviation over the specified period. | ||
|
||
<a name="MovingStd[T].IdlePeriod"></a> | ||
### func \(\*MovingStd\[T\]\) [IdlePeriod](<https://github.com/cinar/indicator/blob/v2/volatility/moving_std.go#L69>) | ||
|
||
```go | ||
func (m *MovingStd[T]) IdlePeriod() int | ||
``` | ||
|
||
IdlePeriod is the initial period that Moving Standard Deviation won't yield any results. | ||
|
||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>) |
Oops, something went wrong.