Skip to content

Commit

Permalink
Remove strategy.Strategy from the strategy structs.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Sep 14, 2024
1 parent c10a9c1 commit 8bc081b
Show file tree
Hide file tree
Showing 29 changed files with 151 additions and 201 deletions.
36 changes: 36 additions & 0 deletions helper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The information provided on this project is strictly for informational purposes
- [func ChangeRatio\[T Number\]\(c \<\-chan T, before int\) \<\-chan T](<#ChangeRatio>)
- [func CheckEquals\[T comparable\]\(inputs ...\<\-chan T\) error](<#CheckEquals>)
- [func CloseAndLogError\(closer io.Closer, message string\)](<#CloseAndLogError>)
- [func CommonPeriod\(periods ...int\) int](<#CommonPeriod>)
- [func Count\[T Number, O any\]\(from T, other \<\-chan O\) \<\-chan T](<#Count>)
- [func DaysBetween\(from, to time.Time\) int](<#DaysBetween>)
- [func DecrementBy\[T Number\]\(c \<\-chan T, d T\) \<\-chan T](<#DecrementBy>)
Expand Down Expand Up @@ -75,6 +76,7 @@ The information provided on this project is strictly for informational purposes
- [func SliceToChan\[T any\]\(slice \[\]T\) \<\-chan T](<#SliceToChan>)
- [func Sqrt\[T Number\]\(c \<\-chan T\) \<\-chan T](<#Sqrt>)
- [func Subtract\[T Number\]\(ac, bc \<\-chan T\) \<\-chan T](<#Subtract>)
- [func SyncPeriod\[T any\]\(commonPeriod, period int, c \<\-chan T\) \<\-chan T](<#SyncPeriod>)
- [func Waitable\[T any\]\(wg \*sync.WaitGroup, c \<\-chan T\) \<\-chan T](<#Waitable>)
- [type Bst](<#Bst>)
- [func NewBst\[T Number\]\(\) \*Bst\[T\]](<#NewBst>)
Expand Down Expand Up @@ -322,6 +324,31 @@ func CloseAndLogError(closer io.Closer, message string)

CloseAndLogError attempts to close the closer and logs any error.

<a name="CommonPeriod"></a>
## func [CommonPeriod](<https://github.com/cinar/indicator/blob/master/helper/sync.go#L24>)

```go
func CommonPeriod(periods ...int) int
```

CommonPeriod calculates the smallest period at which all data channels can be synchronized

Example:

```
// Synchronize channels with periods 4, 2, and 3.
commonPeriod := helper.CommonPeriod(4, 2, 3) // commonPeriod = 4

// Synchronize the first channel
c1 := helper.Sync(commonPeriod, 4, c1)

// Synchronize the second channel
c2 := helper.Sync(commonPeriod, 2, c2)

// Synchronize the third channel
c3 := helper.Sync(commonPeriod, 3, c3)
```

<a name="Count"></a>
## func [Count](<https://github.com/cinar/indicator/blob/master/helper/count.go#L25>)

Expand Down Expand Up @@ -915,6 +942,15 @@ actual := helper.Subtract(ac, bc)
fmt.Println(helper.ChanToSlice(actual)) // [1, 2, 3, 4, 5]
```

<a name="SyncPeriod"></a>
## func [SyncPeriod](<https://github.com/cinar/indicator/blob/master/helper/sync.go#L29>)

```go
func SyncPeriod[T any](commonPeriod, period int, c <-chan T) <-chan T
```

SyncPeriod adjusts the given channel to match the given common period.

<a name="Waitable"></a>
## func [Waitable](<https://github.com/cinar/indicator/blob/master/helper/waitable.go#L11>)

Expand Down
51 changes: 22 additions & 29 deletions strategy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,20 @@ func (a Action) Annotation() string
Annotation returns a single character string representing the recommended action. It returns "S" for Sell, "B" for Buy, and an empty string for Hold.

<a name="AndStrategy"></a>
## type [AndStrategy](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L17-L25>)
## type [AndStrategy](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L17-L23>)

AndStrategy combines multiple strategies and emits actionable recommendations when \*\*all\*\* strategies in the group \*\*reach the same actionable conclusion\*\*. This can be a conservative approach, potentially delaying recommendations until full consensus is reached.

```go
type AndStrategy struct {
Strategy

// Strategies are the group of strategies that will be consulted to make an actionable recommendation.
Strategies []Strategy
// contains filtered or unexported fields
}
```

<a name="NewAndStrategy"></a>
### func [NewAndStrategy](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L28>)
### func [NewAndStrategy](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L26>)

```go
func NewAndStrategy(name string) *AndStrategy
Expand All @@ -202,7 +200,7 @@ func NewAndStrategy(name string) *AndStrategy
NewAndStrategy function initializes an empty and strategies group with the given name.

<a name="AndStrategy.Compute"></a>
### func \(\*AndStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L41>)
### func \(\*AndStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L39>)

```go
func (a *AndStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Action
Expand All @@ -211,7 +209,7 @@ func (a *AndStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Action
Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

<a name="AndStrategy.Name"></a>
### func \(\*AndStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L36>)
### func \(\*AndStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L34>)

```go
func (a *AndStrategy) Name() string
Expand All @@ -220,7 +218,7 @@ func (a *AndStrategy) Name() string
Name returns the name of the strategy.

<a name="AndStrategy.Report"></a>
### func \(\*AndStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L71>)
### func \(\*AndStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L69>)

```go
func (a *AndStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Expand All @@ -229,18 +227,17 @@ func (a *AndStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

<a name="BuyAndHoldStrategy"></a>
## type [BuyAndHoldStrategy](<https://github.com/cinar/indicator/blob/master/strategy/buy_and_hold_strategy.go#L16-L18>)
## type [BuyAndHoldStrategy](<https://github.com/cinar/indicator/blob/master/strategy/buy_and_hold_strategy.go#L16-L17>)

BuyAndHoldStrategy defines an investment approach of acquiring and indefinitely retaining an asset. This strategy primarily serves as a benchmark for evaluating the performance of alternative strategies against a baseline of passive asset ownership.

```go
type BuyAndHoldStrategy struct {
Strategy
}
```

<a name="NewBuyAndHoldStrategy"></a>
### func [NewBuyAndHoldStrategy](<https://github.com/cinar/indicator/blob/master/strategy/buy_and_hold_strategy.go#L21>)
### func [NewBuyAndHoldStrategy](<https://github.com/cinar/indicator/blob/master/strategy/buy_and_hold_strategy.go#L20>)

```go
func NewBuyAndHoldStrategy() *BuyAndHoldStrategy
Expand All @@ -249,7 +246,7 @@ func NewBuyAndHoldStrategy() *BuyAndHoldStrategy
NewBuyAndHoldStrategy function initializes a new buy and hold strategy instance.

<a name="BuyAndHoldStrategy.Compute"></a>
### func \(\*BuyAndHoldStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/buy_and_hold_strategy.go#L32>)
### func \(\*BuyAndHoldStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/buy_and_hold_strategy.go#L31>)

```go
func (*BuyAndHoldStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Action
Expand All @@ -258,7 +255,7 @@ func (*BuyAndHoldStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Acti
Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

<a name="BuyAndHoldStrategy.Name"></a>
### func \(\*BuyAndHoldStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/buy_and_hold_strategy.go#L26>)
### func \(\*BuyAndHoldStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/buy_and_hold_strategy.go#L25>)

```go
func (*BuyAndHoldStrategy) Name() string
Expand All @@ -267,7 +264,7 @@ func (*BuyAndHoldStrategy) Name() string
Name returns the name of the strategy.

<a name="BuyAndHoldStrategy.Report"></a>
### func \(\*BuyAndHoldStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/buy_and_hold_strategy.go#L56>)
### func \(\*BuyAndHoldStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/buy_and_hold_strategy.go#L55>)

```go
func (b *BuyAndHoldStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Expand All @@ -276,22 +273,20 @@ func (b *BuyAndHoldStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

<a name="MajorityStrategy"></a>
## type [MajorityStrategy](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L13-L21>)
## type [MajorityStrategy](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L13-L19>)

MajorityStrategy emits actionable recommendations aligned with what the strategies in the group recommends.

```go
type MajorityStrategy struct {
Strategy

// Strategies are the group of strategies that will be consulted to make an actionable recommendation.
Strategies []Strategy
// contains filtered or unexported fields
}
```

<a name="NewMajorityStrategy"></a>
### func [NewMajorityStrategy](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L24>)
### func [NewMajorityStrategy](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L22>)

```go
func NewMajorityStrategy(name string) *MajorityStrategy
Expand All @@ -300,7 +295,7 @@ func NewMajorityStrategy(name string) *MajorityStrategy
NewMajorityStrategy function initializes an empty majority strategies group with the given name.

<a name="NewMajorityStrategyWith"></a>
### func [NewMajorityStrategyWith](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L29>)
### func [NewMajorityStrategyWith](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L27>)

```go
func NewMajorityStrategyWith(name string, strategies []Strategy) *MajorityStrategy
Expand All @@ -309,7 +304,7 @@ func NewMajorityStrategyWith(name string, strategies []Strategy) *MajorityStrate
NewMajorityStrategyWith function initializes a majority strategies group with the given name and strategies.

<a name="MajorityStrategy.Compute"></a>
### func \(\*MajorityStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L42>)
### func \(\*MajorityStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L40>)

```go
func (a *MajorityStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Action
Expand All @@ -318,7 +313,7 @@ func (a *MajorityStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Acti
Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

<a name="MajorityStrategy.Name"></a>
### func \(\*MajorityStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L37>)
### func \(\*MajorityStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L35>)

```go
func (a *MajorityStrategy) Name() string
Expand All @@ -327,7 +322,7 @@ func (a *MajorityStrategy) Name() string
Name returns the name of the strategy.

<a name="MajorityStrategy.Report"></a>
### func \(\*MajorityStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L70>)
### func \(\*MajorityStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/majority_strategy.go#L68>)

```go
func (a *MajorityStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Expand All @@ -336,22 +331,20 @@ func (a *MajorityStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

<a name="OrStrategy"></a>
## type [OrStrategy](<https://github.com/cinar/indicator/blob/master/strategy/or_strategy.go#L14-L22>)
## type [OrStrategy](<https://github.com/cinar/indicator/blob/master/strategy/or_strategy.go#L14-L20>)

OrStrategy emits actionable recommendations when \*\*at least one\*\* strategy in the group recommends an action \*\*without any conflicting recommendations\*\* from other strategies.

```go
type OrStrategy struct {
Strategy

// Strategies are the group of strategies that will be consulted to make an actionable recommendation.
Strategies []Strategy
// contains filtered or unexported fields
}
```

<a name="NewOrStrategy"></a>
### func [NewOrStrategy](<https://github.com/cinar/indicator/blob/master/strategy/or_strategy.go#L25>)
### func [NewOrStrategy](<https://github.com/cinar/indicator/blob/master/strategy/or_strategy.go#L23>)

```go
func NewOrStrategy(name string) *OrStrategy
Expand All @@ -360,7 +353,7 @@ func NewOrStrategy(name string) *OrStrategy
NewOrStrategy function initializes an empty or strategies group with the given name.

<a name="OrStrategy.Compute"></a>
### func \(\*OrStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/or_strategy.go#L38>)
### func \(\*OrStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/or_strategy.go#L36>)

```go
func (a *OrStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Action
Expand All @@ -369,7 +362,7 @@ func (a *OrStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Action
Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

<a name="OrStrategy.Name"></a>
### func \(\*OrStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/or_strategy.go#L33>)
### func \(\*OrStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/or_strategy.go#L31>)

```go
func (a *OrStrategy) Name() string
Expand All @@ -378,7 +371,7 @@ func (a *OrStrategy) Name() string
Name returns the name of the strategy.

<a name="OrStrategy.Report"></a>
### func \(\*OrStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/or_strategy.go#L66>)
### func \(\*OrStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/or_strategy.go#L64>)

```go
func (a *OrStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Expand Down Expand Up @@ -469,7 +462,7 @@ type Strategy interface {
```

<a name="AllAndStrategies"></a>
### func [AllAndStrategies](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L94>)
### func [AllAndStrategies](<https://github.com/cinar/indicator/blob/master/strategy/and_strategy.go#L92>)

```go
func AllAndStrategies(strategies []Strategy) []Strategy
Expand Down
2 changes: 0 additions & 2 deletions strategy/and_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
// the group **reach the same actionable conclusion**. This can be a conservative approach, potentially
// delaying recommendations until full consensus is reached.
type AndStrategy struct {
Strategy

// Strategies are the group of strategies that will be consulted to make an actionable recommendation.
Strategies []Strategy

Expand Down
1 change: 0 additions & 1 deletion strategy/buy_and_hold_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
// a benchmark for evaluating the performance of alternative
// strategies against a baseline of passive asset ownership.
type BuyAndHoldStrategy struct {
Strategy
}

// NewBuyAndHoldStrategy function initializes a new buy and hold strategy instance.
Expand Down
14 changes: 6 additions & 8 deletions strategy/compound/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ func AllStrategies() []strategy.Strategy
AllStrategies returns a slice containing references to all available compound strategies.

<a name="MacdRsiStrategy"></a>
## type [MacdRsiStrategy](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L26-L34>)
## type [MacdRsiStrategy](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L26-L32>)

MacdRsiStrategy represents the configuration parameters for calculating the MACD\-RSI strategy.

```go
type MacdRsiStrategy struct {
strategy.Strategy

// MacdStrategy is the MACD strategy instance.
MacdStrategy *trend.MacdStrategy

Expand All @@ -75,7 +73,7 @@ type MacdRsiStrategy struct {
```

<a name="NewMacdRsiStrategy"></a>
### func [NewMacdRsiStrategy](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L37>)
### func [NewMacdRsiStrategy](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L35>)

```go
func NewMacdRsiStrategy() *MacdRsiStrategy
Expand All @@ -84,7 +82,7 @@ func NewMacdRsiStrategy() *MacdRsiStrategy
NewMacdRsiStrategy function initializes a new MACD\-RSI strategy instance with the default parameters.

<a name="NewMacdRsiStrategyWith"></a>
### func [NewMacdRsiStrategyWith](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L45>)
### func [NewMacdRsiStrategyWith](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L43>)

```go
func NewMacdRsiStrategyWith(buyAt, sellAt float64) *MacdRsiStrategy
Expand All @@ -93,7 +91,7 @@ func NewMacdRsiStrategyWith(buyAt, sellAt float64) *MacdRsiStrategy
NewMacdRsiStrategyWith function initializes a new MACD\-RSI strategy instance with the given parameters.

<a name="MacdRsiStrategy.Compute"></a>
### func \(\*MacdRsiStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L61>)
### func \(\*MacdRsiStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L59>)

```go
func (m *MacdRsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
Expand All @@ -102,7 +100,7 @@ func (m *MacdRsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strat
Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

<a name="MacdRsiStrategy.Name"></a>
### func \(\*MacdRsiStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L53>)
### func \(\*MacdRsiStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L51>)

```go
func (m *MacdRsiStrategy) Name() string
Expand All @@ -111,7 +109,7 @@ func (m *MacdRsiStrategy) Name() string
Name returns the name of the strategy.

<a name="MacdRsiStrategy.Report"></a>
### func \(\*MacdRsiStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L84>)
### func \(\*MacdRsiStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/compound/macd_rsi_strategy.go#L82>)

```go
func (m *MacdRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Expand Down
2 changes: 0 additions & 2 deletions strategy/compound/macd_rsi_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const (

// MacdRsiStrategy represents the configuration parameters for calculating the MACD-RSI strategy.
type MacdRsiStrategy struct {
strategy.Strategy

// MacdStrategy is the MACD strategy instance.
MacdStrategy *trend.MacdStrategy

Expand Down
Loading

0 comments on commit 8bc081b

Please sign in to comment.