-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
810 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2023 Onur Cinar. All Rights Reserved. | ||
// The source code is provided under MIT License. | ||
// https://github.com/cinar/indicator | ||
|
||
package helper | ||
|
||
// Buffered takes a channel of any type and returns a new channel of the same type with | ||
// a buffer of the specified size. This allows the original channel to continue sending | ||
// data even if the receiving end is temporarily unavailable. | ||
// | ||
// Example: | ||
func Buffered[T any](c <-chan T, size int) <-chan T { | ||
result := make(chan T, size) | ||
|
||
go func() { | ||
Pipe(c, result) | ||
}() | ||
|
||
return result | ||
} |
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,23 @@ | ||
// Copyright (c) 2023 Onur Cinar. All Rights Reserved. | ||
// The source code is provided under MIT License. | ||
// https://github.com/cinar/indicator | ||
|
||
package helper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cinar/indicator/helper" | ||
) | ||
|
||
func TestBuffered(t *testing.T) { | ||
c := make(chan int, 1) | ||
b := helper.Buffered(c, 4) | ||
|
||
c <- 1 | ||
c <- 2 | ||
c <- 3 | ||
c <- 4 | ||
|
||
helper.Drain(b) | ||
} |
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,77 @@ | ||
<!-- Code generated by gomarkdoc. DO NOT EDIT --> | ||
|
||
# strategy | ||
|
||
```go | ||
import "github.com/cinar/indicator/strategy" | ||
``` | ||
|
||
## Index | ||
|
||
- [type Action](<#Action>) | ||
- [type ApoStrategy](<#ApoStrategy>) | ||
- [func NewApoStrategy\[T helper.Number\]\(\) \*ApoStrategy\[T\]](<#NewApoStrategy>) | ||
- [func \(a \*ApoStrategy\[T\]\) Compute\(c \<\-chan T\) \<\-chan Action](<#ApoStrategy[T].Compute>) | ||
|
||
|
||
<a name="Action"></a> | ||
## type [Action](<https://github.com/cinar/indicator/blob/v2/strategy/action.go#L9>) | ||
|
||
ActionType represents the different action categories that a strategy can recommend. | ||
|
||
```go | ||
type Action int | ||
``` | ||
|
||
<a name="Hold"></a> | ||
|
||
```go | ||
const ( | ||
// Hold suggests maintaining the current position and not | ||
// taking any actions on the asset. | ||
Hold Action = 0 | ||
|
||
// Sell suggests disposing of the asset and exiting the current position. | ||
// This recommendation typically indicates that the strategy believes the | ||
// asset's price has reached its peak or is likely to decline. | ||
Sell Action = -1 | ||
|
||
// Buy suggests acquiring the asset and entering a new position. This | ||
// recommendation usually implies that the strategy believes the | ||
// asset's price is undervalued. | ||
Buy Action = 1 | ||
) | ||
``` | ||
|
||
<a name="ApoStrategy"></a> | ||
## type [ApoStrategy](<https://github.com/cinar/indicator/blob/v2/strategy/apo_strategy.go#L16-L20>) | ||
|
||
ApoStrategy represents the configuration parameters for calculating the APO strategy. An APO value crossing above zero suggests a bullish trend, while crossing below zero indicates a bearish trend. Positive APO values signify an upward trend, while negative values signify a downward trend. | ||
|
||
```go | ||
type ApoStrategy[T helper.Number] struct { | ||
// Apo represents the configuration parameters for calculating the | ||
// Absolute Price Oscillator (APO). | ||
Apo *trend.Apo[T] | ||
} | ||
``` | ||
|
||
<a name="NewApoStrategy"></a> | ||
### func [NewApoStrategy](<https://github.com/cinar/indicator/blob/v2/strategy/apo_strategy.go#L23>) | ||
|
||
```go | ||
func NewApoStrategy[T helper.Number]() *ApoStrategy[T] | ||
``` | ||
|
||
NewApo function initializes a new APO strategy instance with the default parameters. | ||
|
||
<a name="ApoStrategy[T].Compute"></a> | ||
### func \(\*ApoStrategy\[T\]\) [Compute](<https://github.com/cinar/indicator/blob/v2/strategy/apo_strategy.go#L31>) | ||
|
||
```go | ||
func (a *ApoStrategy[T]) Compute(c <-chan T) <-chan Action | ||
``` | ||
|
||
Compute uses the given values as input and returns a channel of action recommendations. | ||
|
||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>) |
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,25 @@ | ||
// Copyright (c) 2023 Onur Cinar. All Rights Reserved. | ||
// The source code is provided under MIT License. | ||
// https://github.com/cinar/indicator | ||
|
||
package strategy | ||
|
||
// ActionType represents the different action categories that a | ||
// strategy can recommend. | ||
type Action int | ||
|
||
const ( | ||
// Hold suggests maintaining the current position and not | ||
// taking any actions on the asset. | ||
Hold Action = 0 | ||
|
||
// Sell suggests disposing of the asset and exiting the current position. | ||
// This recommendation typically indicates that the strategy believes the | ||
// asset's price has reached its peak or is likely to decline. | ||
Sell Action = -1 | ||
|
||
// Buy suggests acquiring the asset and entering a new position. This | ||
// recommendation usually implies that the strategy believes the | ||
// asset's price is undervalued. | ||
Buy Action = 1 | ||
) |
Oops, something went wrong.